Bug 729537 - Make sure the displayport is always set correctly. r=mfinkle
authorChris Lord <chrislord.net@gmail.com>
Thu, 23 Feb 2012 13:45:32 +0000
changeset 89225 15e3fc38103fa0a88eed6803fb4e11f0eb753902
parent 89224 e66077845005b40a6c5e0bfb91cbb5a777d05783
child 89226 c8451607557be802afca5e89b91575e4c998497c
push id22242
push userkgupta@mozilla.com
push dateWed, 14 Mar 2012 15:19:09 +0000
treeherdermozilla-central@936ef50fa498 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs729537
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 729537 - Make sure the displayport is always set correctly. r=mfinkle We were seeing unexpectedly large buffers and oddness until the first pinch-zoom. This was caused by not setting the displayport correctly. Change things up so that we just use the window size and resize events instead of the viewport size (which is sent asynchronously to resize events) and make sure to set the displayport whenever necessary.
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -283,16 +283,28 @@ var BrowserApp = {
       if (window.arguments[1])
         forceRestore = window.arguments[1];
       if (window.arguments[2])
         gScreenWidth = window.arguments[2];
       if (window.arguments[3])
         gScreenHeight = window.arguments[3];
     }
 
+    // Monitor window size changes
+    window.addEventListener("resize", function() {
+      if (gScreenWidth != window.outerWidth || gScreenHeight != window.outerHeight) {
+        gScreenWidth = window.outerWidth;
+        gScreenHeight = window.outerHeight;
+        BrowserApp.selectedTab.refreshDisplayPort();
+
+        // Java pauses updates until we confirm we have the new display size
+        sendMessageToJava({ gecko: { type: "Viewport:UpdateAndDraw" } });
+      }
+    }, false);
+
     // XXX maybe we don't do this if the launch was kicked off from external
     Services.io.offline = false;
 
     // Broadcast a UIReady message so add-ons know we are finished with startup
     let event = document.createEvent("Events");
     event.initEvent("UIReady", true, false);
     window.dispatchEvent(event);
 
@@ -427,16 +439,17 @@ var BrowserApp = {
     if (this._selectedTab)
       this._selectedTab.setActive(false);
 
     this._selectedTab = aTab;
     if (!aTab)
       return;
 
     aTab.setActive(true);
+    aTab.refreshDisplayPort();
     aTab.updateViewport(false);
     this.deck.selectedPanel = aTab.browser;
   },
 
   get selectedBrowser() {
     if (this._selectedTab)
       return this._selectedTab.browser;
     return null;
@@ -1585,44 +1598,47 @@ Tab.prototype = {
       this.browser.focus();
       this.browser.docShellIsActive = true;
     } else {
       this.browser.setAttribute("type", "content-targetable");
       this.browser.docShellIsActive = false;
     }
   },
 
+  refreshDisplayPort: function refreshDisplayPort() {
+    if (this._zoom <= 0)
+      return;
+
+    dump("### Setting displayport, screen-size = " + gScreenWidth + "x" + gScreenHeight + ", zoom = " + this._zoom);
+    let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsIDOMWindowUtils);
+    cwu.setResolution(this._zoom, this._zoom);
+    cwu.setDisplayPortForElement(-kBufferAmount / this._zoom, -kBufferAmount / this._zoom,
+                                 (gScreenWidth + kBufferAmount * 2) / this._zoom,
+                                 (gScreenHeight + kBufferAmount * 2) / this._zoom,
+                                 this.browser.contentDocument.documentElement);
+  },
+
   set viewport(aViewport) {
     // Transform coordinates based on zoom
     aViewport.x /= aViewport.zoom;
     aViewport.y /= aViewport.zoom;
 
     // Set scroll position
     let win = this.browser.contentWindow;
     win.scrollTo(aViewport.x, aViewport.y);
     this.userScrollPos.x = win.scrollX;
     this.userScrollPos.y = win.scrollY;
 
-    gScreenWidth = aViewport.width;
-    gScreenHeight = aViewport.height;
-    dump("### gScreenWidth = " + gScreenWidth + "\n");
-
+    // Set zoom level
     let zoom = aViewport.zoom;
-    let cwu = window.top.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindowUtils);
-
     if (Math.abs(zoom - this._zoom) >= 1e-6) {
       this._zoom = zoom;
-      cwu.setResolution(zoom, zoom);
+      this.refreshDisplayPort();
     }
-
-    cwu.setDisplayPortForElement(-kBufferAmount / zoom, -kBufferAmount / zoom,
-                                 (gScreenWidth + kBufferAmount * 2) / zoom,
-                                 (gScreenHeight + kBufferAmount * 2) / zoom,
-                                 this.browser.contentDocument.documentElement);
   },
 
   get viewport() {
     let viewport = {
       width: gScreenWidth,
       height: gScreenHeight,
       pageWidth: gScreenWidth,
       pageHeight: gScreenHeight,
@@ -1675,16 +1691,17 @@ Tab.prototype = {
 
   updateViewport: function(aReset, aZoomLevel) {
     dump("### JS side updateViewport " + aReset + " zoom " + aZoomLevel + "\n");
 
     if (aReset) {
       if (!aZoomLevel)
         aZoomLevel = this.getDefaultZoomLevel();
       this._zoom = aZoomLevel;
+      this.refreshDisplayPort();
     }
 
     this.sendViewportUpdate();
   },
 
   sendViewportUpdate: function() {
     if (BrowserApp.selectedTab != this)
       return;
@@ -2140,16 +2157,17 @@ Tab.prototype = {
           // FIXME: This is a workaround for the fact that we suppress draw events.
           // This means we need to retrigger a draw event here since we might
           // have suppressed a draw event before documentIdForCurrentViewport
           // got updated. The real fix is to get rid of suppressing draw events
           // based on the value of documentIdForCurrentViewport, which we
           // can do once the docshell and the browser element are aware 
           // of the existence of <meta viewport>. 
           sendMessageToJava({ gecko: { type: "Viewport:UpdateAndDraw" } });
+          this.refreshDisplayPort();
         }
         break;
     }
   },
 
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsIWebProgressListener,
     Ci.nsISHistoryListener,