Back out e5f8db95d0c5 (Bug 639179 Part 3) due to mobile unittest orange.

This commit is contained in:
L. David Baron 2011-04-09 18:25:02 -07:00
parent b925795dbb
commit fd5da61b62

View File

@ -60,13 +60,6 @@ const kAxisLockRevertThreshold = 0.8;
// Same as NS_EVENT_STATE_ACTIVE from nsIEventStateManager.h // Same as NS_EVENT_STATE_ACTIVE from nsIEventStateManager.h
const kStateActive = 0x00000001; const kStateActive = 0x00000001;
// After a drag begins, kinetic panning is stopped if the drag doesn't become
// a pan in 300 milliseconds.
const kStopKineticPanOnDragTimeout = 300;
// Max velocity of a pan. This is in pixels/millisecond.
const kMaxVelocity = 6;
/** /**
* MouseModule * MouseModule
* *
@ -212,21 +205,19 @@ MouseModule.prototype = {
this._targetScrollInterface = targetScrollInterface; this._targetScrollInterface = targetScrollInterface;
// Do tap // Do tap
if (!this._kinetic.isActive()) { let event = document.createEvent("Events");
let event = document.createEvent("Events"); event.initEvent("TapDown", true, true);
event.initEvent("TapDown", true, true); event.clientX = aEvent.clientX;
event.clientX = aEvent.clientX; event.clientY = aEvent.clientY;
event.clientY = aEvent.clientY; let success = aEvent.target.dispatchEvent(event);
let success = aEvent.target.dispatchEvent(event); if (success) {
if (success) { this._recordEvent(aEvent);
this._recordEvent(aEvent); this._target = aEvent.target;
this._target = aEvent.target; this._mouseOverTimeout.once(kOverTapWait);
this._mouseOverTimeout.once(kOverTapWait); this._longClickTimeout.once(kLongTapWait);
this._longClickTimeout.once(kLongTapWait); } else {
} else { // cancel all pending content clicks
// cancel all pending content clicks this._cleanClickBuffer();
this._cleanClickBuffer();
}
} }
// Do pan // Do pan
@ -367,7 +358,6 @@ MouseModule.prototype = {
let dragData = this._dragData; let dragData = this._dragData;
dragData.setDragStart(aEvent.screenX, aEvent.screenY, aDraggable); dragData.setDragStart(aEvent.screenX, aEvent.screenY, aDraggable);
this._kinetic.addData(0, 0); this._kinetic.addData(0, 0);
this._dragStartTime = Date.now();
if (!this._kinetic.isActive()) if (!this._kinetic.isActive())
this._dragger.dragStart(aEvent.clientX, aEvent.clientY, aEvent.target, this._targetScrollInterface); this._dragger.dragStart(aEvent.clientX, aEvent.clientY, aEvent.target, this._targetScrollInterface);
}, },
@ -384,15 +374,13 @@ MouseModule.prototype = {
// mousedown/mouseup event previous to this one. In this case, we // mousedown/mouseup event previous to this one. In this case, we
// want the kinetic panner to tell our drag interface to stop. // want the kinetic panner to tell our drag interface to stop.
if (dragData.isPan()) { if (!dragData.isPan() && !this._kinetic.isActive()) {
if (Date.now() - this._dragStartTime > kStopKineticPanOnDragTimeout) // There was no pan and no kinetic scrolling, so just stop dragger.
this._kinetic._velocity.set(0, 0);
// Start kinetic pan.
this._kinetic.start();
} else {
this._kinetic.end();
this._dragger.dragStop(0, 0, this._targetScrollInterface); this._dragger.dragStop(0, 0, this._targetScrollInterface);
this._dragger = null; this._dragger = null;
} else if (dragData.isPan()) {
// Start kinetic pan.
this._kinetic.start();
} }
}, },
@ -404,7 +392,6 @@ MouseModule.prototype = {
*/ */
_dragBy: function _dragBy(dX, dY, aIsKinetic) { _dragBy: function _dragBy(dX, dY, aIsKinetic) {
let dragged = true; let dragged = true;
let dragData = this._dragData;
if (!this._waitingForPaint || aIsKinetic) { if (!this._waitingForPaint || aIsKinetic) {
let dragData = this._dragData; let dragData = this._dragData;
dragged = this._dragger.dragMove(dX, dY, this._targetScrollInterface, aIsKinetic); dragged = this._dragger.dragMove(dX, dY, this._targetScrollInterface, aIsKinetic);
@ -415,9 +402,6 @@ MouseModule.prototype = {
this.dX = 0; this.dX = 0;
this.dY = 0; this.dY = 0;
} }
if (!dragData.isPan())
this._kinetic.pause();
return dragged; return dragged;
}, },
@ -847,7 +831,6 @@ function KineticController(aPanBy, aEndCallback) {
KineticController.prototype = { KineticController.prototype = {
_reset: function _reset() { _reset: function _reset() {
this._active = false; this._active = false;
this._paused = false;
this.momentumBuffer = []; this.momentumBuffer = [];
this._velocity.set(0, 0); this._velocity.set(0, 0);
}, },
@ -889,9 +872,7 @@ KineticController.prototype = {
let callback = { let callback = {
onBeforePaint: function kineticHandleEvent(timeStamp) { onBeforePaint: function kineticHandleEvent(timeStamp) {
// Someone called end() on us between timer intervals if (!self.isActive()) // someone called end() on us between timer intervals
// or we are paused.
if (!self.isActive() || self._paused)
return; return;
// To make animation end fast enough but to keep smoothness, average the ideal // To make animation end fast enough but to keep smoothness, average the ideal
@ -942,7 +923,6 @@ KineticController.prototype = {
}; };
this._active = true; this._active = true;
this._paused = false;
mozRequestAnimationFrame(callback); mozRequestAnimationFrame(callback);
}, },
@ -969,22 +949,9 @@ KineticController.prototype = {
} }
} }
let currentVelocityX = 0; // Only allow kinetic scrolling to speed up if kinetic scrolling is active.
let currentVelocityY = 0; this._velocity.x = (distanceX < 0 ? Math.min : Math.max)((distanceX / swipeLength) * this._speedSensitivity, this._velocity.x);
this._velocity.y = (distanceY < 0 ? Math.min : Math.max)((distanceY / swipeLength) * this._speedSensitivity, this._velocity.y);
if (this.isActive()) {
let currentTime = Date.now() - this._initialTime;
currentVelocityX = Util.clamp(this._velocity.x + this._acceleration.x * currentTime, -kMaxVelocity, kMaxVelocity);
currentVelocityY = Util.clamp(this._velocity.y + this._acceleration.y * currentTime, -kMaxVelocity, kMaxVelocity);
}
if (currentVelocityX * this._velocity.x <= 0)
currentVelocityX = 0;
if (currentVelocityY * this._velocity.y <= 0)
currentVelocityY = 0;
this._velocity.x = clampFromZero((distanceX / swipeLength) + currentVelocityX, Math.abs(currentVelocityX), kMaxVelocity);
this._velocity.y = clampFromZero((distanceY / swipeLength) + currentVelocityY, Math.abs(currentVelocityY), kMaxVelocity);
// Set acceleration vector to opposite signs of velocity // Set acceleration vector to opposite signs of velocity
this._acceleration.set(this._velocity.clone().map(sign).scale(-this._decelerationRate)); this._acceleration.set(this._velocity.clone().map(sign).scale(-this._decelerationRate));
@ -994,16 +961,12 @@ KineticController.prototype = {
this._time = 0; this._time = 0;
this.momentumBuffer = []; this.momentumBuffer = [];
if (!this.isActive() || this._paused) if (!this.isActive())
this._startTimer(); this._startTimer();
return true; return true;
}, },
pause: function pause() {
this._paused = true;
},
end: function end() { end: function end() {
if (this.isActive()) { if (this.isActive()) {
if (this._beforeEnd) if (this._beforeEnd)