Factor out how APZ-aware events are dispatched from widgets. (bug 1126090 part 2, r=kats)
authordvander@alliedmods.net <danderson@mozilla.com>
Fri, 06 Mar 2015 14:26:59 -0800
changeset 262636 2d15f031ead0648b05dd6c0260c957618417b078
parent 262635 6bb1f6eaba4db00ed4eddbdde4390c79c2602a81
child 262637 37077c295992f24c4a5f4c9f9559f38a77c7af23
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1126090
milestone39.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
Factor out how APZ-aware events are dispatched from widgets. (bug 1126090 part 2, r=kats)
widget/gonk/nsWindow.cpp
widget/gtk/nsWindow.cpp
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/nsIWidget.h
widget/windows/nsWindow.cpp
--- a/widget/gonk/nsWindow.cpp
+++ b/widget/gonk/nsWindow.cpp
@@ -321,17 +321,17 @@ nsWindow::DispatchTouchEventForAPZ(const
             return;
         }
     }
 
     // If it didn't get captured, dispatch the event into the gecko root process
     // for "normal" flow. The event might get sent to the child process still,
     // but if it doesn't we need to notify the APZ of various things. All of
     // that happens in DispatchEventForAPZ
-    DispatchEventForAPZ(&event, aGuid, aInputBlockId);
+    ProcessUntransformedAPZEvent(&event, aGuid, aInputBlockId);
 }
 
 class DispatchTouchInputOnControllerThread : public Task
 {
 public:
     DispatchTouchInputOnControllerThread(const MultiTouchInput& aInput)
       : Task()
       , mInput(aInput)
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -3250,29 +3250,17 @@ nsWindow::OnScrollEvent(GdkEventScroll *
                                    NSToIntFloor(aEvent->y_root));
         wheelEvent.refPoint = point - WidgetToScreenOffset();
     }
 
     KeymapWrapper::InitInputEvent(wheelEvent, aEvent->state);
 
     wheelEvent.time = aEvent->time;
 
-    if (mAPZC) {
-        uint64_t inputBlockId = 0;
-        ScrollableLayerGuid guid;
-
-        nsEventStatus result = mAPZC->ReceiveInputEvent(*wheelEvent.AsWheelEvent(), &guid, &inputBlockId);
-        if (result == nsEventStatus_eConsumeNoDefault) {
-            return;
-        }
-        DispatchEventForAPZ(&wheelEvent, guid, inputBlockId);
-    } else {
-        nsEventStatus status;
-        DispatchEvent(&wheelEvent, status);
-    }
+    DispatchAPZAwareEvent(&wheelEvent);
 }
 
 void
 nsWindow::OnVisibilityNotifyEvent(GdkEventVisibility *aEvent)
 {
     LOGDRAW(("Visibility event %i on [%p] %p\n",
              aEvent->state, this, aEvent->window));
 
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -968,19 +968,19 @@ void nsBaseWidget::ConfigureAPZCTreeMana
 
   nsRefPtr<GeckoContentController> controller = CreateRootContentController();
   if (controller) {
     CompositorParent::SetControllerForLayerTree(rootLayerTreeId, controller);
   }
 }
 
 nsEventStatus
-nsBaseWidget::DispatchEventForAPZ(WidgetGUIEvent* aEvent,
-                                  const ScrollableLayerGuid& aGuid,
-                                  uint64_t aInputBlockId)
+nsBaseWidget::ProcessUntransformedAPZEvent(WidgetInputEvent* aEvent,
+                                           const ScrollableLayerGuid& aGuid,
+                                           uint64_t aInputBlockId)
 {
   MOZ_ASSERT(NS_IsMainThread());
   InputAPZContext context(aGuid, aInputBlockId);
 
   // If this is a touch event and APZ has targeted it to an APZC in the root
   // process, apply that APZC's callback-transform before dispatching the
   // event. If the event is instead targeted to an APZC in the child process,
   // the transform will be applied in the child process before dispatching
@@ -1010,16 +1010,35 @@ nsBaseWidget::DispatchEventForAPZ(Widget
                 aGuid, aInputBlockId, mSetTargetAPZCCallback);
       mAPZEventState->ProcessWheelEvent(*wheelEvent, aGuid, aInputBlockId);
     }
   }
 
   return status;
 }
 
