Bug 639179 Part 2: Carefully track values sent to dragger r=mbrubeck
authorBenjamin Stover <bstover@mozilla.com>
Mon, 11 Apr 2011 13:52:42 -0700
changeset 67856 d42f0af7b2f76017a6dbb7590dcbdf097fd7c787
parent 67855 3d16959fd802dad8b33ebaae3d8856363357eb0a
child 67857 ba45ce3791cc8b4d664b50208f2befc7e50cdcf4
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
bugs639179
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 639179 Part 2: Carefully track values sent to dragger r=mbrubeck
mobile/chrome/content/input.js
--- a/mobile/chrome/content/input.js
+++ b/mobile/chrome/content/input.js
@@ -879,44 +879,51 @@ KineticController.prototype = {
         // time frame (smooth animation) with the actual time lapse (end fast enough).
         // Animation will never take longer than 2 times the ideal length of time.
         let realt = timeStamp - self._initialTime;
         self._time += self._updateInterval;
         let t = (self._time + realt) / 2;
 
         // Calculate new position using x(t) formula.
         let x = v0Bin.set(v0).scale(t).add(aBin.set(a).scale(0.5 * t * t));
-        let dx = x.x - lastx.x;
-        let dy = x.y - lastx.y;
-        lastx.set(x);
+        let dx = Math.round(x.x - lastx.x);
+        let dy = Math.round(x.y - lastx.y);
 
         // Test to see if movement is finished for each component. As seen in graph, we want the
         // final position to be at tf.
         if (t >= -v0.x / a.x) {
           // Plug in t=-v0/a into x(t) to get final position.
-          dx = -v0.x * v0.x / 2 / a.x - lastx.x;
+          dx = Math.round(-v0.x * v0.x / 2 / a.x - lastx.x);
           // Reset components. Next frame: a's component will be 0 and t >= NaN will be false.
           lastx.x = 0;
           v0.x = 0;
           a.x = 0;
         }
         // Symmetric to above case.
         if (t >= -v0.y / a.y) {
-          dy = -v0.y * v0.y / 2 / a.y - lastx.y;
+          dy = Math.round(-v0.y * v0.y / 2 / a.y - lastx.y);
           lastx.y = 0;
           v0.y = 0;
           a.y = 0;
         }
 
-        let panned = false;
-        try { panned = self._panBy(Math.round(-dx), Math.round(-dy), true); } catch (e) {}
-        if (!panned)
+        if (v0.x == 0 && v0.y == 0) {
           self.end();
-        else
-          mozRequestAnimationFrame(this);
+        } else {
+          let panStop = false;
+          if (dx != 0 || dy != 0) {
+            try { panStop = !self._panBy(-dx, -dy, true); } catch (e) {}
+            lastx.add(dx, dy);
+          }
+
+          if (panStop)
+            self.end();
+          else
+            mozRequestAnimationFrame(this);
+        }
       }
     };
 
     this._active = true;
     mozRequestAnimationFrame(callback);
   },
 
   start: function start() {