[mobile2] Update Browser.zoom to use getPosition
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 02 Sep 2010 16:01:46 -0700
changeset 66629 770b89ac56c6f6265d69ca34e88d3cabac67d2fe
parent 66628 8f15f79f173053e2ffa6027e96df5d1114961ad7
child 66630 2ec5396338c04603f72bab7a9088b5b69e2ac078
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)
[mobile2] Update Browser.zoom to use getPosition
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -843,27 +843,34 @@ var Browser = {
   },
 
   /** Zoom one step in (negative) or out (positive). */
   zoom: function zoom(aDirection) {
     let tab = this.selectedTab;
     if (!tab.allowZoom)
       return;
 
-    let zoomLevel = getBrowser().scale;
+    let oldZoomLevel = tab.browser.scale;
+    let zoomLevel = oldZoomLevel;
+
     let zoomValues = ZoomManager.zoomValues;
     let i = zoomValues.indexOf(ZoomManager.snap(zoomLevel)) + (aDirection < 0 ? 1 : -1);
     if (i >= 0 && i < zoomValues.length)
       zoomLevel = zoomValues[i];
 
     zoomLevel = tab.clampZoomLevel(zoomLevel);
 
-    let centerX = getBrowser().viewportScrollX + window.innerWidth / 2;
-    let centerY = getBrowser().viewportScrollY + window.innerHeight / 2;
-    this.animatedZoomTo(this._getZoomRectForPoint(centerX, centerY, zoomLevel));
+    let scrollX = {}, scrollY = {};
+    tab.browser.getPosition(scrollX, scrollY);
+
+    let centerX = (scrollX.value + window.innerWidth / 2) / oldZoomLevel;
+    let centerY = (scrollY.value + window.innerHeight / 2) / oldZoomLevel;
+
+    let rect = this._getZoomRectForPoint(centerX, centerY, zoomLevel);
+    this.animatedZoomTo(rect);
   },
 
   /** Rect should be in browser coordinates. */
   _getZoomLevelForRect: function _getZoomLevelForRect(rect) {
     const margin = 15;
     return this.selectedTab.clampZoomLevel(window.innerWidth / (rect.width + margin * 2));
   },