+nsEventStatus
+nsBaseWidget::DispatchAPZAwareEvent(WidgetInputEvent* aEvent)
+{
+  if (mAPZC) {
+    uint64_t inputBlockId = 0;
+    ScrollableLayerGuid guid;
+
+    nsEventStatus result = mAPZC->ReceiveInputEvent(*aEvent, &guid, &inputBlockId);
+    if (result == nsEventStatus_eConsumeNoDefault) {
+        return result;
+    }
+    return ProcessUntransformedAPZEvent(aEvent, guid, inputBlockId);
+  }
+
+  nsEventStatus status;
+  DispatchEvent(aEvent, status);
+  return status;
+}
+
 void
 nsBaseWidget::GetPreferredCompositorBackends(nsTArray<LayersBackend>& aHints)
 {
   if (mUseLayersAcceleration) {
     aHints.AppendElement(LayersBackend::LAYERS_OPENGL);
   }
 
   aHints.AppendElement(LayersBackend::LAYERS_BASIC);
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -227,16 +227,19 @@ public:
               bool             aForceUseIWidgetParent = false) MOZ_OVERRIDE;
   NS_IMETHOD              AttachViewToTopLevel(bool aUseAttachedEvents) MOZ_OVERRIDE;
   virtual nsIWidgetListener* GetAttachedWidgetListener() MOZ_OVERRIDE;
   virtual void               SetAttachedWidgetListener(nsIWidgetListener* aListener) MOZ_OVERRIDE;
   NS_IMETHOD              RegisterTouchWindow() MOZ_OVERRIDE;
   NS_IMETHOD              UnregisterTouchWindow() MOZ_OVERRIDE;
   NS_IMETHOD_(TextEventDispatcher*) GetTextEventDispatcher() MOZ_OVERRIDE MOZ_FINAL;
 
+  // Dispatch an event that must be first be routed through APZ.
+  nsEventStatus DispatchAPZAwareEvent(mozilla::WidgetInputEvent* aEvent) MOZ_OVERRIDE;
+
   void NotifyWindowDestroyed();
   void NotifySizeMoveDone();
   void NotifyWindowMoved(int32_t aX, int32_t aY);
 
   // Register plugin windows for remote updates from the compositor
   virtual void RegisterPluginWindowForRemoteUpdates() MOZ_OVERRIDE;
   virtual void UnregisterPluginWindowForRemoteUpdates() MOZ_OVERRIDE;
 
@@ -322,21 +325,20 @@ protected:
   virtual void    OnDestroy();
   void            BaseCreate(nsIWidget *aParent,
                              const nsIntRect &aRect,
                              nsWidgetInitData *aInitData);
 
   virtual void ConfigureAPZCTreeManager();
   virtual already_AddRefed<GeckoContentController> CreateRootContentController();
 
-  // Dispatch an event that has been routed through APZ directly from the
-  // widget.
-  nsEventStatus DispatchEventForAPZ(mozilla::WidgetGUIEvent* aEvent,
-                                    const ScrollableLayerGuid& aGuid,
-                                    uint64_t aInputBlockId);
+  // Dispatch an event that has already been routed through APZ.
+  nsEventStatus ProcessUntransformedAPZEvent(mozilla::WidgetInputEvent* aEvent,
+                                             const ScrollableLayerGuid& aGuid,
+                                             uint64_t aInputBlockId);
 
   const nsIntRegion RegionFromArray(const nsTArray<nsIntRect>& aRects);
   void ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects);
 
   virtual nsIContent* GetLastRollup() MOZ_OVERRIDE
   {
     return mLastRollup;
   }
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1683,16 +1683,23 @@ class nsIWidget : public nsISupports {
     /**
      * Dispatches an event to the widget
      *
      */
     NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* event,
                              nsEventStatus & aStatus) = 0;
 
     /**
+     * Dispatches an event that must be handled by APZ first, when APZ is
+     * enabled. If invoked in the child process, it is forwarded to the
+     * parent process synchronously.
+     */
+    virtual nsEventStatus DispatchAPZAwareEvent(mozilla::WidgetInputEvent* aEvent) = 0;
+
+    /**
      * Enables the dropping of files to a widget (XXX this is temporary)
      *
      */
     NS_IMETHOD EnableDragDrop(bool aEnable) = 0;
    
     /**
      * Enables/Disables system mouse capture.
      * @param aCapture true enables mouse capture, false disables mouse capture 
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3661,30 +3661,23 @@ bool nsWindow::DispatchKeyboardEvent(Wid
 {
   nsEventStatus status;
   DispatchEvent(event, status);
   return ConvertStatus(status);
 }
 
 bool nsWindow::DispatchScrollEvent(WidgetGUIEvent* aEvent)
 {
-  nsEventStatus status;
-
-  if (mAPZC && aEvent->mClass == eWheelEventClass) {
-    uint64_t inputBlockId = 0;
-    ScrollableLayerGuid guid;
-
-    nsEventStatus result = mAPZC->ReceiveInputEvent(*aEvent->AsWheelEvent(), &guid, &inputBlockId);
-    if (result == nsEventStatus_eConsumeNoDefault) {
-      return true;
-    }
-    status = DispatchEventForAPZ(aEvent, guid, inputBlockId);
-  } else {
+  if (aEvent->mClass != eWheelEventClass) {
+    nsEventStatus status;
     DispatchEvent(aEvent, status);
-  }
+    return ConvertStatus(status);
+  }
+
+  nsEventStatus status = DispatchAPZAwareEvent(aEvent->AsInputEvent());
   return ConvertStatus(status);
 }
 
 bool nsWindow::DispatchWindowEvent(WidgetGUIEvent* event)
 {
   nsEventStatus status;
   DispatchEvent(event, status);
   return ConvertStatus(status);