From 73ef98dfae2cd0fb09cf9fdad4ce48bf0cb320a5 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Wed, 17 Sep 2008 14:53:58 -0400 Subject: [PATCH] Bug 455361: don't redispatch clicks if we're in kinetic, refactor some event handling code, r=stuart --- mobile/chrome/content/deckbrowser.xml | 132 ++++++++++++++------------ 1 file changed, 70 insertions(+), 62 deletions(-) diff --git a/mobile/chrome/content/deckbrowser.xml b/mobile/chrome/content/deckbrowser.xml index 2ff901f1f165..712a95ba9be3 100644 --- a/mobile/chrome/content/deckbrowser.xml +++ b/mobile/chrome/content/deckbrowser.xml @@ -111,7 +111,7 @@ var self = this; this._updateTimeout = setTimeout(function () { - if (!self.dragData.dragging && !self.dragData.kineticId) + if (!self.dragData.dragging) self._browserToCanvas(); }, 100); ]]> @@ -750,37 +750,42 @@ 0) { - this.dragData.velocityX = -dx / dt; - this.dragData.velocityY = -dy / dt; - - this.dragData.originalX = this.dragData.dragX; - this.dragData.originalY = this.dragData.dragY; + let p2 = this._panEventTracker[this._panEventTrackerIndex]; + let p1 = this._panEventTracker[(this._panEventTrackerIndex + 1) % this.PAN_EVENTS_TO_TRACK]; + if (p2 && p1) { + let dx = p2.x - p1.x; + let dy = p2.y - p1.y; + let dt = p2.t - p1.t; + if (dt > 0) { + this.dragData.velocityX = -dx / dt; + this.dragData.velocityY = -dy / dt; + + 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)); + let [destPageX, destPageY] = this._constrainPanCoords(this._screenToPage(this.dragData.dragX + + this.dragData.velocityX * 800), + this._screenToPage(this.dragData.dragY + + this.dragData.velocityY * 800)); - this.dragData.destinationX = -this._pageToScreen(destPageX); - this.dragData.destinationY = -this._pageToScreen(destPageY); + this.dragData.destinationX = -this._pageToScreen(destPageX); + this.dragData.destinationY = -this._pageToScreen(destPageY); - 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)); - } else { - this._endPan(); - } - } else { - this._endPan() - } + 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)); + } else { + this._endPan(); + } + } else { + this._endPan() + } + + // Clear out the old events since they aren't needed anymore + for (var i = 0; i < this.PAN_EVENTS_TO_TRACK; i++) { + this._panEventTracker[i] = null; + } ]]> @@ -863,7 +868,7 @@