Bug 672411 - Calculate the viewport height correctly for non-scalable pages [r=wesj]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 29 Jul 2011 07:18:50 -0700
changeset 75911 f3f755ec65868764f290f486d2216cfc26bac361
parent 75910 8177de770dd2d7eee08dad3908070abbb3480876
child 75912 40eedacb461c4c4261ea7f7b4b20fd9d1375a2f8
push id21068
push userbmo@edmorley.co.uk
push dateFri, 26 Aug 2011 01:18:22 +0000
treeherdermozilla-central@e87454393401 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs672411
milestone9.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 672411 - Calculate the viewport height correctly for non-scalable pages [r=wesj]
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -2802,18 +2802,19 @@ Tab.prototype = {
       } else if (!validW && !validH) {
         viewportW = Browser.defaultBrowserWidth;
         viewportH = Browser.defaultBrowserWidth * (screenH / screenW);
       }
     }
 
     // Make sure the viewport height is not shorter than the window when
     // the page is zoomed out to show its full width.
-    if (viewportH * this.clampZoomLevel(this.getPageZoomLevel()) < screenH)
-      viewportH = Math.max(viewportH, screenH * (browser.contentDocumentWidth / screenW));
+    let pageZoomLevel = this.getPageZoomLevel(screenW);
+    let minScale = this.clampZoomLevel(pageZoomLevel, pageZoomLevel);
+    viewportH = Math.max(viewportH, screenH / minScale);
 
     if (browser.contentWindowWidth != viewportW || browser.contentWindowHeight != viewportH)
       browser.setWindowSize(viewportW, viewportH);
   },
 
   restoreViewportPosition: function restoreViewportPosition(aOldWidth, aNewWidth) {
     let browser = this._browser;
 
@@ -2935,21 +2936,33 @@ Tab.prototype = {
       this._notification = null;
       this._browser = null;
       this._loading = false;
 
       Elements.browsers.removeChild(notification);
     }
   },
 
-  clampZoomLevel: function clampZoomLevel(aScale) {
+  /**
+   * Takes a scale and restricts it based on this tab's zoom limits.
+   * @param aScale The original scale.
+   * @param aPageZoomLevel (optional) The zoom-to-fit scale, if known.
+   *   This is a performance optimization to avoid extra calls.
+   */
+  clampZoomLevel: function clampZoomLevel(aScale, aPageZoomLevel) {
+    let md = this.metadata;
+    if (!this.allowZoom) {
+      return (md && md.defaultZoom)
+        ? md.defaultZoom
+        : (aPageZoomLevel || this.getPageZoomLevel());
+    }
+
     let browser = this._browser;
     let bounded = Util.clamp(aScale, ZoomManager.MIN, ZoomManager.MAX);
 
-    let md = this.metadata;
     if (md && md.minZoom)
       bounded = Math.max(bounded, md.minZoom);
     if (md && md.maxZoom)
       bounded = Math.min(bounded, md.maxZoom);
 
     bounded = Math.max(bounded, this.getPageZoomLevel());
 
     let rounded = Math.round(bounded * kBrowserViewZoomLevelPrecision) / kBrowserViewZoomLevelPrecision;
@@ -3018,22 +3031,28 @@ Tab.prototype = {
     let granularity = Services.prefs.getIntPref("browser.ui.zoom.pageFitGranularity");
     let threshold = 1 - 1 / granularity;
     if (threshold < pageZoom && pageZoom < 1)
       pageZoom = 1;
 
     return this.clampZoomLevel(pageZoom);
   },
 
-  getPageZoomLevel: function getPageZoomLevel() {
+  /**
+   * @param aScreenWidth (optional) The width of the browser widget, if known.
+   *   This is a performance optimization to save extra calls to getBoundingClientRect.
+   * @return The scale at which the browser will be zoomed out to fit the document width.
+   */
+  getPageZoomLevel: function getPageZoomLevel(aScreenWidth) {
     let browserW = this._browser.contentDocumentWidth;
     if (browserW == 0)
       return 1.0;
 
-    return this._browser.getBoundingClientRect().width / browserW;
+    let screenW = aScreenWidth || this._browser.getBoundingClientRect().width;
+    return screenW / browserW;
   },
 
   get allowZoom() {
     return this.metadata.allowZoom && !Util.isURLEmpty(this.browser.currentURI.spec);
   },
 
   updateThumbnail: function updateThumbnail(options) {
     let options = options || {};