Bug 1238137 - Telemetry pings for main thread keyboard-driven scroll input methods. r=ehsan
Pings are sent in the implementations of the nsISelectionController methods
ScrollLine, ScrollPage, ScrollCharacter, and CompleteScroll. It is assumed
that these methods are triggered by keyboard input.
A small number of false positives can occur if these methods are called
in response to something other than keyboard input; this is considered
acceptable.
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -42,19 +42,22 @@
#include "mozilla/Preferences.h"
#include "nsTextNode.h"
#include "nsIController.h"
#include "mozilla/TextEvents.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "nsNumberControlFrame.h"
#include "nsFrameSelection.h"
+#include "mozilla/Telemetry.h"
+#include "mozilla/layers/ScrollInputMethods.h"
using namespace mozilla;
using namespace mozilla::dom;
+using mozilla::layers::ScrollInputMethod;
static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
class MOZ_STACK_CLASS ValueSetter
{
public:
explicit ValueSetter(nsIEditor* aEditor)
: mEditor(aEditor)
@@ -541,16 +544,19 @@ nsTextInputSelectionImpl::PageMove(bool
}
NS_IMETHODIMP
nsTextInputSelectionImpl::CompleteScroll(bool aForward)
{
if (!mScrollFrame)
return NS_ERROR_NOT_INITIALIZED;
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadCompleteScroll);
+
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::WHOLE,
nsIScrollableFrame::INSTANT);
return NS_OK;
}
NS_IMETHODIMP
nsTextInputSelectionImpl::CompleteMove(bool aForward, bool aExtend)
@@ -590,40 +596,49 @@ nsTextInputSelectionImpl::CompleteMove(b
}
NS_IMETHODIMP
nsTextInputSelectionImpl::ScrollPage(bool aForward)
{
if (!mScrollFrame)
return NS_ERROR_NOT_INITIALIZED;
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollPage);
+
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::PAGES,
nsIScrollableFrame::SMOOTH);
return NS_OK;
}
NS_IMETHODIMP
nsTextInputSelectionImpl::ScrollLine(bool aForward)
{
if (!mScrollFrame)
return NS_ERROR_NOT_INITIALIZED;
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollLine);
+
mScrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::LINES,
nsIScrollableFrame::SMOOTH);
return NS_OK;
}
NS_IMETHODIMP
nsTextInputSelectionImpl::ScrollCharacter(bool aRight)
{
if (!mScrollFrame)
return NS_ERROR_NOT_INITIALIZED;
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollCharacter);
+
mScrollFrame->ScrollBy(nsIntPoint(aRight ? 1 : -1, 0),
nsIScrollableFrame::LINES,
nsIScrollableFrame::SMOOTH);
return NS_OK;
}
NS_IMETHODIMP
nsTextInputSelectionImpl::SelectAll()
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -178,16 +178,17 @@
#include "RestyleManager.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDragSession.h"
#include "nsIFrameInlines.h"
#include "mozilla/gfx/2D.h"
#include "nsSubDocumentFrame.h"
#include "nsQueryObject.h"
#include "nsLayoutStylesheetCache.h"
+#include "mozilla/layers/ScrollInputMethods.h"
#ifdef ANDROID
#include "nsIDocShellTreeOwner.h"
#endif
#ifdef MOZ_TASK_TRACER
#include "GeckoTaskTracer.h"
using namespace mozilla::tasktracer;
@@ -2112,32 +2113,37 @@ PresShell::PageMove(bool aForward, bool
NS_IMETHODIMP
PresShell::ScrollPage(bool aForward)
{
nsIScrollableFrame* scrollFrame =
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
if (scrollFrame) {
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollPage);
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::PAGES,
nsIScrollableFrame::SMOOTH,
nullptr, nullptr,
nsIScrollableFrame::NOT_MOMENTUM,
nsIScrollableFrame::ENABLE_SNAP);
}
return NS_OK;
}
NS_IMETHODIMP
PresShell::ScrollLine(bool aForward)
{
nsIScrollableFrame* scrollFrame =
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
if (scrollFrame) {
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollLine);
+
int32_t lineCount = Preferences::GetInt("toolkit.scrollbox.verticalScrollDistance",
NS_DEFAULT_VERTICAL_SCROLL_DISTANCE);
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? lineCount : -lineCount),
nsIScrollableFrame::LINES,
nsIScrollableFrame::SMOOTH,
nullptr, nullptr,
nsIScrollableFrame::NOT_MOMENTUM,
nsIScrollableFrame::ENABLE_SNAP);
@@ -2146,16 +2152,18 @@ PresShell::ScrollLine(bool aForward)
}
NS_IMETHODIMP
PresShell::ScrollCharacter(bool aRight)
{
nsIScrollableFrame* scrollFrame =
GetFrameToScrollAsScrollable(nsIPresShell::eHorizontal);
if (scrollFrame) {
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollCharacter);
int32_t h = Preferences::GetInt("toolkit.scrollbox.horizontalScrollDistance",
NS_DEFAULT_HORIZONTAL_SCROLL_DISTANCE);
scrollFrame->ScrollBy(nsIntPoint(aRight ? h : -h, 0),
nsIScrollableFrame::LINES,
nsIScrollableFrame::SMOOTH,
nullptr, nullptr,
nsIScrollableFrame::NOT_MOMENTUM,
nsIScrollableFrame::ENABLE_SNAP);
@@ -2164,16 +2172,18 @@ PresShell::ScrollCharacter(bool aRight)
}
NS_IMETHODIMP
PresShell::CompleteScroll(bool aForward)
{
nsIScrollableFrame* scrollFrame =
GetFrameToScrollAsScrollable(nsIPresShell::eVertical);
if (scrollFrame) {
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadCompleteScroll);
scrollFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::WHOLE,
nsIScrollableFrame::SMOOTH,
nullptr, nullptr,
nsIScrollableFrame::NOT_MOMENTUM,
nsIScrollableFrame::ENABLE_SNAP);
}
return NS_OK;
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -72,19 +72,22 @@ static NS_DEFINE_CID(kFrameTraversalCID,
#include "nsIBidiKeyboard.h"
#include "nsError.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/SelectionBinding.h"
#include "mozilla/AsyncEventDispatcher.h"
+#include "mozilla/Telemetry.h"
+#include "mozilla/layers/ScrollInputMethods.h"
using namespace mozilla;
using namespace mozilla::dom;
+using mozilla::layers::ScrollInputMethod;
//#define DEBUG_TABLE 1
static bool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsINode *aNode);
static nsIAtom *GetTag(nsINode *aNode);
// returns the parent
static nsINode* ParentOffset(nsINode *aNode, int32_t *aChildOffset);
@@ -2030,16 +2033,18 @@ nsFrameSelection::CommonPageMove(bool aF
desiredPoint.y = caretPos.y + caretPos.height/2;
nsIFrame::ContentOffsets offsets =
scrolledFrame->GetContentOffsetsFromPoint(desiredPoint);
if (!offsets.content)
return;
// scroll one page
+ mozilla::Telemetry::Accumulate(mozilla::Telemetry::SCROLL_INPUT_METHODS,
+ (uint32_t) ScrollInputMethod::MainThreadScrollPage);
aScrollableFrame->ScrollBy(nsIntPoint(0, aForward ? 1 : -1),
nsIScrollableFrame::PAGES,
nsIScrollableFrame::SMOOTH);
// place the caret
HandleClick(offsets.content, offsets.offset,
offsets.offset, aExtend, false, CARET_ASSOCIATE_AFTER);
}