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 66646 e4dc746c382b756a7a7f71b2c293a07a46b9d058
parent 66645 44c5a4d9c4c7aed13c144e6c6702e2fb5ffbf97f
child 66647 ecb37b7fc1826b8128b1b9fb5a9b6a0e46087f58
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)
reviewersstechz
bugs595052
Bug 595052 - [mobile2] Fix pinch zoom in tileless Fennec [r=stechz]
mobile/chrome/content/InputHandler.js
--- a/mobile/chrome/content/InputHandler.js
+++ b/mobile/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);
   },