Bug 1146020 - Make APZCCallbackHandler extend from ChromeProcessController. r=kats
authorDanilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
Fri, 27 Mar 2015 15:18:19 -0400
changeset 236292 6e2c1ed29f14c44d4f56984240a58aebefa147b1
parent 236291 2e874a1e7a7a260eb3936f417d21fa11014ef074
child 236293 ffcb5e699ef5cfcc7ed12bd252c323af00d7b02d
push id28494
push userphilringnalda@gmail.com
push dateSat, 28 Mar 2015 18:46:06 +0000
treeherdermozilla-central@e16dc56f90d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1146020
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
Bug 1146020 - Make APZCCallbackHandler extend from ChromeProcessController. r=kats This is one of the first steps to implement use APZC on Fennec.
widget/android/APZCCallbackHandler.cpp
widget/android/APZCCallbackHandler.h
widget/android/AndroidJNI.cpp
widget/android/nsWindow.cpp
--- a/widget/android/APZCCallbackHandler.cpp
+++ b/widget/android/APZCCallbackHandler.cpp
@@ -20,23 +20,25 @@ using mozilla::layers::APZCCallbackHelpe
 using mozilla::layers::APZCTreeManager;
 using mozilla::layers::FrameMetrics;
 using mozilla::layers::ScrollableLayerGuid;
 
 namespace mozilla {
 namespace widget {
 namespace android {
 
-StaticRefPtr<APZCCallbackHandler> APZCCallbackHandler::sInstance;
+StaticRefPtr<APZCCallbackHandler>         APZCCallbackHandler::sInstance;
+
+NativePanZoomController::GlobalRef APZCCallbackHandler::sNativePanZoomController = nullptr;
 
 NativePanZoomController::LocalRef
 APZCCallbackHandler::SetNativePanZoomController(NativePanZoomController::Param obj)
 {
-    NativePanZoomController::LocalRef old = mNativePanZoomController;
-    mNativePanZoomController = obj;
+    NativePanZoomController::LocalRef old = sNativePanZoomController;
+    sNativePanZoomController = obj;
     return old;
 }
 
 void
 APZCCallbackHandler::NotifyDefaultPrevented(uint64_t aInputBlockId,
                                             bool aDefaultPrevented)
 {
     if (!AndroidBridge::IsJavaUiThread()) {
@@ -51,121 +53,16 @@ APZCCallbackHandler::NotifyDefaultPreven
 
     MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
     APZCTreeManager* controller = nsWindow::GetAPZCTreeManager();
     if (controller) {
         controller->ContentReceivedInputBlock(aInputBlockId, aDefaultPrevented);
     }
 }
 
-nsIDOMWindowUtils*
-APZCCallbackHandler::GetDOMWindowUtils()
-{
-    nsIAndroidBrowserApp* browserApp = nullptr;
-    if (!nsAppShell::gAppShell) {
-        return nullptr;
-    }
-    nsAppShell::gAppShell->GetBrowserApp(&browserApp);
-    if (!browserApp) {
-        return nullptr;
-    }
-    nsIBrowserTab* tab = nullptr;
-    if (browserApp->GetSelectedTab(&tab) != NS_OK) {
-        return nullptr;
-    }
-    nsIDOMWindow* window = nullptr;
-    if (tab->GetWindow(&window) != NS_OK) {
-        return nullptr;
-    }
-    nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(window);
-    return utils.get();
-}
-
-void
-APZCCallbackHandler::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
-{
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(aFrameMetrics.GetScrollId() != FrameMetrics::NULL_SCROLL_ID);
-
-    if (aFrameMetrics.GetIsRoot()) {
-        nsIDOMWindowUtils* utils = GetDOMWindowUtils();
-        if (utils && APZCCallbackHelper::HasValidPresShellId(utils, aFrameMetrics)) {
-            FrameMetrics metrics = aFrameMetrics;
-            APZCCallbackHelper::UpdateRootFrame(utils, metrics);
-        }
-    } else {
-        // aFrameMetrics.mIsRoot is false, so we are trying to update a subframe.
-        // This requires special handling.
-        nsCOMPtr<nsIContent> content = nsLayoutUtils::FindContentFor(aFrameMetrics.GetScrollId());
-        if (content) {
-            FrameMetrics newSubFrameMetrics(aFrameMetrics);
-            APZCCallbackHelper::UpdateSubFrame(content, newSubFrameMetrics);
-        }
-    }
-}
-
-void
-APZCCallbackHandler::RequestFlingSnap(const FrameMetrics::ViewID& aScrollId,
-                                      const mozilla::CSSPoint& aDestination)
-{
-    APZCCallbackHelper::RequestFlingSnap(aScrollId, aDestination);
-}
-
-void
-APZCCallbackHandler::AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
-                                             const uint32_t& aScrollGeneration)
-{
-    APZCCallbackHelper::AcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
-}
-
-void
-APZCCallbackHandler::HandleDoubleTap(const CSSPoint& aPoint,
-                                     Modifiers aModifiers,
-                                     const mozilla::layers::ScrollableLayerGuid& aGuid)
-{
-    CSSIntPoint point = RoundedToInt(aPoint);
-    nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
-    nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
-            NS_LITERAL_CSTRING("Gesture:DoubleTap"), data));
-}
-
-void
-APZCCallbackHandler::HandleSingleTap(const CSSPoint& aPoint,
-                                     Modifiers aModifiers,
-                                     const mozilla::layers::ScrollableLayerGuid& aGuid)
-{
-    // FIXME Send the modifier data to Gecko for use in mouse events.
-    CSSIntPoint point = RoundedToInt(aPoint);
-    nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
-    nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
-            NS_LITERAL_CSTRING("Gesture:SingleTap"), data));
-}
-
-void
-APZCCallbackHandler::HandleLongTap(const CSSPoint& aPoint,
-                                   Modifiers aModifiers,
-                                   const mozilla::layers::ScrollableLayerGuid& aGuid,
-                                   uint64_t aInputBlockId)
-{
-    // TODO send content response back to APZC
-    CSSIntPoint point = RoundedToInt(aPoint);
-    nsCString data = nsPrintfCString("{ \"x\": %d, \"y\": %d }", point.x, point.y);
-    nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeBroadcastEvent(
-            NS_LITERAL_CSTRING("Gesture:LongPress"), data));
-}
-
-void
-APZCCallbackHandler::SendAsyncScrollDOMEvent(bool aIsRoot,
-                                             const CSSRect& aContentRect,
-                                             const CSSSize& aScrollableSize)
-{
-    // no-op, we don't want to support this event on fennec, and we
-    // want to get rid of this entirely. See bug 898075.
-}
-
 void
 APZCCallbackHandler::PostDelayedTask(Task* aTask, int aDelayMs)
 {
     AndroidBridge::Bridge()->PostTaskToUiThread(aTask, aDelayMs);
 }
 
 } // namespace android
 } // namespace widget
