Bug 605692 - Prevent jittering when fingers are not (really) moving [r=mbrubeck]
authorVivien Nicolas <21@vingtetun.org>
Wed, 20 Oct 2010 22:46:27 +0200
changeset 66883 ce008a40c5dee604656226b7438582a54352b19d
parent 66882 c02a3aa5132e95e7d6fc183ede37b2eb9085d50f
child 66884 2b2b0a35d4e387b8717842027492d69e4b51c9fd
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)
reviewersmbrubeck
bugs605692
Bug 605692 - Prevent jittering when fingers are not (really) moving [r=mbrubeck]
mobile/chrome/content/input.js
--- a/mobile/chrome/content/input.js
+++ b/mobile/chrome/content/input.js
@@ -1075,22 +1075,26 @@ GestureModule.prototype = {
     this._pinchStartX = aEvent.clientX - this._browserBCR.left;
     this._pinchStartY = aEvent.clientY - this._browserBCR.top;
   },
 
   _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);
+    // Accumulate pinch delta. Small changes are just jitter.
+    let oldScale = this._pinchScale;
+    this._pinchDelta += aEvent.delta;
+    if (this._pinchDelta > -oldScale && this._pinchDelta < this._oldScale)
+      return;
 
-    let oldScale = this._pinchScale;
+    // decrease the pinchDelta min/max values to limit zooming out/in speed
+    let delta = Util.clamp(this._pinchDelta, -this._maxShrink, this._maxGrowth);
+
     let newScale = Browser.selectedTab.clampZoomLevel(oldScale * (1 + delta / this._scalingFactor));
-
     let startScale = this._pinchStartScale;
     let scaleRatio = startScale / newScale;
     let cX = aEvent.clientX - this._browserBCR.left;
     let cY = aEvent.clientY - this._browserBCR.top;
 
     // Calculate the new zoom rect.
     let rect = this._pinchStartRect.clone();
     rect.translate(this._pinchStartX - cX + (1-scaleRatio) * cX * rect.width / window.innerWidth,
@@ -1100,16 +1104,18 @@ GestureModule.prototype = {
     rect.height *= scaleRatio;
 
     rect.translateInside(new Rect(0, 0, getBrowser().contentDocumentWidth * startScale,
                                         getBrowser().contentDocumentHeight * startScale));
 
     // redraw zoom canvas according to new zoom rect
     this._pinchZoom.updateTo(rect);
     this._pinchScale = newScale;
+
+    this._pinchDelta = 0;
   },
 
   _pinchEnd: function _pinchEnd(aEvent) {
     // stop ongoing animated zoom
     if (this._pinchZoom) {
       // zoom to current level for real
       this._pinchZoom.finish();
       this._pinchZoom = null;