Bug 1290823 - Factor out the code for dispatching a single tap event to observers into its own function. r=rbarker
This is not just a refactoring. It ensures that the early return in the
factored-out code only skips the dispatch to observers, *not* the
additional processing by ChromeProcessController.
MozReview-Commit-ID: F7xCoORKRlG
--- a/widget/android/AndroidContentController.cpp
+++ b/widget/android/AndroidContentController.cpp
@@ -39,59 +39,66 @@ AndroidContentController::NotifyDefaultP
aInputBlockId, aDefaultPrevented), 0);
return;
}
aManager->ContentReceivedInputBlock(aInputBlockId, aDefaultPrevented);
}
void
+AndroidContentController::DispatchSingleTapToObservers(const LayoutDevicePoint& aPoint,
+ const ScrollableLayerGuid& aGuid) const
+{
+ nsIContent* content = nsLayoutUtils::FindContentFor(aGuid.mScrollId);
+ nsIPresShell* shell = content
+ ? mozilla::layers::APZCCallbackHelper::GetRootContentDocumentPresShellForContent(content)
+ : nullptr;
+
+ if (!shell || !shell->GetPresContext()) {
+ return;
+ }
+
+ CSSPoint point = mozilla::layers::APZCCallbackHelper::ApplyCallbackTransform(
+ aPoint / shell->GetPresContext()->CSSToDevPixelScale(), aGuid);
+
+ if (shell->ScaleToResolution()) {
+ // We need to convert from the root document to the root content document,
+ // by unapplying the resolution that's on the content document.
+ const float resolution = shell->GetResolution();
+ point.x /= resolution;
+ point.y /= resolution;
+ }
+
+ CSSIntPoint rounded = RoundedToInt(point);
+ nsAppShell::PostEvent([rounded] {
+ nsCOMPtr<nsIObserverService> obsServ =
+ mozilla::services::GetObserverService();
+ if (!obsServ) {
+ return;
+ }
+
+ nsPrintfCString data("{\"x\":%d,\"y\":%d}", rounded.x, rounded.y);
+ obsServ->NotifyObservers(nullptr, "Gesture:SingleTap",
+ NS_ConvertASCIItoUTF16(data).get());
+ });
+}
+
+void
AndroidContentController::HandleTap(TapType aType, const LayoutDevicePoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId)
{
// This function will get invoked first on the Java UI thread, and then
// again on the main thread (because of the code in ChromeProcessController::
// HandleTap). We want to post the SingleTap message once; it can be
// done from either thread but we need access to the callback transform
// so we do it from the main thread.
if (NS_IsMainThread() && aType == TapType::eSingleTap) {
- nsIContent* content = nsLayoutUtils::FindContentFor(aGuid.mScrollId);
- nsIPresShell* shell = content
- ? mozilla::layers::APZCCallbackHelper::GetRootContentDocumentPresShellForContent(content)
- : nullptr;
-
- if (!shell || !shell->GetPresContext()) {
- return;
- }
-
- CSSPoint point = mozilla::layers::APZCCallbackHelper::ApplyCallbackTransform(
- aPoint / shell->GetPresContext()->CSSToDevPixelScale(), aGuid);
-
- if (shell->ScaleToResolution()) {
- // We need to convert from the root document to the root content document,
- // by unapplying the resolution that's on the content document.
- const float resolution = shell->GetResolution();
- point.x /= resolution;
- point.y /= resolution;
- }
-
- CSSIntPoint rounded = RoundedToInt(point);
- nsAppShell::PostEvent([rounded] {
- nsCOMPtr<nsIObserverService> obsServ =
- mozilla::services::GetObserverService();
- if (!obsServ) {
- return;
- }
-
- nsPrintfCString data("{\"x\":%d,\"y\":%d}", rounded.x, rounded.y);
- obsServ->NotifyObservers(nullptr, "Gesture:SingleTap",
- NS_ConvertASCIItoUTF16(data).get());
- });
+ DispatchSingleTapToObservers(aPoint, aGuid);
}
ChromeProcessController::HandleTap(aType, aPoint, aModifiers, aGuid, aInputBlockId);
}
void
AndroidContentController::PostDelayedTask(already_AddRefed<Runnable> aTask, int aDelayMs)
{
--- a/widget/android/AndroidContentController.h
+++ b/widget/android/AndroidContentController.h
@@ -43,14 +43,17 @@ public:
void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
APZStateChange aChange,
int aArg) override;
static void NotifyDefaultPrevented(mozilla::layers::IAPZCTreeManager* aManager,
uint64_t aInputBlockId, bool aDefaultPrevented);
private:
nsWindow* mAndroidWindow;
+
+ void DispatchSingleTapToObservers(const LayoutDevicePoint& aPoint,
+ const ScrollableLayerGuid& aGuid) const;
};
} // namespace widget
} // namespace mozilla
#endif