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 2664 1c390a1b969918332145bef7e82973ddbf178845
parent 2663 bee7f6dd725cb3421e1658cb26bfd733925085da
child 2665 3c98f02d7e4c8d7e555c60a37c2819b1946b1e22
push id2237
push usermfinkle@mozilla.com
push dateWed, 19 Jan 2011 16:44:34 +0000
reviewersvingtetun
bugs479862
Bug 479862 - scrollTop and scrollLeft might contain wrong values for scripts on pages [r=vingtetun]
chrome/content/bindings/browser.js
chrome/content/browser.js
--- a/chrome/content/bindings/browser.js
+++ b/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/chrome/content/browser.js
+++ b/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);