Bug 595229 - Don't pan at start of multitouch zoom gesture [r=stechz]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 13 Sep 2010 10:13:17 -0700
changeset 2003 a9fb288e37cbbdf1708af47a9b4d58a4d2f3f6e8
parent 2002 c42cd3d22e0b764738213eb213096e9d7cf8f145
child 2004 512289018ae41c7350c425aaf7adb44a9bc75189
push id1714
push userdougt@mozilla.com
push dateThu, 16 Sep 2010 02:04:21 +0000
reviewersstechz
bugs595229
Bug 595229 - Don't pan at start of multitouch zoom gesture [r=stechz]
chrome/content/InputHandler.js
chrome/content/browser.js
--- a/chrome/content/InputHandler.js
+++ b/chrome/content/InputHandler.js
@@ -1319,16 +1319,21 @@ GestureModule.prototype = {
     // save the initial gesture start point as reference
     [this._pinchStartX, this._pinchStartY] =
         Browser.transformClientToBrowser(aEvent.clientX, aEvent.clientY);
 
     let scrollX = {}, scrollY = {};
     getBrowser().getPosition(scrollX, scrollY);
     this._pinchScrollX = scrollX.value;
     this._pinchScrollY = scrollY.value;
+
+    let [centerX, centerY] = Browser.transformClientToBrowser(window.innerWidth / 2,
+                                                              window.innerHeight / 2);
+    this._centerX = centerX;
+    this._centerY = centerY;
   },
 
   _pinchUpdate: function _pinchUpdate(aEvent) {
     if (!this._pinchZoom || !aEvent.delta)
       return;
 
     // decrease the pinchDelta min/max values to limit zooming out/in speed
     let delta = Util.clamp(aEvent.delta, -this._maxShrink, this._maxGrowth);
@@ -1341,18 +1346,18 @@ GestureModule.prototype = {
 
     let scale = getBrowser().scale;
     let scrollX = {}, scrollY = {};
     getBrowser().getPosition(scrollX, scrollY);
     pX += (this._pinchScrollX - scrollX.value) / scale;
     pY += (this._pinchScrollY - scrollY.value) / scale;
 
     // redraw zoom canvas according to new zoom rect
-    let rect = Browser._getZoomRectForPoint(2 * this._pinchStartX - pX,
-                                            2 * this._pinchStartY - pY,
+    let rect = Browser._getZoomRectForPoint(this._centerX + this._pinchStartX - pX,
+                                            this._centerY + this._pinchStartY - pY,
                                             this._pinchZoomLevel);
     this._pinchZoom.updateTo(rect);
   },
 
   _pinchEnd: function _pinchEnd(aEvent) {
     // release grab
     this._owner.ungrab(this);
 
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -839,18 +839,18 @@ var Browser = {
     if (i >= 0 && i < zoomValues.length)
       zoomLevel = zoomValues[i];
 
     zoomLevel = tab.clampZoomLevel(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 [centerX, centerY] = this.transformClientToBrowser(window.innerWidth / 2,
+                                                           window.innerHeight / 2);
 
     let rect = this._getZoomRectForPoint(centerX, centerY, zoomLevel);
     this.animatedZoomTo(rect);
   },
 
   /** Rect should be in browser coordinates. */
   _getZoomLevelForRect: function _getZoomLevelForRect(rect) {
     const margin = 15;