--- a/widget/android/APZCCallbackHandler.h
+++ b/widget/android/APZCCallbackHandler.h
@@ -1,67 +1,58 @@
 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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/. */
 
 #ifndef APZCCallbackHandler_h__
 #define APZCCallbackHandler_h__
 
-#include "mozilla/layers/GeckoContentController.h"
+#include "mozilla/layers/ChromeProcessController.h"
+#include "mozilla/layers/APZEventState.h"
 #include "mozilla/EventForwards.h"  // for Modifiers
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "GeneratedJNIWrappers.h"
 #include "nsIDOMWindowUtils.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 namespace widget {
 namespace android {
 
-class APZCCallbackHandler final : public mozilla::layers::GeckoContentController
+class APZCCallbackHandler final : public mozilla::layers::ChromeProcessController
 {
 private:
     static StaticRefPtr<APZCCallbackHandler> sInstance;
-    NativePanZoomController::GlobalRef mNativePanZoomController;
+
+    static NativePanZoomController::GlobalRef sNativePanZoomController;
 
 private:
-    APZCCallbackHandler()
-      : mNativePanZoomController(nullptr)
+    APZCCallbackHandler(nsIWidget* aWidget, mozilla::layers::APZEventState* aAPZEventState)
+      : mozilla::layers::ChromeProcessController(aWidget, aAPZEventState)
     {}
 
-    nsIDOMWindowUtils* GetDOMWindowUtils();
+public:
+    static void Initialize(nsIWidget* aWidget, mozilla::layers::APZEventState* aAPZEventState) {
 
-public:
+        MOZ_ASSERT(!sInstance.get(), "APZCCallbackHandler.Initialize() got called twice");
+        sInstance = new APZCCallbackHandler(aWidget, aAPZEventState);
+    }
+
     static APZCCallbackHandler* GetInstance() {
-        if (sInstance.get() == nullptr) {
-            sInstance = new APZCCallbackHandler();
-        }
+        MOZ_ASSERT(sInstance.get(), "Calling APZCCallbackHandler.GetInstance() before it's initialization");
         return sInstance.get();
     }
 
-    NativePanZoomController::LocalRef SetNativePanZoomController(NativePanZoomController::Param obj);
+    static NativePanZoomController::LocalRef SetNativePanZoomController(NativePanZoomController::Param obj);
     void NotifyDefaultPrevented(uint64_t aInputBlockId, bool aDefaultPrevented);
 
-public: // GeckoContentController methods
-    void RequestContentRepaint(const mozilla::layers::FrameMetrics& aFrameMetrics) override;
-    void RequestFlingSnap(const mozilla::layers::FrameMetrics::ViewID& aScrollId,
-                          const mozilla::CSSPoint& aDestination) override;
-    void AcknowledgeScrollUpdate(const mozilla::layers::FrameMetrics::ViewID& aScrollId,
-                                 const uint32_t& aScrollGeneration) override;
-    void HandleDoubleTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
-                         const mozilla::layers::ScrollableLayerGuid& aGuid) override;
-    void HandleSingleTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
-                         const mozilla::layers::ScrollableLayerGuid& aGuid) override;
-    void HandleLongTap(const mozilla::CSSPoint& aPoint, Modifiers aModifiers,
-                       const mozilla::layers::ScrollableLayerGuid& aGuid,
-                       uint64_t aInputBlockId) override;
-    void SendAsyncScrollDOMEvent(bool aIsRoot, const mozilla::CSSRect& aContentRect,
-                                 const mozilla::CSSSize& aScrollableSize) override;
+public: // ChromeProcessController methods
+
     void PostDelayedTask(Task* aTask, int aDelayMs) override;
 };
 
 } // namespace android
 } // namespace widget
 } // namespace mozilla
 
 #endif
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -898,17 +898,17 @@ NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject instance)
 {
     if (!AndroidBridge::Bridge()) {
         return;
     }
 
     const auto& newRef = NativePanZoomController::Ref::From(instance);
     NativePanZoomController::LocalRef oldRef =
-            APZCCallbackHandler::GetInstance()->SetNativePanZoomController(newRef);
+            APZCCallbackHandler::SetNativePanZoomController(newRef);
 
     MOZ_ASSERT(!oldRef, "Registering a new NPZC when we already have one");
 }
 
 NS_EXPORT jboolean JNICALL
 Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env, jobject instance, jobject event)
 {
     APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
@@ -942,17 +942,17 @@ Java_org_mozilla_gecko_gfx_NativePanZoom
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject instance)
 {
     if (!AndroidBridge::Bridge()) {
         return;
     }
 
     NativePanZoomController::LocalRef oldRef =
-            APZCCallbackHandler::GetInstance()->SetNativePanZoomController(nullptr);
+            APZCCallbackHandler::SetNativePanZoomController(nullptr);
 
     MOZ_ASSERT(oldRef, "Clearing a non-existent NPZC");
 }
 
 NS_EXPORT jboolean JNICALL
 Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint(JNIEnv* env, jobject instance)
 {
     // FIXME implement this
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -2481,16 +2481,18 @@ nsWindow::ConfigureAPZCTreeManager()
     if (!sApzcTreeManager) {
         sApzcTreeManager = mAPZC;
     }
 }
 
 already_AddRefed<GeckoContentController>
 nsWindow::CreateRootContentController()
 {
+    widget::android::APZCCallbackHandler::Initialize(this, mAPZEventState);
+
     nsRefPtr<widget::android::APZCCallbackHandler> controller =
         widget::android::APZCCallbackHandler::GetInstance();
     return controller.forget();
 }
 
 uint64_t
 nsWindow::RootLayerTreeId()
 {