Bug 599057 - Fix the center coordinates during pinch zoom [r=mfinkle,stechz]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 15 Oct 2010 08:35:34 -0700
changeset 66839 3284ba225f6a5865ca60db44dbafc7941a4deecb
parent 66838 62cd6c6c7e9e98f680e3e6c324ff63bbdc951a83
child 66840 cf9f3f04a46483b0339c74d86f13a2cb9e408da3
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)
reviewersmfinkle, stechz
bugs599057
Bug 599057 - Fix the center coordinates during pinch zoom [r=mfinkle,stechz]
mobile/chrome/content/input.js
--- a/mobile/chrome/content/input.js
+++ b/mobile/chrome/content/input.js
@@ -1051,64 +1051,60 @@ GestureModule.prototype = {
     let success = aEvent.target.dispatchEvent(event);
 
     if (!success || (aEvent.target instanceof XULElement) ||
         !Browser.selectedTab.allowZoom)
       return;
 
     // create the AnimatedZoom object for fast arbitrary zooming
     this._pinchZoom = AnimatedZoom;
-    this._pinchZoomRect = AnimatedZoom.getStartRect()
+    this._pinchStartRect = AnimatedZoom.getStartRect();
 
     // start from current zoom level
     this._pinchStartScale = this._pinchScale = getBrowser().scale;
     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._pinchClientX = aEvent.clientX;
-    this._pinchClientY = aEvent.clientY;
+    this._pinchStartX = aEvent.clientX;
+    this._pinchStartY = aEvent.clientY;
   },
 
   _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);
 
     let oldScale = this._pinchScale;
     let newScale = Browser.selectedTab.clampZoomLevel(oldScale * (1 + delta / this._scalingFactor));
 
-    let scaleRatio = oldScale / newScale;
+    let startScale = this._pinchStartScale;
+    let scaleRatio = startScale / newScale;
     let [cX, cY] = [aEvent.clientX, aEvent.clientY];
 
     // Calculate the new zoom rect.
-    let rect = this._pinchZoomRect.clone();
-    rect.translate(this._pinchClientX - cX + (1-scaleRatio) * cX * rect.width / window.innerWidth,
-                   this._pinchClientY - cY + (1-scaleRatio) * cY * rect.height / window.innerHeight);
+    let rect = this._pinchStartRect.clone();
+    rect.translate(this._pinchStartX - cX + (1-scaleRatio) * cX * rect.width / window.innerWidth,
+                   this._pinchStartY - cY + (1-scaleRatio) * cY * rect.height / window.innerHeight);
 
     rect.width *= scaleRatio;
     rect.height *= scaleRatio;
 
-    let startScale = this._pinchStartScale;
     rect.translateInside(new Rect(0, 0, getBrowser().contentDocumentWidth * startScale,
                                         getBrowser().contentDocumentHeight * startScale));
 
     // redraw zoom canvas according to new zoom rect
-    this._pinchZoomRect = rect;
-    this._pinchZoom.updateTo(this._pinchZoomRect);
-
+    this._pinchZoom.updateTo(rect);
     this._pinchScale = newScale;
-    this._pinchClientX = cX;
-    this._pinchClientY = cY;
   },
 
   _pinchEnd: function _pinchEnd(aEvent) {
     // stop ongoing animated zoom
     if (this._pinchZoom) {
       // zoom to current level for real
       this._pinchZoom.finish();
       this._pinchZoom = null;