Bug 1457586 - Refactor APZCTreeManager::ProcessTouchVelocity() and related functions to take the time and position deltas separately. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Sun, 05 Aug 2018 00:45:48 -0400
changeset 826876 5d470348b10dba774ab9933a10858a2f1bee1a72
parent 826498 ac6a7c26cff462c90da419c4991f30ae4547685a
child 826877 1081cfbef3066c409f324345f7abf717ae101ff1
child 827066 d55aa360ae5c09b793f858f3436aeb10cc465c2e
push id118401
push userbballo@mozilla.com
push dateMon, 06 Aug 2018 01:00:27 +0000
reviewerskats
bugs1457586
milestone63.0a1
Bug 1457586 - Refactor APZCTreeManager::ProcessTouchVelocity() and related functions to take the time and position deltas separately. r=kats The motivation is to support velocity tracking implementations (added in a later patch) that need the position delta rather than resulting velocity. Also rename the functions to make it clearer that they have to do with dynamic toolbar movement. MozReview-Commit-ID: G0IVJHYTurB
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
gfx/layers/apz/src/Axis.cpp
gfx/layers/apz/src/Axis.h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -1989,20 +1989,25 @@ APZCTreeManager::ProcessUnhandledEvent(L
   }
 
   // Update the focus sequence number and attach it to the event
   mFocusState.ReceiveFocusChangingEvent();
   *aOutFocusSequenceNumber = mFocusState.LastAPZProcessedEvent();
 }
 
 void
-APZCTreeManager::ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY)
+APZCTreeManager::ProcessDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                                    uint32_t aEndTimestampMs,
+                                                    ScreenCoord aDeltaY)
 {
   if (mApzcForInputBlock) {
-    mApzcForInputBlock->HandleTouchVelocity(aTimestampMs, aSpeedY);
+    mApzcForInputBlock->HandleDynamicToolbarMovement(
+        aStartTimestampMs,
+        aEndTimestampMs,
+        ViewAs<ParentLayerPixel>(aDeltaY, PixelCastJustification::ScreenIsParentLayerForRoot));
   }
 }
 
 void
 APZCTreeManager::SetKeyboardMap(const KeyboardMap& aKeyboardMap)
 {
   APZThreadUtils::AssertOnControllerThread();
 
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -583,22 +583,25 @@ public:
                                                          HitTestingTreeNodeAutoLock* aOutScrollbarNode = nullptr);
   already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const LayersId& aLayersId,
                                                          const FrameMetrics::ViewID& aScrollId);
   ScreenToParentLayerMatrix4x4 GetScreenToApzcTransform(const AsyncPanZoomController *aApzc) const;
   ParentLayerToScreenMatrix4x4 GetApzcToGeckoTransform(const AsyncPanZoomController *aApzc) const;
   ScreenPoint GetCurrentMousePosition() const;
 
   /**
-   * Process touch velocity.
-   * Sometimes the touch move event will have a velocity even though no scrolling
-   * is occurring such as when the toolbar is being hidden/shown in Fennec.
-   * This function can be called to have the y axis' velocity queue updated.
+   * Process a movement of the dynamic toolbar by |aDeltaY| over the time
+   * period from |aStartTimestampMs| to |aEndTimestampMs|.
+   * This is used to track velocities accurately in the presence of movement
+   * of the dynamic toolbar, since in such cases the finger can be moving
+   * relative to the screen even though no scrolling is occurring.
    */
-  void ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY);
+  void ProcessDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                     uint32_t aEndTimestampMs,
+                                     ScreenCoord aDeltaY);
 private:
   typedef bool (*GuidComparator)(const ScrollableLayerGuid&, const ScrollableLayerGuid&);
 
   /* Helpers */
   template<class ScrollNode>
   void UpdateHitTestingTreeImpl(LayersId aRootLayerTreeId,
                                 const ScrollNode& aRoot,
                                 bool aIsFirstPaint,
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
@@ -637,21 +637,22 @@ AndroidDynamicToolbarAnimator::ProcessTo
     RequestComposite();
     // If there was no delta left over, the event was completely consumed.
     if (deltaRemainder == 0) {
       status = nsEventStatus_eConsumeNoDefault;
     }
 
     uint32_t timeDelta = aTimeStamp - mControllerLastEventTimeStamp;
     if (mControllerLastEventTimeStamp && timeDelta && aDelta) {
-      float speed = -(float)aDelta / (float)timeDelta;
       // we can't use mApz because we're on the controller thread, so we have
       // the caller provide a RefPtr to the same underlying object, which should
       // be safe to use.
-      aApz->ProcessTouchVelocity(aTimeStamp, speed);
+      aApz->ProcessDynamicToolbarMovement(mControllerLastEventTimeStamp,
+                                          aTimeStamp,
+                                          -(float)aDelta);
     }
   }
 
   return status;
 }
 
 void
 AndroidDynamicToolbarAnimator::HandleTouchEnd(StaticToolbarState aCurrentToolbarState, ScreenIntCoord aCurrentTouch)
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1209,19 +1209,23 @@ nsEventStatus AsyncPanZoomController::Ha
     break;
   }
   default: MOZ_ASSERT_UNREACHABLE("Unhandled input event"); break;
   }
 
   return rv;
 }
 
