Bug 1083395 - Extract helpers function from the input-handling codepath. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 24 Oct 2014 13:29:03 -0400
changeset 212292 00fdb9ef3be69c800433e2b28c8bb601642d6cf3
parent 212291 bcc51b1a6c072af60d24492cd36811e6703bd719
child 212293 e194c411165c0835a0fbfb68767d9a2e3032b62f
push id27704
push userkwierso@gmail.com
push dateSat, 25 Oct 2014 01:25:30 +0000
treeherdermozilla-central@e37231060eb4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1083395
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1083395 - Extract helpers function from the input-handling codepath. r=botond
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1031,17 +1031,17 @@ nsEventStatus AsyncPanZoomController::Re
       if (block->GetOverscrollHandoffChain()->HasFastMovingApzc()) {
         // If we're already in a fast fling, then we want the touch event to stop the fling
         // and to disallow the touch event from being used as part of a fling.
         block->DisallowSingleTap();
       }
       block->GetOverscrollHandoffChain()->CancelAnimations();
     }
 
-    if (mFrameMetrics.GetMayHaveTouchListeners() || mFrameMetrics.GetMayHaveTouchCaret()) {
+    if (NeedToWaitForContent()) {
       // Content may intercept the touch events and prevent-default them. So we schedule
       // a timeout to give content time to do that.
       ScheduleContentResponseTimeout();
     } else {
       // Content won't prevent-default this, so we can just pretend like we scheduled
       // a timeout and it expired. Note that we will still receive a ContentReceivedTouch
       // callback for this block, and so we need to make sure we adjust the touch balance.
       APZC_LOG("%p not waiting for content response on block %p\n", this, block);
@@ -2999,24 +2999,18 @@ AsyncPanZoomController::ProcessPendingIn
     TouchBlockState* curBlock = CurrentTouchBlock();
     if (!curBlock->IsReadyForHandling()) {
       break;
     }
 
     APZC_LOG("%p processing input block %p; preventDefault %d\n",
         this, curBlock, curBlock->IsDefaultPrevented());
     if (curBlock->IsDefaultPrevented()) {
-      SetState(NOTHING);
       curBlock->DropEvents();
-      // Also clear the state in the gesture event listener
-      nsRefPtr<GestureEventListener> listener = GetGestureEventListener();
-      if (listener) {
-        MultiTouchInput cancel(MultiTouchInput::MULTITOUCH_CANCEL, 0, TimeStamp::Now(), 0);
-        listener->HandleInputEvent(cancel);
-      }
+      ResetInputState();
     } else {
       while (curBlock->HasEvents()) {
         HandleInputEvent(curBlock->RemoveFirstEvent());
       }
     }
     MOZ_ASSERT(!curBlock->HasEvents());
 
     if (mTouchBlockQueue.Length() == 1) {
@@ -3029,16 +3023,34 @@ AsyncPanZoomController::ProcessPendingIn
 
     // If we get here, we know there are more touch blocks in the queue after
     // |curBlock|, so we can remove |curBlock| and try to process the next one.
     APZC_LOG("%p discarding depleted touch block %p\n", this, curBlock);
     mTouchBlockQueue.RemoveElementAt(0);
   }
 }
 
+bool
+AsyncPanZoomController::NeedToWaitForContent() const
+{
+  return (mFrameMetrics.GetMayHaveTouchListeners() || mFrameMetrics.GetMayHaveTouchCaret());
+}
+
+void
+AsyncPanZoomController::ResetInputState()
+{
+  SetState(NOTHING);
+  // Also clear the state in the gesture event listener
+  nsRefPtr<GestureEventListener> listener = GetGestureEventListener();
+  if (listener) {
+    MultiTouchInput cancel(MultiTouchInput::MULTITOUCH_CANCEL, 0, TimeStamp::Now(), 0);
+    listener->HandleInputEvent(cancel);
+  }
+}
+
 TouchBlockState*
 AsyncPanZoomController::StartNewTouchBlock(bool aCopyAllowedTouchBehaviorFromCurrent)
 {
   TouchBlockState* newBlock = new TouchBlockState(BuildOverscrollHandoffChain());
   if (gfxPrefs::TouchActionEnabled() && aCopyAllowedTouchBehaviorFromCurrent) {
     newBlock->CopyAllowedTouchBehaviorsFrom(*CurrentTouchBlock());
   }
 
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -810,16 +810,18 @@ private:
   /**
    * Processes any pending input blocks that are ready for processing. There
    * must be at least one input block in the queue when this function is called.
    */
   void ProcessPendingInputBlocks();
   TouchBlockState* StartNewTouchBlock(bool aCopyAllowedTouchBehaviorFromCurrent);
   TouchBlockState* CurrentTouchBlock();
   bool HasReadyTouchBlock();
+  bool NeedToWaitForContent() const;
+  void ResetInputState();
 
 private:
   // The queue of touch blocks that have not yet been processed by this APZC.
   // This member must only be accessed on the controller/UI thread.
   nsTArray<UniquePtr<TouchBlockState>> mTouchBlockQueue;
 
   // This variable requires some explanation. Strap yourself in.
   //