Bug 913909 - Fix saving of scroll offset from APZC [r=jimm]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 15 Oct 2013 14:49:02 -0700
changeset 165685 bb7cbe5f16d3719a40c401febcaa96c8207095ae
parent 165684 43807e2ed2839f18001829b4bfb35a5ad78efaa4
child 165686 8c8de10998cb42ff3a7cafb470c5602d040c0e6e
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs913909
milestone27.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 913909 - Fix saving of scroll offset from APZC [r=jimm]
browser/metro/base/content/bindings/browser.js
--- a/browser/metro/base/content/bindings/browser.js
+++ b/browser/metro/base/content/bindings/browser.js
@@ -543,16 +543,17 @@ let DOMEvents =  {
         break;
     }
   }
 };
 
 DOMEvents.init();
 
 let ContentScroll =  {
+  // The most recent offset set by APZC for the root scroll frame
   _scrollOffset: { x: 0, y: 0 },
 
   init: function() {
     addMessageListener("Content:SetCacheViewport", this);
     addMessageListener("Content:SetWindowSize", this);
 
     if (Services.prefs.getBoolPref("layers.async-pan-zoom.enabled")) {
       addEventListener("scroll", this, false);
@@ -612,19 +613,23 @@ let ContentScroll =  {
           break;
 
         let binding = element.ownerDocument.getBindingParent(element);
         if (binding instanceof Ci.nsIDOMHTMLInputElement && binding.mozIsTextField(false))
           break;
 
         // Set the scroll offset for this element if specified
         if (json.scrollX >= 0 || json.scrollY >= 0) {
-          this.setScrollOffsetForElement(element, json.scrollX, json.scrollY)
-          if (json.id == 1)
+          this.setScrollOffsetForElement(element, json.scrollX, json.scrollY);
+          if (element == content.document.documentElement) {
+            // scrollTo can make some small adjustments to the offset before
+            // actually scrolling the document.  To ensure that _scrollOffset
+            // actually matches the offset stored in the window, re-query it.
             this._scrollOffset = this.getScrollOffset(content);
+          }
         }
 
         // Set displayport. We want to set this after setting the scroll offset, because
         // it is calculated based on the scroll offset.
         let scrollOffset = this.getScrollOffsetForElement(element);
         let x = displayport.x - scrollOffset.x;
         let y = displayport.y - scrollOffset.y;
 
@@ -685,16 +690,19 @@ let ContentScroll =  {
     let isRoot = false;
     if (target instanceof Ci.nsIDOMDocument) {
       var window = target.defaultView;
       var scrollOffset = this.getScrollOffset(window);
       var element = target.documentElement;
 
       if (target == content.document) {
         if (this._scrollOffset.x == scrollOffset.x && this._scrollOffset.y == scrollOffset.y) {
+          // Don't send a scroll message back to APZC if it's the same as the
+          // last one set by APZC.  We use this to avoid sending APZC back an
+          // event that it originally triggered.
           return;
         }
         this._scrollOffset = scrollOffset;
         isRoot = true;
       }
     } else {
       var window = target.currentDoc.defaultView;
       var scrollOffset = this.getScrollOffsetForElement(target);