Bug 479862 - scrollTop and scrollLeft might contain wrong values for scripts on pages [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Wed, 19 Jan 2011 11:45:11 -0500
changeset 67278 49703cad6faa8b470c85063aa5d06cfc7f537a45
parent 67277 c669e1fe0b54864be692b8e06cd95213a6a82235
child 67279 2bd3bb2d317d3fe77c5f8040a9c8e854c9561f04
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs479862
Bug 479862 - scrollTop and scrollLeft might contain wrong values for scripts on pages [r=vingtetun]
mobile/chrome/content/bindings/browser.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/bindings/browser.js
+++ b/mobile/chrome/content/bindings/browser.js
@@ -264,34 +264,46 @@ let DOMEvents =  {
         break;
     }
   }
 };
 
 DOMEvents.init();
 
 let ContentScroll =  {
+  ignoreScroll: false,
+
   init: function() {
     addMessageListener("Content:ScrollTo", this);
     addMessageListener("Content:ScrollBy", this);
     addMessageListener("Content:SetCacheViewport", this);
     addMessageListener("Content:SetWindowSize", this);
 
     addEventListener("scroll", this, false);
     addEventListener("MozScrolledAreaChanged", this, false);
   },
 
   receiveMessage: function(aMessage) {
     let json = aMessage.json;
     switch (aMessage.name) {
-      case "Content:ScrollTo":
+      case "Content:ScrollTo": {
+        let scrollOffset = Util.getScrollOffset(content);
+        if (scrollOffset.x == json.x && scrollOffset.y == json.y)
+          return;
+
+        this.ignoreScroll = true;
         content.scrollTo(json.x, json.y);
         break;
+      }
 
       case "Content:ScrollBy":
+        if (!json.dx && !json.dy)
+          return;
+
+        this.ignoreScroll = true;
         content.scrollBy(json.dx, json.dy);
         break;
 
       case "Content:SetCacheViewport": {
         let rootCwu = Util.getWindowUtils(content);
         if (json.id == 1)
           rootCwu.setResolution(json.scale, json.scale);
 
@@ -336,16 +348,21 @@ let ContentScroll =  {
         break;
       }
     }
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "scroll": {
+        if (this.ignoreScroll) {
+          this.ignoreScroll = false;
+          return;
+        }
+
         let doc = aEvent.target;
         if (doc != content.document)
           return;
 
         let scrollOffset = Util.getScrollOffset(content);
         sendAsyncMessage("scroll", scrollOffset);
         break;
       }
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1171,16 +1171,19 @@ Browser.MainDragger.prototype = {
     let bcr = browser.getBoundingClientRect();
     this._contentView = browser.getViewAt(clientX - bcr.left, clientY - bcr.top);
   },
 
   dragStop: function dragStop(dx, dy, scroller) {
     this._contentView = null;
     this.dragMove(Browser.snapSidebars(), 0, scroller);
     Browser.tryUnfloatToolbar();
+
+    // Update the scroll position of the content
+    getBrowser()._updateCSSViewport();
   },
 
   dragMove: function dragMove(dx, dy, scroller) {
     let doffset = new Point(dx, dy);
 
     // First calculate any panning to take sidebars out of view
     let panOffset = this._panControlsAwayOffset(doffset);