-void AsyncPanZoomController::HandleTouchVelocity(uint32_t aTimesampMs, float aSpeedY)
+void AsyncPanZoomController::HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                                          uint32_t aEndTimestampMs,
+                                                          ParentLayerCoord aDeltaY)
 {
-  mY.HandleTouchVelocity(aTimesampMs, aSpeedY);
+  mY.HandleDynamicToolbarMovement(aStartTimestampMs,
+                                  aEndTimestampMs,
+                                  aDeltaY);
 }
 
 void AsyncPanZoomController::StartAutoscroll(const ScreenPoint& aPoint)
 {
   // Cancel any existing animation.
   CancelAnimation();
 
   SetState(AUTOSCROLL);
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -351,22 +351,25 @@ public:
    * Currently some gestures are detected in GestureEventListener that calls
    * APZC back through this handler in order to avoid recursive calls to
    * APZC::HandleInputEvent() which is supposed to do the work for
    * ReceiveInputEvent().
    */
   nsEventStatus HandleGestureEvent(const InputData& aEvent);
 
   /**
-   * Handler for touch velocity.
-   * Sometimes the touch move event will have a velocity even though no scrolling
-   * is occurring such as when the toolbar is being hidden/shown in Fennec.
-   * This function can be called to have the y axis' velocity queue updated.
+   * Handle movement of the dynamic toolbar by |aDeltaY| over the time
+   * period from |aStartTimestampMs| to |aEndTimestampMs|.
+   * This is used to track velocities accurately in the presence of movement
+   * of the dynamic toolbar, since in such cases the finger can be moving
+   * relative to the screen even though no scrolling is occurring.
    */
-  void HandleTouchVelocity(uint32_t aTimesampMs, float aSpeedY);
+  void HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                    uint32_t aEndTimestampMs,
+                                    ParentLayerCoord aDeltaY);
 
   /**
    * Start autoscrolling this APZC, anchored at the provided location.
    */
   void StartAutoscroll(const ScreenPoint& aAnchorLocation);
 
   /**
    * Stop autoscrolling this APZC.
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -137,24 +137,30 @@ float Axis::ApplyFlingCurveToVelocity(fl
 
 void Axis::AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity) {
   mVelocityQueue.AppendElement(std::make_pair(aTimestampMs, aVelocity));
   if (mVelocityQueue.Length() > gfxPrefs::APZMaxVelocityQueueSize()) {
     mVelocityQueue.RemoveElementAt(0);
   }
 }
 
-void Axis::HandleTouchVelocity(uint32_t aTimestampMs, float aSpeed) {
+void Axis::HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                        uint32_t aEndTimestampMs,
+                                        ParentLayerCoord aDelta)
+{
   // mVelocityQueue is controller-thread only
   APZThreadUtils::AssertOnControllerThread();
 
-  mVelocity = ApplyFlingCurveToVelocity(aSpeed);
-  mVelocitySampleTimeMs = aTimestampMs;
+  float timeDelta = aEndTimestampMs - aStartTimestampMs;
+  MOZ_ASSERT(timeDelta != 0);
+  float speed = aDelta / timeDelta;
+  mVelocity = ApplyFlingCurveToVelocity(speed);
+  mVelocitySampleTimeMs = aEndTimestampMs;
 
-  AddVelocityToQueue(aTimestampMs, mVelocity);
+  AddVelocityToQueue(aEndTimestampMs, mVelocity);
 }
 
 void Axis::StartTouch(ParentLayerCoord aPos, uint32_t aTimestampMs) {
   mStartPos = aPos;
   mPos = aPos;
   mVelocitySampleTimeMs = aTimestampMs;
   mVelocitySamplePos = aPos;
   mAxisLocked = false;
--- a/gfx/layers/apz/src/Axis.h
+++ b/gfx/layers/apz/src/Axis.h
@@ -52,17 +52,19 @@ public:
    */
   void UpdateWithTouchAtDevicePoint(ParentLayerCoord aPos, uint32_t aTimestampMs);
 
 protected:
   float ApplyFlingCurveToVelocity(float aVelocity) const;
   void AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity);
 
 public:
-  void HandleTouchVelocity(uint32_t aTimestampMs, float aSpeed);
+  void HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                    uint32_t aEndTimestampMs,
+                                    ParentLayerCoord aDelta);
 
   /**
    * Notify this Axis that a touch has begun, i.e. the user has put their finger
    * on the screen but has not yet tried to pan.
    */
   void StartTouch(ParentLayerCoord aPos, uint32_t aTimestampMs);
 
   /**