Bug 597283 - Limit pan animation using MozBeforePaint [r=mfinkle]
authorBenjamin Stover <bstover@mozilla.com>
Fri, 17 Sep 2010 11:28:35 -0700
changeset 66667 75473be322cf5815ec6f51615309017a52044f8c
parent 66666 9f1a6c031b133ccada78ad82017a23007e9733b0
child 66668 446fd200900d4be65f1216858e14081d3f382271
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs597283
Bug 597283 - Limit pan animation using MozBeforePaint [r=mfinkle]
mobile/chrome/content/InputHandler.js
--- 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);
   },