Factor out content-handling code from TouchBlockState. (bug 1013432 part 1, r=kats)
authorDavid Anderson <danderson@mozilla.com>
Tue, 09 Dec 2014 02:33:29 -0800
changeset 218838 0f96a3aa598c8221eaa15f6a2b89b31a6b9f420e
parent 218837 110ecfd89e2755487020135cb271270f4e37d305
child 218839 6a9fef0398d306133bef6c53742044dd9dbb382a
push id27946
push userryanvm@gmail.com
push dateTue, 09 Dec 2014 19:04:58 +0000
treeherdermozilla-central@dce2f7ec002e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1013432
milestone37.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
Factor out content-handling code from TouchBlockState. (bug 1013432 part 1, r=kats)
gfx/layers/apz/src/InputBlockState.cpp
gfx/layers/apz/src/InputBlockState.h
--- a/gfx/layers/apz/src/InputBlockState.cpp
+++ b/gfx/layers/apz/src/InputBlockState.cpp
@@ -73,60 +73,81 @@ InputBlockState::GetBlockId() const
 }
 
 bool
 InputBlockState::IsTargetConfirmed() const
 {
   return mTargetConfirmed;
 }
 
-TouchBlockState::TouchBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc,
-                                 bool aTargetConfirmed)
+CancelableBlockState::CancelableBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc,
+                                           bool aTargetConfirmed)
   : InputBlockState(aTargetApzc, aTargetConfirmed)
-  , mAllowedTouchBehaviorSet(false)
   , mPreventDefault(false)
   , mContentResponded(false)
   , mContentResponseTimerExpired(false)
-  , mDuringFastMotion(false)
-  , mSingleTapOccurred(false)
 {
-  TBS_LOG("Creating %p\n", this);
 }
 
 bool
-TouchBlockState::SetContentResponse(bool aPreventDefault)
+CancelableBlockState::SetContentResponse(bool aPreventDefault)
 {
   if (mContentResponded) {
     return false;
   }
   TBS_LOG("%p got content response %d with timer expired %d\n",
     this, aPreventDefault, mContentResponseTimerExpired);
   if (!mContentResponseTimerExpired) {
     mPreventDefault = aPreventDefault;
   }
   mContentResponded = true;
   return true;
 }
 
 bool
-TouchBlockState::TimeoutContentResponse()
+CancelableBlockState::TimeoutContentResponse()
 {
   if (mContentResponseTimerExpired) {
     return false;
   }
   TBS_LOG("%p got content timer expired with response received %d\n",
     this, mContentResponded);
   if (!mContentResponded) {
     mPreventDefault = false;
   }
   mContentResponseTimerExpired = true;
   return true;
 }
 
 bool
