Bug 1127066 - Use (nsBaseWidget's) APZEventState in ChromeProcessController. r=kats
authorBotond Ballo <botond@mozilla.com>
Mon, 09 Feb 2015 19:06:06 -0500
changeset 228807 40a4e0b2dd0807049cd47aa816cf8721fc961228
parent 228806 0c3e7de46a8873ec225e4a6510778cf591c467b2
child 228808 b9150539d7873d419d94c15d8469bb60dc111957
push id28271
push usercbook@mozilla.com
push dateThu, 12 Feb 2015 14:33:39 +0000
treeherderautoland@81f979b17fbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1127066
milestone38.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 1127066 - Use (nsBaseWidget's) APZEventState in ChromeProcessController. r=kats
gfx/layers/apz/util/ChromeProcessController.cpp
gfx/layers/apz/util/ChromeProcessController.h
widget/nsBaseWidget.cpp
--- a/gfx/layers/apz/util/ChromeProcessController.cpp
+++ b/gfx/layers/apz/util/ChromeProcessController.cpp
@@ -2,29 +2,34 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ChromeProcessController.h"
 
 #include "MainThreadUtils.h"    // for NS_IsMainThread()
 #include "base/message_loop.h"  // for MessageLoop
+#include "mozilla/dom/Element.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
+#include "mozilla/layers/APZEventState.h"
 #include "nsIDocument.h"
+#include "nsIInterfaceRequestorUtils.h"
 #include "nsIPresShell.h"
 #include "nsLayoutUtils.h"
 #include "nsView.h"
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace mozilla::widget;
 
-ChromeProcessController::ChromeProcessController(nsIWidget* aWidget)
+ChromeProcessController::ChromeProcessController(nsIWidget* aWidget,
+                                                 APZEventState* aAPZEventState)
   : mWidget(aWidget)
+  , mAPZEventState(aAPZEventState)
   , mUILoop(MessageLoop::current())
 {
   // Otherwise we're initializing mUILoop incorrectly.
   MOZ_ASSERT(NS_IsMainThread());
 
   mUILoop->PostTask(
       FROM_HERE,
       NewRunnableMethod(this, &ChromeProcessController::InitializeRoot));
@@ -35,19 +40,17 @@ ChromeProcessController::InitializeRoot(
 {
   // Create a view-id and set a zero-margin displayport for the root element
   // of the root document in the chrome process. This ensures that the scroll
   // frame for this element gets an APZC, which in turn ensures that all content
   // in the chrome processes is covered by an APZC.
   // The displayport is zero-margin because this element is generally not
   // actually scrollable (if it is, APZC will set proper margins when it's
   // scrolled).
-  nsView* view = nsView::GetViewFor(mWidget);
-  MOZ_ASSERT(view);
-  nsIPresShell* presShell = view->GetPresShell();
+  nsIPresShell* presShell = GetPresShell();
   MOZ_ASSERT(presShell);
   MOZ_ASSERT(presShell->GetDocument());
   nsIContent* content = presShell->GetDocument()->GetDocumentElement();
   MOZ_ASSERT(content);
   uint32_t presShellId;
   FrameMetrics::ViewID viewId;
   if (APZCCallbackHelper::GetOrCreateScrollIdentifiers(content, &presShellId, &viewId)) {
     nsLayoutUtils::SetDisplayPortMargins(content, presShell, ScreenMargin(), 0,
@@ -101,27 +104,76 @@ ChromeProcessController::Destroy()
 float
 ChromeProcessController::GetPresShellResolution() const
 {
   // The document in the chrome process cannot be zoomed, so its pres shell
   // resolution is 1.
   return 1.0f;
 }
 
+nsIPresShell*
+ChromeProcessController::GetPresShell() const
+{
+  nsView* view = nsView::GetViewFor(mWidget);
+  MOZ_ASSERT(view);
+  return view->GetPresShell();
+}
+
+already_AddRefed<nsIDOMWindowUtils>
+ChromeProcessController::GetDOMWindowUtils() const
+{
+  if (nsIDocument* doc = GetPresShell()->GetDocument()) {
+    nsCOMPtr<nsIDOMWindowUtils> result = do_GetInterface(doc->GetWindow());
+    return result.forget();
+  }
+  return nullptr;
+}
+
 void
 ChromeProcessController::HandleSingleTap(const CSSPoint& aPoint,
                                          int32_t aModifiers,
                                          const ScrollableLayerGuid& aGuid)
 {
   if (MessageLoop::current() != mUILoop) {
     mUILoop->PostTask(
         FROM_HERE,
         NewRunnableMethod(this, &ChromeProcessController::HandleSingleTap,
                           aPoint, aModifiers, aGuid));
     return;
   }
 
-  LayoutDevicePoint point =
-      APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid, GetPresShellResolution())
-    * mWidget->GetDefaultScale();
+  mAPZEventState->ProcessSingleTap(aPoint, aGuid, GetPresShellResolution());
+}
+
+void
+ChromeProcessController::HandleLongTap(const mozilla::CSSPoint& aPoint, int32_t aModifiers,
+                                       const ScrollableLayerGuid& aGuid,
+                                       uint64_t aInputBlockId)
+{
+  if (MessageLoop::current() != mUILoop) {
+    mUILoop->PostTask(
+        FROM_HERE,
+        NewRunnableMethod(this, &ChromeProcessController::HandleLongTap,
+                          aPoint, aModifiers, aGuid, aInputBlockId));
+    return;
+  }
 
-  APZCCallbackHelper::FireSingleTapEvent(point, mWidget);
+  mAPZEventState->ProcessLongTap(GetDOMWindowUtils(), aPoint, aGuid,
+      aInputBlockId, GetPresShellResolution());
 }
+
+void
+ChromeProcessController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
+                                              APZStateChange aChange,
+                                              int aArg)
+{
+  if (MessageLoop::current() != mUILoop) {
+    mUILoop->PostTask(
+        FROM_HERE,
+        NewRunnableMethod(this, &ChromeProcessController::NotifyAPZStateChange,
+                          aGuid, aChange, aArg));
+    return;
+  }
+
+  mAPZEventState->ProcessAPZStateChange(GetPresShell()->GetDocument(), aGuid.mScrollId, aChange, aArg);
+}
+
+
--- a/gfx/layers/apz/util/ChromeProcessController.h
+++ b/gfx/layers/apz/util/ChromeProcessController.h
@@ -3,59 +3,69 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_layers_ChromeProcessController_h
 #define mozilla_layers_ChromeProcessController_h
 
 #include "mozilla/layers/GeckoContentController.h"
 #include "nsCOMPtr.h"
+#include "nsRefPtr.h"
 
+class nsIDOMWindowUtils;
+class nsIPresShell;
 class nsIWidget;
 
 class MessageLoop;
 
 namespace mozilla {
 
 namespace layers {
+
+class APZEventState;
 class CompositorParent;
 
 // A ChromeProcessController is attached to the root of a compositor's layer
 // tree.
 class ChromeProcessController : public mozilla::layers::GeckoContentController
 {
   typedef mozilla::layers::FrameMetrics FrameMetrics;
   typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
 
 public:
-  explicit ChromeProcessController(nsIWidget* aWidget);
+  explicit ChromeProcessController(nsIWidget* aWidget, APZEventState* aAPZEventState);
   virtual void Destroy() MOZ_OVERRIDE;
 
   // GeckoContentController interface
   virtual void RequestContentRepaint(const FrameMetrics& aFrameMetrics) MOZ_OVERRIDE;
   virtual void PostDelayedTask(Task* aTask, int aDelayMs) MOZ_OVERRIDE;
   virtual void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
                                        const uint32_t& aScrollGeneration) MOZ_OVERRIDE;
 
   virtual void HandleDoubleTap(const mozilla::CSSPoint& aPoint, int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE {}
   virtual void HandleSingleTap(const mozilla::CSSPoint& aPoint, int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE;
   virtual void HandleLongTap(const mozilla::CSSPoint& aPoint, int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid,
-                               uint64_t aInputBlockId) MOZ_OVERRIDE {}
+                               uint64_t aInputBlockId) MOZ_OVERRIDE;
   virtual void HandleLongTapUp(const CSSPoint& aPoint, int32_t aModifiers,
                                const ScrollableLayerGuid& aGuid) MOZ_OVERRIDE {}
   virtual void SendAsyncScrollDOMEvent(bool aIsRoot, const mozilla::CSSRect &aContentRect,
                                        const mozilla::CSSSize &aScrollableSize) MOZ_OVERRIDE {}
-
+  virtual void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
+                                    APZStateChange aChange,
+                                    int aArg) MOZ_OVERRIDE;
 private:
   nsCOMPtr<nsIWidget> mWidget;
+  nsRefPtr<APZEventState> mAPZEventState;
   MessageLoop* mUILoop;
 
   void InitializeRoot();
   float GetPresShellResolution() const;
+  nsIPresShell* GetPresShell() const;
+  already_AddRefed<nsIDOMWindowUtils> GetDOMWindowUtils() const;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif /* mozilla_layers_ChromeProcessController_h */
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -909,17 +909,17 @@ void nsBaseWidget::CreateCompositor()
   nsIntRect rect;
   GetBounds(rect);
   CreateCompositor(rect.width, rect.height);
 }
 
 already_AddRefed<GeckoContentController>
 nsBaseWidget::CreateRootContentController()
 {
-  nsRefPtr<GeckoContentController> controller = new ChromeProcessController(this);
+  nsRefPtr<GeckoContentController> controller = new ChromeProcessController(this, mAPZEventState);
   return controller.forget();
 }
 
 class ChromeProcessSetTargetAPZCCallback : public SetTargetAPZCCallback {
 public:
   explicit ChromeProcessSetTargetAPZCCallback(APZCTreeManager* aTreeManager)
     : mTreeManager(aTreeManager)
   {}