Bug 495471: Easy to lose access to canvas from firstrun screen, r=mfinkle
authorStuart Parmenter <pavlov@pavlov.net>
Tue, 02 Jun 2009 22:05:39 -0400
changeset 65242 b7fa325f271e9b445c1e04ad9eab27e6df098cb6
parent 65241 3ceb6228fcd55a2a4fbe0039b528b816b80d6e8a
child 65243 dc2fe48863483f7bcb91a3c78038234f477809dc
push idunknown
push userunknown
push dateunknown
reviewersmfinkle
bugs495471
Bug 495471: Easy to lose access to canvas from firstrun screen, r=mfinkle
mobile/chrome/content/InputHandler.js
--- a/mobile/chrome/content/InputHandler.js
+++ b/mobile/chrome/content/InputHandler.js
@@ -476,17 +476,17 @@ KineticData.prototype = {
         // dump("             speeds: " + self._speedX + " " + self._speedY + "\n");
 
         if (self._speedX == 0 && self._speedY == 0) {
           self.endKinetic();
           return;
         } else {
           let dx = Math.round(self._speedX * self._updateInterval);
           let dy = Math.round(self._speedY * self._updateInterval);
-          //dump("dx, dy: " + dx + " " + dy + "\n");
+          // dump("dx, dy: " + dx + " " + dy + "\n");
 
           let panned = self._owner._dragBy(dx, dy);
           if (!panned) {
             self.endKinetic();
             return;
           }
         }
 
@@ -525,18 +525,19 @@ KineticData.prototype = {
     let tempX = 0;
     let tempY = 0;
 
     // build arrays of each movement's speed in pixels/ms
     let prev = mb[0];
     for (let i = 1; i < mblen; i++) {
       let me = mb[i];
 
-      tempX += (me.sx - prev.sx) / (me.t - prev.t);
-      tempY += (me.sy - prev.sy) / (me.t - prev.t);
+      let timeDiff = me.t - prev.t;
+      tempX += (me.sx - prev.sx) / timeDiff;
+      tempY += (me.sy - prev.sy) / timeDiff;
 
       prev = me;
     }
 
     // average the speeds out (this could probably be a bit smarter)
     this._speedX = tempX / mblen;
     this._speedY = tempY / mblen;
 
@@ -568,23 +569,26 @@ KineticData.prototype = {
       else
         ws.panBy(-rightVis * w, 0, true);
     }
   },
 
   addData: function addData(sx, sy) {
     let mbLength = this.momentumBuffer.length;
     // avoid adding duplicates which would otherwise slow down the speed
+    let now = Date.now();
+
     if (mbLength > 0) {
       let mbLast = this.momentumBuffer[mbLength - 1];
-      if (mbLast.sx == sx && mbLast.sy == sy)
+      if ((mbLast.sx == sx && mbLast.sy == sy) || mbLast.t == now) {
 	return;
+      }
     }
 
-    this.momentumBuffer.push({'t': Date.now(), 'sx' : sx, 'sy' : sy});
+    this.momentumBuffer.push({'t': now, 'sx' : sx, 'sy' : sy});
   }
 };
 
 function ContentPanningModule(owner, browserCanvas, useEarlyMouseMoves) {
   this._owner = owner;
   this._browserCanvas = browserCanvas;
   this._dragData = new DragData(this, 50, 200);
   this._kineticData = new KineticData(this);