Bug 597283 - Limit pan animation using MozBeforePaint [r=mfinkle]
--- a/mobile/chrome/content/InputHandler.js
+++ b/mobile/chrome/content/InputHandler.js
@@ -344,17 +344,17 @@ function MouseModule(owner, browserViewC
this._kineticStop.bind(this));
messageManager.addMessageListener("Browser:ContextMenu", this);
}
MouseModule.prototype = {
handleEvent: function handleEvent(aEvent) {
- if (aEvent.button !== 0 && aEvent.type != "contextmenu")
+ if (aEvent.button !== 0 && aEvent.type != "contextmenu" && aEvent.type != "MozBeforePaint")
return;
switch (aEvent.type) {
case "mousedown":
this._onMouseDown(aEvent);
break;
case "mousemove":
this._onMouseMove(aEvent);
@@ -367,16 +367,20 @@ MouseModule.prototype = {
this._doDragStop(0, 0, true);
break;
case "MozMagnifyGestureStart":
case "MozMagnifyGesture":
// disallow kinetic panning after gesture
if (this._dragData.dragging)
this._doDragStop(0, 0, true);
break;
+ case "MozBeforePaint":
+ this._waitingForPaint = false;
+ removeEventListener("MozBeforePaint", this, false);
+ break;
}
},
receiveMessage: function receiveMessage(aMessage) {
// TODO: Make "contextmenu" a first class part of InputHandler
// Bug 554639
if (aMessage.name != "Browser:ContextMenu" || !ContextHelper.popupState)
return;
@@ -520,17 +524,17 @@ MouseModule.prototype = {
},
/**
* If we're in a drag, do what we have to do to drag on.
*/
_onMouseMove: function _onMouseMove(aEvent) {
let dragData = this._dragData;
- if (dragData.dragging) {
+ if (dragData.dragging && !this._waitingForPaint) {
let oldIsPan = dragData.isPan();
dragData.setDragPosition(aEvent.screenX, aEvent.screenY);
aEvent.stopPropagation();
aEvent.preventDefault();
if (dragData.isPan()) {
this._owner.grab(this);
// Only pan when mouse event isn't part of a click. Prevent jittering on tap.
let [sX, sY] = dragData.panPosition();
@@ -604,17 +608,23 @@ MouseModule.prototype = {
/**
* Used by _doDragMove() above and by KineticController's timer to do the
* actual dragMove signalling to the dragger. We'd put this in _doDragMove()
* but then KineticController would be adding to its own data as it signals
* the dragger of dragMove()s.
*/
_dragBy: function _dragBy(dX, dY) {
let dragData = this._dragData;
- return this._dragger.dragMove(dX, dY, this._targetScrollInterface);
+ let dragged = this._dragger.dragMove(dX, dY, this._targetScrollInterface);
+ if (dragged && !this._waitingForPaint) {
+ this._waitingForPaint = true;
+ mozRequestAnimationFrame();
+ addEventListener("MozBeforePaint", this, false);
+ }
+ return dragged;
},
/** Callback for kinetic scroller. */
_kineticStop: function _kineticStop() {
let dragData = this._dragData;
if (!dragData.dragging)
this._doDragStop(0, 0, true);
},