Bug 1498812 - Part 2: Switch GeckoViewScrollChild to use the visual viewport. r=snorp
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 11 Jan 2019 19:49:04 +0000
changeset 453546 bbbb9e3c793d
parent 453545 466e822d2986
child 453547 bf744ce7867a
push id35360
push usernbeleuzu@mozilla.com
push dateSat, 12 Jan 2019 09:39:47 +0000
treeherdermozilla-central@cb35977ae7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1498812, 1371796
milestone66.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 1498812 - Part 2: Switch GeckoViewScrollChild to use the visual viewport. r=snorp Given the usage example of pull-to-refresh in bug 1371796, downstream consumers will probably more interested in the true visible scroll position of the user within the page, i.e. the visual viewport. Listening for *visual* viewport events will also definitively be required to get the saveAndRestoreState GeckoView test properly working once we switch Gecko's session store helper function to use the *visual* viewport scroll position. Differential Revision: https://phabricator.services.mozilla.com/D15682
mobile/android/chrome/geckoview/GeckoViewScrollChild.js
--- a/mobile/android/chrome/geckoview/GeckoViewScrollChild.js
+++ b/mobile/android/chrome/geckoview/GeckoViewScrollChild.js
@@ -3,37 +3,39 @@
  * 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/. */
 
 ChromeUtils.import("resource://gre/modules/GeckoViewChildModule.jsm");
 
 class GeckoViewScrollChild extends GeckoViewChildModule {
   onEnable() {
     debug `onEnable`;
-    addEventListener("scroll", this, false);
+    addEventListener("mozvisualscroll", this, { mozSystemGroup: true });
   }
 
   onDisable() {
     debug `onDisable`;
-    removeEventListener("scroll", this);
+    removeEventListener("mozvisualscroll", { mozSystemGroup: true });
   }
 
   handleEvent(aEvent) {
-    if (aEvent.originalTarget.defaultView != content) {
+    if (aEvent.originalTarget.ownerGlobal != content) {
       return;
     }
 
     debug `handleEvent: ${aEvent.type}`;
 
     switch (aEvent.type) {
-      case "scroll":
+      case "mozvisualscroll":
+        let x = {}, y = {};
+        content.windowUtils.getVisualViewportOffset(x, y);
         this.eventDispatcher.sendRequest({
           type: "GeckoView:ScrollChanged",
-          scrollX: Math.round(content.scrollX),
-          scrollY: Math.round(content.scrollY),
+          scrollX: x.value,
+          scrollY: y.value,
         });
         break;
     }
   }
 }
 
 let {debug, warn} = GeckoViewScrollChild.initLogging("GeckoViewScroll");
 let module = GeckoViewScrollChild.create(this);