Bug 638170 - Restore scroll position during FirstPaint [r=vingtetun]
authorWes Johnston <wjohnston@mozilla.com>
Thu, 03 Mar 2011 16:55:42 -0800
changeset 67465 8f4937a1fa8be52b231fc496789f4219ea5cf6f9
parent 67464 142df357b2227146264882cd0c88a94db5b761a6
child 67466 cba6aba978cb021d67d08ad84afe47108fe331ed
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
bugs638170
Bug 638170 - Restore scroll position during FirstPaint [r=vingtetun]
mobile/chrome/content/bindings/browser.js
mobile/chrome/content/bindings/browser.xml
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/bindings/browser.js
+++ b/mobile/chrome/content/bindings/browser.js
@@ -53,17 +53,19 @@ let WebProgressListener = {
 
     // Keep track of hash changes
     this.hashChanged = (location == this._lastLocation);
     this._lastLocation = location;
 
     // When a new page is loaded fire a message for the first paint
     addEventListener("MozAfterPaint", function(aEvent) {
       removeEventListener("MozAfterPaint", arguments.callee, true);
-      sendAsyncMessage("Browser:FirstPaint", {});
+
+      let scrollOffset = ContentScroll.getScrollOffset(content);
+      sendAsyncMessage("Browser:FirstPaint", scrollOffset);
     }, true);
   },
 
   onStatusChange: function onStatusChange(aWebProgress, aRequest, aStatus, aMessage) {
   },
 
   onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
     if (content != aWebProgress.DOMWindow)
@@ -195,18 +197,16 @@ let DOMEvents =  {
       case "DOMContentLoaded":
         if (document.documentURIObject.spec == "about:blank")
           return;
 
         sendAsyncMessage("DOMContentLoaded", { });
         break;
 
       case "pageshow":
-        if (aEvent.persisted)
-          ContentScroll.sendScroll();
       case "pagehide": {
         if (aEvent.target.defaultView != content)
           break;
 
         let util = aEvent.target.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
                                             .getInterface(Ci.nsIDOMWindowUtils);
 
         let json = {
--- a/mobile/chrome/content/bindings/browser.xml
+++ b/mobile/chrome/content/bindings/browser.xml
@@ -1053,17 +1053,21 @@
           if ("_contentView" in rootView)
             rootView._contentView.scrollTo(x, y);
         ]]></body>
       </method>
 
       <!-- After fuzzy zoom, sync the displayport with the new viewport. -->
       <method name="finishFuzzyZoom">
         <body><![CDATA[
-          this.getRootView()._updateCacheViewport();
+          let view = this.getRootView();
+
+          // ensure that we are scrolled within the page's viewable area
+          view.scrollBy(0,0);
+          view._updateCacheViewport();
 
           let event = document.createEvent("Events");
           event.initEvent("ZoomChanged", true, false);
           this.dispatchEvent(event);
         ]]></body>
       </method>
 
       <!-- The ratio of CSS pixels to device pixels. -->
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1426,24 +1426,26 @@ Browser.WebProgress.prototype = {
     // _waitForLoad would scroll to top.
     aTab.pageScrollOffset = { x: 0, y: 0 };
   },
 
   _waitForLoad: function _waitForLoad(aTab) {
     let browser = aTab.browser;
     browser.messageManager.removeMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
 
-    browser.messageManager.addMessageListener("Browser:FirstPaint", function(aMessage) {
+    browser.messageManager.addMessageListener("Browser:FirstPaint", function firstPaintListener(aMessage) {
       browser.messageManager.removeMessageListener(aMessage.name, arguments.callee);
 
       // We're about to have new page content, so scroll the content area
-      // to the top so the new paints will draw correctly.
+      // so the new paints will draw correctly.
       // Background tabs are delayed scrolled to top in _documentStop
       if (getBrowser() == browser) {
-        browser.getRootView().scrollTo(0, 0);
+        let json = aMessage.json;
+        browser.getRootView().scrollTo(Math.floor(json.x * browser.scale),
+                                       Math.floor(json.y * browser.scale));
         Browser.pageScrollboxScroller.scrollTo(0, 0);
       }
 
       aTab.scrolledAreaChanged();
       browser.messageManager.addMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
     });
   }
 };