Bug 602707 - Fixes for FormHelper zoom [r=mfinkle,vingtetun]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 18 Oct 2010 06:31:44 -0700
changeset 66846 e145fa68558eed26e759f2ca6f7fc1add06099ef
parent 66845 2e1cebf652f1e492313e2ff0c2126f6c285dce07
child 66847 cf63c8389d05490355c930d7b2028a9afd7fd8a1
push idunknown
push userunknown
push dateunknown
reviewersmfinkle, vingtetun
bugs602707
Bug 602707 - Fixes for FormHelper zoom [r=mfinkle,vingtetun]
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -2040,17 +2040,17 @@ var FormHelperUI = {
       } else {
         harmonizedCaretHeight = 30; // fallback height
 
         // use the element as position
         harmonizedCaretY = aElementRect.y;
         aCaretRect.x = aElementRect.x;
       }
 
-      let zoomLevel = browser.scale;
+      let oldZoomLevel = zoomLevel = browser.scale;
       let enableZoom = Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("formhelper.autozoom");
       if (enableZoom) {
         zoomLevel = (viewAreaHeight / caretLines) / harmonizedCaretHeight;
         zoomLevel = Util.clamp(zoomLevel, kBrowserFormZoomLevelMin, kBrowserFormZoomLevelMax);
         zoomLevel = Browser.selectedTab.clampZoomLevel(zoomLevel);
       }
       viewAreaWidth /= zoomLevel;
 
@@ -2059,31 +2059,32 @@ var FormHelperUI = {
       // if the viewAreaWidth is smaller than the neutralized position + margins.
       // [YES] use the x position of the element minus margins as x position for our visible rect.
       // [NO] use the x position of the caret minus margins as the x position for our visible rect.
       let x = (marginLeft + marginRight + margin + aCaretRect.x - aElementRect.x) < viewAreaWidth
                ? aElementRect.x - margin - marginLeft
                : aCaretRect.x - viewAreaWidth + margin + marginRight;
       // Use the adjusted Caret Y minus a margin for our visible rect
       let y = harmonizedCaretY - margin;
-      x *= browser.scale;
-      y *= browser.scale;
+      x *= oldZoomLevel;
+      y *= oldZoomLevel;
 
       let scroll = browser.getPosition();
 
       // from here on play with zoomed values
       // if we want to have it animated, build up zoom rect and animate.
-      if (enableZoom && browser.scale != zoomLevel) {
+      if (enableZoom) {
         // don't use browser functions they are bogus for this case
-        let zoomRatio = zoomLevel / browser.scale;
+        let zoomRatio = zoomLevel / oldZoomLevel;
 
         let visW = window.innerWidth, visH = window.innerHeight;
         let newVisW = visW / zoomRatio, newVisH = visH / zoomRatio;
         let zoomRect = new Rect(x, y, newVisW, newVisH);
-
+        zoomRect.translateInside(new Rect(0, 0, browser.contentDocumentWidth * oldZoomLevel,
+                                                browser.contentDocumentHeight * oldZoomLevel));
         Browser.animatedZoomTo(zoomRect);
       }
       else { // no zooming at all
         browser.scrollTo(x, y);
       }
     }
   },