Bug 483425 - bandaid visual jarring when clicking on link r=mfinkle
authorTaras Glek <tglek@mozilla.com>
Thu, 19 Mar 2009 10:31:12 -0700
changeset 65129 7eb7487f5e7f16cf25177de4e2c8343c44c121c7
parent 65128 4ea10fc4bf82f45b7cd09604bc584d6d207260cf
child 65130 32f7b1800a7dacac9d0729430daa66f6e62050cd
push idunknown
push userunknown
push dateunknown
reviewersmfinkle
bugs483425
Bug 483425 - bandaid visual jarring when clicking on link r=mfinkle
mobile/chrome/content/CanvasBrowser.js
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/CanvasBrowser.js
+++ b/mobile/chrome/content/CanvasBrowser.js
@@ -73,16 +73,19 @@ CanvasBrowser.prototype = {
   // for cancelling when we end page loads
   _drawTimeout: 0,
 
   // the max right/bottom coords we saw from paint events
   // while we were loading a page.  If we see something that's bigger than
   // either, we'll trigger a page zoom.
   _maxRight: 0,
   _maxBottom: 0,
+  
+  // Tells us to pan to top before first draw 
+  _needToPanToTop: false,
 
   get canvasDimensions() {
     if (!this._canvasRect) {
       let canvasRect = this._canvas.getBoundingClientRect();
       this._canvasRect = {
         width: canvasRect.width,
         height: canvasRect.height
       };
@@ -233,28 +236,20 @@ CanvasBrowser.prototype = {
 
   clearRegion: function clearRegion() {
     // once all of the rectangles have been subtracted
     // region ends up in a funny state unless it's reset
     this._rgnPage.setToRect(0,0,0,0);
   },
 
   startLoading: function startLoading() {
-    // Clear the whole canvas
-    // we clear the whole canvas because the browser's width or height
-    // could be less than the area we end up actually drawing.
-    this.clearRegion();
-    var ctx = this._canvas.getContext("2d");
-    ctx.fillStyle = "rgb(255,255,255)";
-    ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);
-
     this._maxRight = 0;
     this._maxBottom = 0;
-
     this._pageLoading = true;
+    this._needToPanToTop = true;
   },
 
   endLoading: function() {
     this._pageLoading = false;
     this._maybeZoomToPage = false;
     this.zoomToPage();
     // flush the region, to reduce startPanning delay
     // and to avoid getting a black border in tab thumbnail
@@ -281,18 +276,16 @@ CanvasBrowser.prototype = {
     this._isPanning = false;
   },
 
   viewportHandler: function viewportHandler(bounds, boundsSizeChanged) {
     this._isPanning = false;
     let pageBounds = bounds.clone();
     let visibleBounds = ws.viewportVisibleRect;
 
-    //should add a divide/multiply func to pageBounds
-
     // do not floor top/left, or the blit below will be off
     pageBounds.top = this._screenToPage(pageBounds.top);
     pageBounds.left = this._screenToPage(pageBounds.left);
     pageBounds.bottom = Math.ceil(this._screenToPage(pageBounds.bottom));
     pageBounds.right = Math.ceil(this._screenToPage(pageBounds.right));
 
     visibleBounds.top = Math.max(0, this._screenToPage(visibleBounds.top));
     visibleBounds.left = Math.max(0, this._screenToPage(visibleBounds.left));
@@ -490,24 +483,34 @@ CanvasBrowser.prototype = {
     var zoomDelta = 0.05; // 1/20
     if (aDirection >= 0)
       zoomDelta *= -1;
 
     this.zoomLevel = this._zoomLevel + zoomDelta;
   },
 
   zoomToPage: function() {
-    //dump("zoom to page\n");
+    let needToPanToTop = this._needToPanToTop;
+    // Ensure pages are panned at the top before zooming/painting
+    // combine the initial pan + zoom into a transaction
+    if (needToPanToTop) {
+      ws.beginUpdateBatch();      
+      this._needToPanToTop = false;
+      ws.panTo(0, 0);
+    }
     // Adjust the zoomLevel to fit the page contents in our window
     // width
     let [contentW, ] = this._contentAreaDimensions;
     let [canvasW, ] = this.canvasDimensions;
 
     if (contentW > canvasW)
       this.zoomLevel = canvasW / contentW;
+    
+    if (needToPanToTop)
+      ws.endUpdateBatch();
   },
 
   zoomToElement: function(aElement) {
     const margin = 15;
 
     let elRect = this._getPagePosition(aElement);
     let elWidth = elRect.width;
     let visibleViewportWidth = this._pageToScreen(this._visibleBounds.width);
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -251,19 +251,16 @@ var BrowserUI = {
         this._setIcon(this._faviconLink);
         this.updateIcon();
         this._faviconLink = null;
         break;
 
       case TOOLBARSTATE_LOADING:
         this.show(UIMODE_URLVIEW);
         icons.setAttribute("mode", "loading");
-
-        ws.panTo(0, -60, true);
-
         this._favicon.src = "";
         this._faviconLink = null;
         this.updateIcon();
         break;
     }
   },
 
   updateIcon : function() {