Bug 639102 - Draw thumbnails on FirstPaint. r=mbrubeck, a=pavlov
authorWes Johnston <wjohnston@mozilla.com>
Mon, 07 Mar 2011 15:01:05 -0800
changeset 67478 5b5b05bbe4e8a54a6835a291866ff4ee52217182
parent 67477 a9229236790dd4959998bed55c7fd8e76d4e5661
child 67479 59797f58a62937ab4a89c1cf5ade866c09e0268c
push idunknown
push userunknown
push dateunknown
reviewersmbrubeck, pavlov
bugs639102
Bug 639102 - Draw thumbnails on FirstPaint. r=mbrubeck, a=pavlov
mobile/chrome/content/browser.js
mobile/chrome/content/tabs.xml
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1412,19 +1412,16 @@ Browser.WebProgress.prototype = {
     }
   },
 
   _networkStop: function _networkStop(aTab) {
     aTab.endLoading();
 
     if (aTab == Browser.selectedTab)
       BrowserUI.update(TOOLBARSTATE_LOADED);
-
-    if (aTab.browser.currentURI.spec != "about:blank")
-      aTab.updateThumbnail();
   },
 
   _documentStop: function _documentStop(aTab) {
     // Make sure the URLbar is in view. If this were the selected tab,
     // _waitForLoad would scroll to top.
     aTab.pageScrollOffset = { x: 0, y: 0 };
   },
 
@@ -1441,16 +1438,18 @@ Browser.WebProgress.prototype = {
       if (getBrowser() == browser) {
         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();
+      if (browser.currentURI.spec != "about:blank")
+        aTab.updateThumbnail();
       browser.messageManager.addMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
     });
   }
 };
 
 
 function nsBrowserAccess() { }
 
@@ -2514,16 +2513,20 @@ Tab.prototype = {
   startLoading: function startLoading() {
     if (this._loading) throw "Already Loading!";
     this._loading = true;
   },
 
   endLoading: function endLoading() {
     if (!this._loading) throw "Not Loading!";
     this._loading = false;
+    if (this._drawThumb) {
+      this._drawThumb = false;
+      this.updateThumbnail();
+    }
   },
 
   isLoading: function isLoading() {
     return this._loading;
   },
 
   create: function create(aURI, aParams) {
     this._chromeTab = document.getElementById("tabs").addTab();
@@ -2709,16 +2712,21 @@ Tab.prototype = {
 
   get allowZoom() {
     return this.metadata.allowZoom && !Util.isURLEmpty(this.browser.currentURI.spec);
   },
 
   updateThumbnail: function updateThumbnail() {
     let browser = this._browser;
 
+    if (this._loading) {
+      this._drawThumb = true;
+      return;
+    }
+
     // Do not repaint thumbnail if we already painted for this load. Bad things
     // happen when we do async canvas draws in quick succession.
     if (!browser || this._thumbnailWindowId == browser.contentWindowId)
       return;
 
     // Do not try to paint thumbnails if contentWindowWidth/Height have not been
     // set yet. This also blows up for async canvas draws.
     if (!browser.contentWindowWidth || !browser.contentWindowHeight)
--- a/mobile/chrome/content/tabs.xml
+++ b/mobile/chrome/content/tabs.xml
@@ -59,31 +59,33 @@
         <parameter name="width"/>
         <parameter name="height"/>
         <body>
           <![CDATA[
             const tabWidth = 104;
             const tabHeight = 65;
 
             let ratio = tabHeight / tabWidth;
+            if (browser.contentDocumentWidth > 0)
+              width = Math.min(width, browser.contentDocumentWidth);
             height = width * ratio;
 
             let thumbnail = this.thumbnail;
             thumbnail.removeAttribute("empty");
 
             // Recreate the canvas as it may be tainted and not useable for remote pages
             if (thumbnail.hasAttribute("restored")) {
               thumbnail.removeAttribute("restored");
               thumbnail = this.thumbnail.cloneNode(false);
               this.thumbnail.parentNode.replaceChild(thumbnail, this.thumbnail);
               this.thumbnail = thumbnail;
             }
 
             let self = this;
-            let renderer = rendererFactory(browser, thumbnail)
+            let renderer = rendererFactory(browser, thumbnail);
             renderer.drawContent(function(ctx, callback) {
               ctx.save();
               ctx.clearRect(0, 0, tabWidth, tabHeight);
               ctx.scale(tabWidth / width, tabHeight / height);
               callback(browser, 0, 0, width, height, "white");
               ctx.restore();
 
               // We don't have an event for the async drawContent anymore, so hack it