+CancelableBlockState::IsDefaultPrevented() const
+{
+  MOZ_ASSERT(mContentResponded || mContentResponseTimerExpired);
+  return mPreventDefault;
+}
+
+bool
+CancelableBlockState::IsReadyForHandling() const
+{
+  if (!IsTargetConfirmed())
+    return false;
+  return mContentResponded || mContentResponseTimerExpired;
+}
+
+TouchBlockState::TouchBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc,
+                                 bool aTargetConfirmed)
+  : CancelableBlockState(aTargetApzc, aTargetConfirmed)
+  , mAllowedTouchBehaviorSet(false)
+  , mDuringFastMotion(false)
+  , mSingleTapOccurred(false)
+{
+  TBS_LOG("Creating %p\n", this);
+}
+
+bool
 TouchBlockState::SetAllowedTouchBehaviors(const nsTArray<TouchBehaviorFlags>& aBehaviors)
 {
   if (mAllowedTouchBehaviorSet) {
     return false;
   }
   TBS_LOG("%p got allowed touch behaviours for %lu points\n", this, aBehaviors.Length());
   mAllowedTouchBehaviors.AppendElements(aBehaviors);
   mAllowedTouchBehaviorSet = true;
@@ -139,36 +160,27 @@ TouchBlockState::CopyAllowedTouchBehavio
   TBS_LOG("%p copying allowed touch behaviours from %p\n", this, &aOther);
   MOZ_ASSERT(aOther.mAllowedTouchBehaviorSet);
   return SetAllowedTouchBehaviors(aOther.mAllowedTouchBehaviors);
 }
 
 bool
 TouchBlockState::IsReadyForHandling() const
 {
-  if (!IsTargetConfirmed()) {
+  if (!CancelableBlockState::IsReadyForHandling()) {
     return false;
   }
+
   // TODO: for long-tap blocks we probably don't need the touch behaviour?
   if (gfxPrefs::TouchActionEnabled() && !mAllowedTouchBehaviorSet) {
     return false;
   }
-  if (!mContentResponded && !mContentResponseTimerExpired) {
-    return false;
-  }
   return true;
 }
 
-bool
-TouchBlockState::IsDefaultPrevented() const
-{
-  MOZ_ASSERT(mContentResponded || mContentResponseTimerExpired);
-  return mPreventDefault;
-}
-
 void
 TouchBlockState::SetDuringFastMotion()
 {
   TBS_LOG("%p setting fast-motion flag\n", this);
   mDuringFastMotion = true;
 }
 
 bool
--- a/gfx/layers/apz/src/InputBlockState.h
+++ b/gfx/layers/apz/src/InputBlockState.h
@@ -39,86 +39,110 @@ protected:
 private:
   nsRefPtr<AsyncPanZoomController> mTargetApzc;
   nsRefPtr<const OverscrollHandoffChain> mOverscrollHandoffChain;
   bool mTargetConfirmed;
   const uint64_t mBlockId;
 };
 
 /**
+ * This class represents a set of events that can be cancelled by web content
+ * via event listeners.
+ *
+ * Each cancelable input block can be cancelled by web content, and
+ * this information is stored in the mPreventDefault flag. Because web
+ * content runs on the Gecko main thread, we cannot always wait for web content's
+ * response. Instead, there is a timeout that sets this flag in the case
+ * where web content doesn't respond in time. The mContentResponded
+ * and mContentResponseTimerExpired flags indicate which of these scenarios
+ * occurred.
+ */
+class CancelableBlockState : public InputBlockState
+{
+public:
+  CancelableBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc,
+                       bool aTargetConfirmed);
+
+  /**
+   * Record whether or not content cancelled this block of events.
+   * @param aPreventDefault true iff the block is cancelled.
+   * @return false if this block has already received a response from
+   *         web content, true if not.
+   */
+  bool SetContentResponse(bool aPreventDefault);
+
+  /**
+   * Record that content didn't respond in time.
+   * @return false if this block already timed out, true if not.
+   */
+  bool TimeoutContentResponse();
+
+  /**
+   * @return true iff web content cancelled this block of events.
+   */
+  bool IsDefaultPrevented() const;
+
+  /**
+   * @returns true if web content responded or timed out.
+   */
+  virtual bool IsReadyForHandling() const;
+
+private:
+  bool mPreventDefault;
+  bool mContentResponded;
+  bool mContentResponseTimerExpired;
+};
+
+/**
  * This class represents a single touch block. A touch block is
  * a set of touch events that can be cancelled by web content via
  * touch event listeners.
  *
  * Every touch-start event creates a new touch block. In this case, the
  * touch block consists of the touch-start, followed by all touch events
  * up to but not including the next touch-start (except in the case where
  * a long-tap happens, see below). Note that in particular we cannot know
  * when a touch block ends until the next one is started. Most touch
  * blocks are created by receipt of a touch-start event.
  *
  * Every long-tap event also creates a new touch block, since it can also
  * be consumed by web content. In this case, when the long-tap event is
  * dispatched to web content, a new touch block is started to hold the remaining
  * touch events, up to but not including the next touch start (or long-tap).
  *
- * Conceptually, each touch block can be cancelled by web content, and
- * this information is stored in the mPreventDefault flag. Because web
- * content runs on the Gecko main thread, we cannot always wait for web content's
- * response. Instead, there is a timeout that sets this flag in the case
- * where web content doesn't respond in time. The mContentResponded
- * and mContentResponseTimerExpired flags indicate which of these scenarios
- * occurred.
- *
  * Additionally, if touch-action is enabled, each touch block should
  * have a set of allowed touch behavior flags; one for each touch point.
  * This also requires running code on the Gecko main thread, and so may
  * be populated with some latency. The mAllowedTouchBehaviorSet and
  * mAllowedTouchBehaviors variables track this information.
  */
-class TouchBlockState : public InputBlockState
+class TouchBlockState : public CancelableBlockState
 {
 public:
   typedef uint32_t TouchBehaviorFlags;
 
   explicit TouchBlockState(const nsRefPtr<AsyncPanZoomController>& aTargetApzc,
                            bool aTargetConfirmed);
 
   /**
-   * Record whether or not content cancelled this block of events.
-   * @param aPreventDefault true iff the block is cancelled.
-   * @return false if this block has already received a response from
-   *         web content, true if not.
-   */
-  bool SetContentResponse(bool aPreventDefault);
-  /**
-   * Record that content didn't respond in time.
-   * @return false if this block already timed out, true if not.
-   */
-  bool TimeoutContentResponse();
-  /**
    * Set the allowed touch behavior flags for this block.
    * @return false if this block already has these flags set, true if not.
    */
   bool SetAllowedTouchBehaviors(const nsTArray<TouchBehaviorFlags>& aBehaviors);
   /**
    * Copy the allowed touch behavior flags from another block.
    * @return false if this block already has these flags set, true if not.
    */
   bool CopyAllowedTouchBehaviorsFrom(const TouchBlockState& aOther);
 
   /**
    * @return true iff this block has received all the information needed
    *         to properly dispatch the events in the block.
    */
-  bool IsReadyForHandling() const;
-  /**
-   * @return true iff web content cancelled this block of events.
-   */
-  bool IsDefaultPrevented() const;
+  bool IsReadyForHandling() const MOZ_OVERRIDE;
 
   /**
    * Sets a flag that indicates this input block occurred while the APZ was
    * in a state of fast motion. This affects gestures that may be produced
    * from input events in this block.
    */
   void SetDuringFastMotion();
   /**
@@ -171,19 +195,16 @@ public:
    */
   bool TouchActionAllowsPanningX() const;
   bool TouchActionAllowsPanningY() const;
   bool TouchActionAllowsPanningXY() const;
 
 private:
   nsTArray<TouchBehaviorFlags> mAllowedTouchBehaviors;
   bool mAllowedTouchBehaviorSet;
-  bool mPreventDefault;
-  bool mContentResponded;
-  bool mContentResponseTimerExpired;
   bool mDuringFastMotion;
   bool mSingleTapOccurred;
   nsTArray<MultiTouchInput> mEvents;
 };
 
 } // namespace layers
 } // namespace mozilla