Bug 1290823 - Factor out the code for dispatching a single tap event to observers into its own function. r=rbarker a=ritu
authorBotond Ballo <botond@mozilla.com>
Mon, 08 Aug 2016 16:12:40 -0400
changeset 347633 c5d62f297f9a9559279f74f8ff0ee4ffe7885d73
parent 347632 bef207d78f05f9b39923c40c69ecbde6b70dd80c
child 347634 285042c2d340a0f8d0314793ebfc24e040441883
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker, ritu
bugs1290823
milestone50.0a2
Bug 1290823 - Factor out the code for dispatching a single tap event to observers into its own function. r=rbarker a=ritu 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