Bug 595052 - [mobile2] Fix pinch zoom in tileless Fennec [r=stechz]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 13 Sep 2010 10:11:54 -0700
changeset 2002 c42cd3d22e0b764738213eb213096e9d7cf8f145
parent 2001 5012211c43775f03976ebdef0077343975189ccb
child 2003 a9fb288e37cbbdf1708af47a9b4d58a4d2f3f6e8
push id1714
push userdougt@mozilla.com
push dateThu, 16 Sep 2010 02:04:21 +0000
reviewersstechz
bugs595052
Bug 595052 - [mobile2] Fix pinch zoom in tileless Fennec [r=stechz]
chrome/content/InputHandler.js
--- a/chrome/content/InputHandler.js
+++ b/chrome/content/InputHandler.js
@@ -1304,55 +1304,51 @@ GestureModule.prototype = {
     // XXX ugh, this is awful. None of this code should be in InputHandler.
     document.getElementById("inputhandler-overlay").customClicker.panBegin();
 
     // create the AnimatedZoom object for fast arbitrary zooming
     this._pinchZoom = animatedZoom;
 
     // start from current zoom level
     this._pinchZoomLevel = getBrowser().scale;
-    this._pinchDelta = 0;
     this._ignoreNextUpdate = true; // first update gives useless, huge delta
 
     // cache gesture limit values
     this._maxGrowth = Services.prefs.getIntPref("browser.ui.pinch.maxGrowth");
     this._maxShrink = Services.prefs.getIntPref("browser.ui.pinch.maxShrink");
     this._scalingFactor = Services.prefs.getIntPref("browser.ui.pinch.scalingFactor");
 
     // 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._pinchStartX += scrollX.value;
-    this._pinchStartY += scrollY.value;
+    this._pinchScrollX = scrollX.value;
+    this._pinchScrollY = scrollY.value;
   },
 
   _pinchUpdate: function _pinchUpdate(aEvent) {
     if (!this._pinchZoom || !aEvent.delta)
       return;
 
-    // Accumulate pinch delta. Changes smaller than 1 are just jitter.
-    this._pinchDelta += aEvent.delta;
-
     // decrease the pinchDelta min/max values to limit zooming out/in speed
-    let delta = Math.max(-this._maxShrink, Math.min(this._maxGrowth, this._pinchDelta));
+    let delta = Util.clamp(aEvent.delta, -this._maxShrink, this._maxGrowth);
     this._pinchZoomLevel *= (1 + delta / this._scalingFactor);
     this._pinchZoomLevel = Browser.selectedTab.clampZoomLevel(this._pinchZoomLevel);
-    this._pinchDelta = 0;
 
     // get current pinch position to calculate opposite vector for zoom point
     let [pX, pY] =
         Browser.transformClientToBrowser(aEvent.clientX, aEvent.clientY);
 
+    let scale = getBrowser().scale;
     let scrollX = {}, scrollY = {};
     getBrowser().getPosition(scrollX, scrollY);
-    pX += scrollX.value;
-    pY += scrollY.value;
+    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,
                                             this._pinchZoomLevel);
     this._pinchZoom.updateTo(rect);
   },