From f1ebde00f5c490a3abcc83cae64e73aeb32c1922 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 23 Sep 2008 14:06:28 -0400 Subject: [PATCH] Bug 455453 - Panning goes in the wrong direction r=gavin --- mobile/chrome/content/deckbrowser.xml | 82 ++++++++++++++++++++------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/mobile/chrome/content/deckbrowser.xml b/mobile/chrome/content/deckbrowser.xml index 67192e01101a..32401a50087f 100644 --- a/mobile/chrome/content/deckbrowser.xml +++ b/mobile/chrome/content/deckbrowser.xml @@ -847,35 +847,51 @@ 0) { - this.dragData.velocityX = -dx / dt; - this.dragData.velocityY = -dy / dt; + if (dt > 0) { // dt should never be less than 0 + this.dragData.velocityX = dx / dt; + this.dragData.velocityY = dy / dt; + // Save the original x.y we're starting from to make sure + // we don't go backwards this.dragData.originalX = this.dragData.dragX; this.dragData.originalY = this.dragData.dragY; - let [destPageX, destPageY] = this._constrainPanCoords(this._screenToPage(this.dragData.dragX - + this.dragData.velocityX * 800), - this._screenToPage(this.dragData.dragY - + this.dragData.velocityY * 800)); + // s = S0 + 0.5 * v0^2 * 1/CoK); s = position, s0 = initial pos + // v0 = initial velocity, CoK = Coefficient of Kinetic friction + // All in page coords + let idealDestScreenX = this.dragData.dragX + Math.abs(this.dragData.velocityX) + * this.dragData.velocityX * 100; + let idealDestScreenY = this.dragData.dragY + Math.abs(this.dragData.velocityY) + * this.dragData.velocityY * 100 + + let [destPageX, destPageY] = this._constrainPanCoords(-this._screenToPage(idealDestScreenX), + -this._screenToPage(idealDestScreenY)); + + + // Convert to screen coords this.dragData.destinationX = -this._pageToScreen(destPageX); this.dragData.destinationY = -this._pageToScreen(destPageY); + // If we have a kinetic timer, kill it. This shouldn't happen if (this.dragData.kineticId) window.clearInterval(this.dragData.kineticId); - this.dragData.kineticId = window.setInterval(this._doKinetic, dt / (this.PAN_EVENTS_TO_TRACK - 1), - this, dt / (this.PAN_EVENTS_TO_TRACK - 1)); + // Start timer for kinetic movements + let interval = dt / (this.PAN_EVENTS_TO_TRACK - 1); + this.dragData.kineticId = window.setInterval(this._doKinetic, interval, this, interval); } else { + // dt <= 0, this is bad this._endPan(); } } else { + // p1 or p2 is null, either we didn't pan enough, or something went wrong this._endPan() } @@ -890,24 +906,45 @@ nextX && nextX > self.dragData.destinationX) || (self.dragData.originalX < nextX && @@ -925,9 +962,12 @@ self._updateCanvasPosition(); + // calculate how much we've actually moved and end if less than 4px let actualDx = startX - self.dragData.dragX; - let actualDy = startY - self.dragData.dragY - if ((actualDx / (self.dragData.destinationX - self.dragData.originalX) < 0 && actualDy / (self.dragData.destinationY - self.dragData.originalY) < 0) || ( Math.abs(actualDx) < 4 && Math.abs(actualDy) < 4)) { + let actualDy = startY - self.dragData.dragY; + if ((actualDx / (self.dragData.destinationX - self.dragData.originalX) < 0 && + actualDy / (self.dragData.destinationY - self.dragData.originalY) < 0) || + (Math.abs(actualDx) < 4 && Math.abs(actualDy) < 4)) { self._endKinetic(); } ]]>