make formhelper work like it does in m-b trunk
authorBenjamin Stover <bstover@mozilla.com>
Thu, 02 Sep 2010 14:42:44 -0700
changeset 66627 91874b795d6e89a4fc96856c64b2547d1726e9e4
parent 66626 170b86ea6a36eaed1d7f1f0ba850ec3f2231fbcf
child 66628 8f15f79f173053e2ffa6027e96df5d1114961ad7
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)
make formhelper work like it does in m-b trunk
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1557,26 +1557,22 @@ var FindHelperUI = {
   },
 
   updateCommands: function findHelperUpdateCommands(aValue) {
     this._cmdPrevious.setAttribute("disabled", aValue == "");
     this._cmdNext.setAttribute("disabled", aValue == "");
   },
 
   _zoom: function _findHelperZoom(aElementRect) {
-    return;
-
-    let zoomRect = bv.getVisibleRect();
-
     // Zoom to a specified Rect
-    if (aElementRect && bv.allowZoom && Services.prefs.getBoolPref("findhelper.autozoom")) {
+    if (aElementRect && Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("findhelper.autozoom")) {
       let zoomLevel = Browser._getZoomLevelForRect(aElementRect);
       zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
 
-      zoomRect = Browser._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
+      let zoomRect = Browser._getZoomRectForPoint(aElementRect.center().x, aElementRect.y, zoomLevel);
       Browser.animatedZoomTo(zoomRect);
     }
   }
 };
 
 /**
  * Responsible for navigating forms and filling in information.
  *  - Navigating forms is handled by next and previous commands.
@@ -1833,25 +1829,20 @@ var FormHelperUI = {
       SelectHelperUI.show(aCurrentElement.list);
     } else if (lastHasChoices && !currentHasChoices) {
       SelectHelperUI.hide();
     }
   },
 
   /** Zoom and move viewport so that element is legible and touchable. */
   _zoom: function _formHelperZoom(aElementRect, aCaretRect) {
-    return;
-
-    let bv = Browser._browserView;
-
     if (aElementRect && aCaretRect && this._open) {
       this._currentCaretRect = aCaretRect;
 
-      // might not always be set, if not - use the windowsize
-      let visibleScreenArea = !bv._visibleScreenArea.isEmpty() ? bv._visibleScreenArea : new Rect(0, 0, window.innerWidth, window.innerHeight);
+      let visibleScreenArea = new Rect(0, 0, window.innerWidth, window.innerHeight);
 
       // respect the helper container in setting the correct viewAreaHeight
       let viewAreaHeight = visibleScreenArea.height - this._container.getBoundingClientRect().height;
       let viewAreaWidth = visibleScreenArea.width;
       let caretLines = Services.prefs.getIntPref("formhelper.caretLines.portrait");
       let harmonizeValue = Services.prefs.getIntPref("formhelper.harmonizeValue");
 
       if (!Util.isPortrait())
@@ -1890,18 +1881,18 @@ var FormHelperUI = {
       } else {
         harmonizedCaretHeight = 30; // fallback height
 
         // use the element as position
         harmonizedCaretY = aElementRect.y;
         aCaretRect.x = aElementRect.x;
       }
 
-      let zoomLevel = bv.getZoomLevel();
-      let enableZoom = bv.allowZoom && Services.prefs.getBoolPref("formhelper.autozoom");
+      let zoomLevel = getBrowser().scale;
+      let enableZoom = Browser.selectedTab.allowZoom && Services.prefs.getBoolPref("formhelper.autozoom");
       if (enableZoom) {
         zoomLevel = (viewAreaHeight / caretLines) / harmonizedCaretHeight;
         zoomLevel = Math.min(Math.max(kBrowserFormZoomLevelMin, zoomLevel), kBrowserFormZoomLevelMax);
       }
       viewAreaWidth /= zoomLevel;
 
       const margin = Services.prefs.getIntPref("formhelper.margin");
 
@@ -1909,42 +1900,34 @@ var FormHelperUI = {
       // [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 adjustet Caret Y minus a margin four our visible rect
       let y = harmonizedCaretY - margin;
 
+      let scrollX = {}, scrollY = {};
+      getBrowser().getPosition(scrollX, scrollY);
+      let vis = new Rect(scrollX.value, scrollY.value, window.innerWidth, window.innerHeight);
+      x *= getBrowser().scale;
+      y *= getBrowser().scale;
+
       // from here on play with zoomed values
       // if we want to have it animated, build up zoom rect and animate.
-      if (enableZoom && bv.getZoomLevel() != zoomLevel) {
-        let vis = bv.getVisibleRect();
-        x = bv.browserToViewport(x);
-        y = bv.browserToViewport(y);
-
-        //dont use browser functions they are bogus for this case
-        let zoomRatio = zoomLevel / bv.getZoomLevel();
+      if (enableZoom && getBrowser().scale != zoomLevel) {
+        // don't use browser functions they are bogus for this case
+        let zoomRatio = zoomLevel / getBrowser().scale;
         let newVisW = vis.width / zoomRatio, newVisH = vis.height / zoomRatio;
         let zoomRect = new Rect(x, y, newVisW, newVisH);
 
         Browser.animatedZoomTo(zoomRect);
       }
       else { // no zooming at all
-        let vis = bv.getVisibleRect();
-        // get our x and y in viewport "zoomed" coordinates
-        x = bv.browserToViewport(x);
-        y = bv.browserToViewport(y);
-
-        Browser.contentScrollboxScroller.scrollBy(x-vis.x, y-vis.y);
-
-        // workaround for tilemanager bug, after scrolling one screen height, text gets not painted on typing
-        bv.invalidateEntireView();
-
-        bv.onAfterVisibleMove();
+        getBrowser().scrollBy(x - vis.x, y - vis.y);
       }
     }
   },
 
   /* Store the current zoom level, and scroll positions to restore them if needed */
   _zoomStart: function _formHelperZoomStart() {
     if (!Services.prefs.getBoolPref("formhelper.restore"))
       return;