Bug 707571 (part 1) - Make viewport calculations respect zoom limits set by the page [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 18 May 2012 18:36:47 -0700
changeset 98480 18a75044ea04cee09812b38c87b5220c923714e9
parent 98479 ab3f805f32102b91ff3d10081f1b55e6d4864dac
child 98481 203bc6e6dc1676743535aff3b309a090aa36514d
push id1116
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 19:38:18 +0000
treeherdermozilla-beta@95f959a8b4dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs707571
milestone15.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 707571 (part 1) - Make viewport calculations respect zoom limits set by the page [r=mfinkle]
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -2417,16 +2417,17 @@ Tab.prototype = {
     this.setBrowserSize(viewportW, viewportH);
     let minScale = 1.0;
     if (this.browser.contentDocument) {
       // this may get run during a Viewport:Change message while the document
       // has not yet loaded, so need to guard against a null document.
       let [pageWidth, pageHeight] = this.getPageSize(this.browser.contentDocument, viewportW, viewportH);
       minScale = gScreenWidth / pageWidth;
     }
+    minScale = this.clampZoom(minScale);
     viewportH = Math.max(viewportH, screenH / minScale);
     this.setBrowserSize(viewportW, viewportH);
 
     // Avoid having the scroll position jump around after device rotation.
     let win = this.browser.contentWindow;
     this.userScrollPos.x = win.scrollX;
     this.userScrollPos.y = win.scrollY;
 
@@ -2438,29 +2439,45 @@ Tab.prototype = {
     // 3. screen size remains constant, but CSS viewport changes (meta viewport
     //    tag is added or removed)
     // 4. neither screen size nor CSS viewport changes
     //
     // In all of these cases, we maintain how much actual content is visible
     // within the screen width. Note that "actual content" may be different
     // with respect to CSS pixels because of the CSS viewport size changing.
     let zoomScale = (screenW * oldBrowserWidth) / (aOldScreenWidth * viewportW);
-    this.setResolution(this._zoom * zoomScale, false);
+    let zoom = this.clampZoom(this._zoom * zoomScale);
+    this.setResolution(zoom, false);
     this.sendViewportUpdate();
   },
 
   setBrowserSize: function(aWidth, aHeight) {
     this.browserWidth = aWidth;
 
     if (!this.browser.contentWindow)
       return;
     let cwu = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
     cwu.setCSSViewport(aWidth, aHeight);
   },
 
+  /** Takes a scale and restricts it based on this tab's zoom limits. */
+  clampZoom: function clampZoom(aZoom) {
+    let zoom = ViewportHandler.clamp(aZoom, kViewportMinScale, kViewportMaxScale);
+
+    let md = this.metadata;
+    if (!md.allowZoom)
+      return md.defaultZoom || zoom;
+
+    if (md && md.minZoom)
+      zoom = Math.max(zoom, md.minZoom);
+    if (md && md.maxZoom)
+      zoom = Math.min(zoom, md.maxZoom);
+    return zoom;
+  },
+
   getRequestLoadContext: function(aRequest) {
     if (aRequest && aRequest.notificationCallbacks) {
       try {
         return aRequest.notificationCallbacks.getInterface(Ci.nsILoadContext);
       } catch (ex) { }
     }
 
     if (aRequest && aRequest.loadGroup && aRequest.loadGroup.notificationCallbacks) {