Bug 556617 - volume rocker zooming allows zooming out past page-width [r=mark.finkle]
authorMatt Brubeck <mbrubeck@mozilla.org>
Thu, 08 Apr 2010 10:43:04 -0400
changeset 66115 dc17a7c0e3d31bfd1b9eca72111a5bff66c07200
parent 66114 67c9eadfce0084ca11d768a15459e582a06fdfa1
child 66116 445d79e4ff7a97d2dd7fb14e96abcc3e36fb0654
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
bugs556617
Bug 556617 - volume rocker zooming allows zooming out past page-width [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
@@ -163,18 +163,17 @@ BrowserView.Util = {
   },
 
   /** Force zoom levels "near" 1 to exactly 1.  */
   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, kBrowserViewZoomLevelPageFitAdjust);
+    return BrowserView.Util.clampZoomLevel(visibleRect.width / browserW);
   },
 
   createBrowserViewportState: function createBrowserViewportState() {
     return new BrowserView.BrowserViewportState(new Rect(0, 0, 1, 1), 0, 0, 1);
   },
 
   getViewportStateFromBrowser: function getViewportStateFromBrowser(browser) {
     return browser.__BrowserView__vps;
@@ -577,55 +576,52 @@ BrowserView.prototype = {
         // Content has shrunk outside of the visible rectangle.
         // XXX for some reason scroller doesn't know it is outside its bounds
         Browser.contentScrollboxScroller.scrollBy(0, 0);
         this.onAfterVisibleMove();
       }
     }
   },
 
-  /** Call when default zoomToPage value may change. */
+  /** Call when default zoom level may change. */
   updateDefaultZoom: function updateDefaultZoom() {
     let bvs = this._browserViewportState;
     if (!bvs)
       return false;
 
     let isDefault = (bvs.zoomLevel == bvs.defaultZoomLevel);
-    bvs.defaultZoomLevel = this.getZoomForPage();
+    bvs.defaultZoomLevel = this.getDefaultZoomLevel();
     if (isDefault)
       this.setZoomLevel(bvs.defaultZoomLevel);
     return isDefault;
   },
 
   isDefaultZoom: function isDefaultZoom() {
     let bvs = this._browserViewportState;
     if (!bvs)
       return true;
     return bvs.zoomLevel == bvs.defaultZoomLevel;
   },
 
-  zoomToPage: function zoomToPage() {
-    let bvs = this._browserViewportState;
-    if (bvs) {
-      this.setZoomLevel(this.getZoomForPage());
-      bvs.defaultZoomLevel = bvs.zoomLevel;  // make sure default zl is up to date
-    }
-  },
-
-  getZoomForPage: function getZoomForPage() {
+  getDefaultZoomLevel: function getDefaultZoomLevel() {
     let browser = this._browser;
     if (!browser)
       return 0;
 
     let metaData = Util.contentIsHandheld(browser);
     if (metaData.reason == "handheld" || metaData.reason == "doctype")
       return 1;
     else if (metaData.reason == "viewport" && metaData.scale > 0)
       return metaData.scale;
 
+    let zl = this.getPageZoomLevel();
+    return BrowserView.Util.adjustZoomLevel(zl, kBrowserViewZoomLevelPageFitAdjust);
+  },
+
+  getPageZoomLevel: function getPageZoomLevel() {
     let bvs = this._browserViewportState;  // browser exists, so bvs must as well
     let w = this.viewportToBrowser(bvs.viewportRect.right);
     let h = this.viewportToBrowser(bvs.viewportRect.bottom);
     return BrowserView.Util.pageZoomLevel(this.getVisibleRect(), w, h);
   },
 
   zoom: function zoom(aDirection) {
     let bvs = this._browserViewportState;
@@ -644,37 +640,37 @@ BrowserView.prototype = {
 
   //
   // MozAfterPaint events do not guarantee to inform us of all
   // invalidated paints (See
   // https://developer.mozilla.org/en/Gecko-Specific_DOM_Events#Important_notes
   // for details on what the event *does* guarantee).  This is only an
   // issue when the same current <browser> is used to navigate to a
   // new page.  Unless a zoom was issued during the page transition
-  // (e.g. a call to zoomToPage() or something of that nature), we
+  // (e.g. a call to setZoomLevel() or something of that nature), we
   // aren't guaranteed that we've actually invalidated the entire
   // page.  We don't want to leave bits of the previous page in the
   // view of the new one, so this method exists as a way for Browser
   // to inform us that the page is changing, and that we really ought
   // to invalidate everything.  Ideally, we wouldn't have to rely on
   // this being called, and we would get proper invalidates for the
   // whole page no matter what is or is not visible.
   //
   // Note that calling this function isn't necessary in almost all
   // cases, but should be done for correctness.  Most of the time, one
   // of the following two conditions is satisfied.  Either
   //
   //   (1) Pages have different widths so the Browser calls a
-  //       zoomToPage() which forces a dirtyAll, or
+  //       updateDefaultZoom() which forces a dirtyAll, or
   //   (2) MozAfterPaint does indeed inform us of dirtyRects covering
   //       the entire page (everything that could possibly become
   //       visible).
   /**
    * Invalidates the entire page by throwing away any cached graphical
-   * portions of the view and refusing to allow a zoomToPage() until
+   * portions of the view and refusing to allow a updateDefaultZoom() until
    * the next explicit update of the viewport dimensions.
    *
    * This method should be called when the <browser> last set by
    * setBrowser() is about to navigate to a new page.
    */
   invalidateEntireView: function invalidateEntireView() {
     if (this._browserViewportState) {
       this._viewportChanged(false, true);
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1017,19 +1017,22 @@ var Browser = {
     }
     return false;
   },
 
   /** Zoom one step in (negative) or out (positive). */
   zoom: function zoom(aDirection) {
     let bv = this._browserView;
     let zoomLevel = bv.getZoomLevel() + (aDirection > 0 ? -1 : 1) * kBrowserViewZoomLevelIncrement;
-    let adjusted = BrowserView.Util.adjustZoomLevel(zoomLevel, kBrowserViewZoomLevelIncrement / 2);
+
+    zoomLevel = BrowserView.Util.adjustZoomLevel(zoomLevel, kBrowserViewZoomLevelIncrement / 2);
+    zoomLevel = Math.max(zoomLevel, bv.getPageZoomLevel());
+
     let center = this.getVisibleRect().center().map(bv.viewportToBrowser);
-    this.setVisibleRect(this._getZoomRectForPoint(center.x, center.y, adjusted));
+    this.setVisibleRect(this._getZoomRectForPoint(center.x, center.y, zoomLevel));
   },
 
   /**
    * Find the needed zoom level for zooming on an element
    */
   _getZoomLevelForElement: function _getZoomLevelForElement(element) {
     const margin = 15;
 
@@ -1134,19 +1137,18 @@ var Browser = {
       return true;
     } else {
       return false;
     }
   },
 
   zoomFromPoint: function zoomFromPoint(cX, cY) {
     let bv = this._browserView;
-
-    let zoomLevel = bv.getZoomForPage();
     if (!bv.isDefaultZoom()) {
+      let zoomLevel = bv.getDefaultZoomLevel();
       let [elementX, elementY] = this.transformClientToBrowser(cX, cY);
       let zoomRect = this._getZoomRectForPoint(elementX, elementY, zoomLevel);
       this.setVisibleRect(zoomRect);
     }
   },
 
   getContentClientRects: function getContentClientRects(contentElem) {
     // XXX don't copy getBoundingContentRect