Bug 476703: When switching tabs, use last pan x,y offsets, r=mfinkle
authorSHIMODA Hiroshi <shimoda@clear-code.com>
Tue, 16 Jun 2009 01:31:15 -0400
changeset 568 5e0ab5179c38
parent 567 5095102c37ca
child 569 98bf817c7201
push id504
push usermfinkle@mozilla.com
push dateTue, 16 Jun 2009 05:31:00 +0000
reviewersmfinkle
bugs476703
Bug 476703: When switching tabs, use last pan x,y offsets, r=mfinkle
chrome/content/CanvasBrowser.js
chrome/content/browser.js
--- a/chrome/content/CanvasBrowser.js
+++ b/chrome/content/CanvasBrowser.js
@@ -113,38 +113,57 @@ CanvasBrowser.prototype = {
         .getInterface(Ci.nsIDOMWindowUtils);
     }
     return this._contentDOMWindowUtils;
   },
 
   setCurrentBrowser: function setCurrentBrowser(browser, skipZoom) {
     let currentBrowser = this._browser;
     if (currentBrowser) {
+      // backup state
+      currentBrowser.mZoomLevel = this.zoomLevel;
+      currentBrowser.mPanX = ws._viewingRect.x;
+      currentBrowser.mPanY = ws._viewingRect.y;
+      
       // stop monitor paint events for this browser
       currentBrowser.removeEventListener("MozAfterPaint", this._paintHandler, false);
       currentBrowser.setAttribute("type", "content");
       currentBrowser.docShell.isOffScreenBrowser = false;
     }
+
     this._contentDOMWindowUtils = null;
 
     browser.setAttribute("type", "content-primary");
     if (!skipZoom)
       browser.docShell.isOffScreenBrowser = true;
 
     // start monitoring paint events for this browser
     var self = this;
     this._paintHandler = function(ev) { self._handleMozAfterPaint(ev); };
 
     browser.addEventListener("MozAfterPaint", this._paintHandler, false);
 
     this._browser = browser;
 
     // endLoading(and startLoading in most cases) calls zoom anyway
     if (!skipZoom) {
-      self.zoomToPage();
+      this.zoomToPage();
+    }
+
+    if ("mZoomLevel" in browser) {
+      // restore last state
+      ws.beginUpdateBatch();
+      ws.panTo(browser.mPanX, browser.mPanY);
+      this.zoomLevel = browser.mZoomLevel;
+      ws.endUpdateBatch(true);
+
+      // drop the cache
+      delete browser.mZoomLevel;
+      delete browser.mPanX;
+      delete browser.mPanY;
     }
   },
 
   // Change in zoom or offsets should require a clear
   // or a flush operation on the queue. XXX need tochanged justone to
   // be based on time taken..ie do as many paints as we can <200ms
   // returns true if q is cleared
   flushRegion: function flushRegion(viewingBoundsOnly) {
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -372,18 +372,16 @@ var Browser = {
 
     let firstTab = this._selectedTab == null;
     this._selectedTab = tab;
 
     ws.beginUpdateBatch();
     this._canvasBrowser.setCurrentBrowser(this.selectedBrowser, firstTab);
     document.getElementById("tabs").selectedItem = tab.chromeTab;
 
-    ws.panTo(0, -BrowserUI.toolbarH);
-
     if (!firstTab) {
       let webProgress = this.selectedBrowser.webProgress;
       let securityUI = this.selectedBrowser.securityUI;
 
       try {
         tab._listener.onLocationChange(webProgress, null, this.selectedBrowser.currentURI);
         if (securityUI)
           tab._listener.onSecurityChange(webProgress, null, securityUI.state);