Bug 599419 - FormHelper should clamp zoom values [r=wesj,vingtetun]
authorMatt Brubeck <mbrubeck@mozilla.com>
Wed, 27 Oct 2010 16:54:44 -0700
changeset 66921 4cbe38cf142e33b168e1ec0662b8d84b2c0eb2e5
parent 66920 47973af62b0dbba3de58a2ef6682ec90c8d9f39d
child 66922 ea9e51b17b9a5fb74e70cf0f274bee8e3affe449
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)
reviewerswesj, vingtetun
bugs599419
Bug 599419 - FormHelper should clamp zoom values [r=wesj,vingtetun]
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1713,16 +1713,17 @@ var FindHelperUI = {
     this._cmdNext.setAttribute("disabled", disabled);
   },
 
   _zoom: function _findHelperZoom(aElementRect) {
     // Zoom to a specified Rect
     if (aElementRect && Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("findhelper.autozoom")) {
       let zoomLevel = Browser._getZoomLevelForRect(aElementRect);
       zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
+      zoomLevel = Browser.selectedTab.clampZoomLevel(zoomLevel);
 
       let zoomRect = Browser._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
       Browser.animatedZoomTo(zoomRect);
     }
   }
 };
 
 /**
@@ -1998,16 +1999,17 @@ var FormHelperUI = {
     let browser = getBrowser();
 
     // Zoom to a specified Rect
     if (aElementRect && Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("formhelper.autozoom")) {
       this._currentElementRect = aElementRect;
       // Zoom to an element by keeping the caret into view
       let zoomLevel = this._getZoomLevelForRect(aElementRect);
       zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
+      zoomLevel = Browser.selectedTab.clampZoomLevel(zoomLevel);
 
       zoomRect = this._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
       Browser.animatedZoomTo(zoomRect);
     }
 
     // Move the view to show the caret if needed
     if (aCaretRect) {
       this._currentCaretRect = aCaretRect;
@@ -2044,36 +2046,35 @@ var FormHelperUI = {
 
     let restore = this._restore;
     getBrowser().scale = restore.scale;
     Browser.contentScrollboxScroller.scrollTo(restore.contentScrollOffset.x, restore.contentScrollOffset.y);
     Browser.pageScrollboxScroller.scrollTo(restore.pageScrollOffset.x, restore.pageScrollOffset.y);
   },
 
   _getZoomRectForPoint: function _getZoomRectForPoint(x, y, zoomLevel) {
-    const margin = 30;
-
     let browser = getBrowser();
     x = x * browser.scale;
     y = y * browser.scale;
 
     let vis = this.visibleScreenArea
     zoomLevel = Math.min(ZoomManager.MAX, zoomLevel);
     let oldScale = browser.scale;
     let zoomRatio = zoomLevel / oldScale;
     let newVisW = vis.width / zoomRatio, newVisH = vis.height / zoomRatio;
-    let result = new Rect((x - newVisW / 2) - margin / 2, y - newVisH / 2, newVisW + margin, newVisH);
+    let result = new Rect(x - newVisW / 2, y - newVisH / 2, newVisW, newVisH);
 
     // Make sure rectangle doesn't poke out of viewport
     return result.translateInside(new Rect(0, 0, browser.contentDocumentWidth * oldScale,
                                                  browser.contentDocumentHeight * oldScale));
   },
 
   _getZoomLevelForRect: function _getZoomLevelForRect(aRect) {
-    let zoomLevel = this.visibleScreenArea.width / aRect.width;
+    const margin = 30;
+    let zoomLevel = this.visibleScreenArea.width / (aRect.width + margin);
     return Util.clamp(zoomLevel, kBrowserFormZoomLevelMin, kBrowserFormZoomLevelMax);
   },
 
   _getOffsetForCaret: function _formHelperGetOffsetForCaret(aCaretRect, aRect) {
     // Determine if we need to move left or right to bring the caret into view
     let deltaX = 0;
     if (aCaretRect.right > aRect.right)
       deltaX = aCaretRect.right - aRect.right;