Bug 1290823 - Factor out the code for dispatching a single tap event to observers into its own function. r=rbarker
authorBotond Ballo <botond@mozilla.com>
Mon, 08 Aug 2016 16:12:40 -0400
changeset 349893 6ee3b3be309baa1a40ed3c036cab4671359a3bed
parent 349892 54c34dbafa19ba57727f2b23921c40fdd7e160cf
child 349894 7faf4ab858f35ba51a9020000a71952301b586a6
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1290823
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
widget/android/AndroidContentController.cpp
widget/android/AndroidContentController.h
--- 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