Bug 555196 - Regression: Zoom in/out commands break when zoom level is 1.0 [r=mark.finkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 26 Mar 2010 11:32:43 -0400
changeset 66069 7fe22b827fad6309f8dac0f35a005cbc4a5c956b
parent 66068 bcd91b0b3f9292a0ea0e44ffb17b41739a3e14cc
child 66070 f34d064c7c8a2333a4131d728a1fa1b210f99c81
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmark
bugs555196
Bug 555196 - Regression: Zoom in/out commands break when zoom level is 1.0 [r=mark.finkle]
mobile/chrome/content/BrowserView.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/BrowserView.js
+++ b/mobile/chrome/content/BrowserView.js
@@ -40,17 +40,18 @@
 
 let Ci = Components.interfaces;
 
 const kBrowserViewZoomLevelMin = 0.2;
 const kBrowserViewZoomLevelMax = 4.0;
 const kBrowserFormZoomLevelMin = 1.0;
 const kBrowserFormZoomLevelMax = 2.0;
 const kBrowserViewZoomLevelPrecision = 10000;
-const kBrowserViewZoomLevelMaxAdjust = 0.2;
+const kBrowserViewZoomLevelIncrement = 0.1;
+const kBrowserViewZoomLevelPageFitAdjust = 0.2;
 const kBrowserViewPrefetchBeginIdleWait = 1;    // seconds
 const kBrowserViewPrefetchBeginIdleWaitLoading = 10;    // seconds
 const kBrowserViewCacheSize = 6;
 
 /**
  * A BrowserView maintains state of the viewport (browser, zoom level,
  * dimensions) and the visible rectangle into the viewport, for every
  * browser it is given (cf setBrowser()).  In updates to the viewport state,
@@ -157,23 +158,23 @@ BrowserView.Util = {
 
   clampZoomLevel: function clampZoomLevel(zl) {
     let bounded = Math.min(Math.max(kBrowserViewZoomLevelMin, zl), kBrowserViewZoomLevelMax);
     let rounded = Math.round(bounded * kBrowserViewZoomLevelPrecision) / kBrowserViewZoomLevelPrecision;
     return (rounded) ? rounded : 1.0;
   },
 
   /** Force zoom levels "near" 1 to exactly 1.  */
-  adjustZoomLevel: function adjustZoomLevel(zl) {
-    return (Math.abs(1.0 - zl) <= kBrowserViewZoomLevelMaxAdjust) ? 1.0 : zl;
+  adjustZoomLevel: function adjustZoomLevel(zl, threshold) {
+    return (Math.abs(1.0 - zl) < threshold) ? 1.0 : zl;
   },
 
   pageZoomLevel: function pageZoomLevel(visibleRect, browserW, browserH) {
     let zl = BrowserView.Util.clampZoomLevel(visibleRect.width / browserW);
-    return BrowserView.Util.adjustZoomLevel(zl);
+    return BrowserView.Util.adjustZoomLevel(zl, kBrowserViewZoomLevelPageFitAdjust);
   },
 
   createBrowserViewportState: function createBrowserViewportState() {
     return new BrowserView.BrowserViewportState(new Rect(0, 0, 1, 1), 0, 0, 1);
   },
 
   getViewportStateFromBrowser: function getViewportStateFromBrowser(browser) {
     return browser.__BrowserView__vps;
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1042,18 +1042,18 @@ var Browser = {
       return true;
     }
     return false;
   },
 
   /** Zoom one step in (negative) or out (positive). */
   zoom: function zoom(aDirection) {
     let bv = this._browserView;
-    let zoomLevel = bv.getZoomLevel() + (aDirection > 0 ? -0.1 : 0.1);
-    let adjusted = BrowserView.Util.adjustZoomLevel(zoomLevel);
+    let zoomLevel = bv.getZoomLevel() + (aDirection > 0 ? -1 : 1) * kBrowserViewZoomLevelIncrement;
+    let adjusted = BrowserView.Util.adjustZoomLevel(zoomLevel, kBrowserViewZoomLevelIncrement / 2);
     let center = this.getVisibleRect().center().map(bv.viewportToBrowser);
     this.setVisibleRect(this._getZoomRectForPoint(center.x, center.y, adjusted));
   },
 
   /**
    * Find the needed zoom level for zooming on an element
    */
   _getZoomLevelForElement: function _getZoomLevelForElement(element) {