From 16f21d1f8912c011d5bbd3e2bda84ce9531d76ca Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Mon, 6 Apr 2020 17:18:12 +0000 Subject: [PATCH] Bug 1589046 - Propagate the return value from AttemptScroll to DispatchScroll and CallDispatchScroll. r=botond No functional changes here. Differential Revision: https://phabricator.services.mozilla.com/D69623 --HG-- extra : moz-landing-system : lando --- gfx/layers/apz/src/APZCTreeManager.cpp | 12 +++++++---- gfx/layers/apz/src/APZCTreeManager.h | 12 ++++++++--- gfx/layers/apz/src/AsyncPanZoomController.cpp | 20 ++++++++++--------- gfx/layers/apz/src/AsyncPanZoomController.h | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 216484a917fa..dc377f31ec94 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -2623,7 +2623,7 @@ static bool TransformDisplacement(APZCTreeManager* aTreeManager, return true; } -void APZCTreeManager::DispatchScroll( +bool APZCTreeManager::DispatchScroll( AsyncPanZoomController* aPrev, ParentLayerPoint& aStartPoint, ParentLayerPoint& aEndPoint, OverscrollHandoffState& aOverscrollHandoffState) { @@ -2635,19 +2635,19 @@ void APZCTreeManager::DispatchScroll( // nothing more to scroll, so we ignore the rest of the pan gesture. if (overscrollHandoffChainIndex >= overscrollHandoffChain.Length()) { // Nothing more to scroll - ignore the rest of the pan gesture. - return; + return false; } next = overscrollHandoffChain.GetApzcAtIndex(overscrollHandoffChainIndex); if (next == nullptr || next->IsDestroyed()) { - return; + return false; } // Convert the start and end points from |aPrev|'s coordinate space to // |next|'s coordinate space. if (!TransformDisplacement(this, aPrev, next, aStartPoint, aEndPoint)) { - return; + return false; } // Scroll |next|. If this causes overscroll, it will call DispatchScroll() @@ -2662,7 +2662,11 @@ void APZCTreeManager::DispatchScroll( if (!TransformDisplacement(this, next, aPrev, aStartPoint, aEndPoint)) { NS_WARNING("Failed to untransform scroll points during dispatch"); } + return false; } + + // Return true to indicate the scroll was consumed entirely. + return true; } ParentLayerPoint APZCTreeManager::DispatchFling( diff --git a/gfx/layers/apz/src/APZCTreeManager.h b/gfx/layers/apz/src/APZCTreeManager.h index 9e69e927e3fc..1288a9c19f24 100644 --- a/gfx/layers/apz/src/APZCTreeManager.h +++ b/gfx/layers/apz/src/APZCTreeManager.h @@ -328,10 +328,10 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge { * overscroll to the next APZC. Note that because of scroll grabbing, the * first APZC to scroll may not be the one that is receiving the touch events. * - * |aAPZC| is the APZC that received the touch events triggering the scroll + * |aPrev| is the APZC that received the touch events triggering the scroll * (in the case of an initial scroll), or the last APZC to scroll (in the * case of overscroll) - * |aStartPoint| and |aEndPoint| are in |aAPZC|'s transformed screen + * |aStartPoint| and |aEndPoint| are in |aPrev|'s transformed screen * coordinates (i.e. the same coordinates in which touch points are given to * APZCs). The amount of (over)scroll is represented by two points rather * than a displacement because with certain 3D transforms, the same @@ -348,6 +348,12 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge { * an overscrolled state if no APZC further up in the handoff chain accepted * the entire scroll. * + * The function will return true if the entire scroll was consumed, and + * false otherwise. As this function also modifies aStartPoint and aEndPoint, + * when scroll is consumed, it should always the case that this function + * returns true if and only if IsZero(aStartPoint - aEndPoint), using the + * modified aStartPoint and aEndPoint after the function returns. + * * The way this method works is best illustrated with an example. * Consider three nested APZCs, A, B, and C, with C being the innermost one. * Say B is scroll-grabbing. @@ -376,7 +382,7 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge { * Note: this should be used for panning only. For handing off overscroll for * a fling, use DispatchFling(). */ - void DispatchScroll(AsyncPanZoomController* aApzc, + bool DispatchScroll(AsyncPanZoomController* aPrev, ParentLayerPoint& aStartPoint, ParentLayerPoint& aEndPoint, OverscrollHandoffState& aOverscrollHandoffState); diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index ff506a461192..b278b7106aa4 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -3264,12 +3264,14 @@ bool AsyncPanZoomController::AttemptScroll( // Note: "+ overscroll" rather than "- overscroll" because "overscroll" // is what's left of "displacement", and "displacement" is "start - end". ++aOverscrollHandoffState.mChainIndex; - CallDispatchScroll(aStartPoint, aEndPoint, aOverscrollHandoffState); - - overscroll = aStartPoint - aEndPoint; - if (IsZero(overscroll)) { + bool consumed = + CallDispatchScroll(aStartPoint, aEndPoint, aOverscrollHandoffState); + if (consumed) { return true; } + + overscroll = aStartPoint - aEndPoint; + MOZ_ASSERT(!IsZero(overscroll)); } // If there is no APZC later in the handoff chain that accepted the @@ -3501,7 +3503,7 @@ void AsyncPanZoomController::StartOverscrollAnimation( StartAnimation(new OverscrollAnimation(*this, aVelocity)); } -void AsyncPanZoomController::CallDispatchScroll( +bool AsyncPanZoomController::CallDispatchScroll( ParentLayerPoint& aStartPoint, ParentLayerPoint& aEndPoint, OverscrollHandoffState& aOverscrollHandoffState) { // Make a local copy of the tree manager pointer and check if it's not @@ -3509,7 +3511,7 @@ void AsyncPanZoomController::CallDispatchScroll( // Destroy(), which nulls out mTreeManager, could be called concurrently. APZCTreeManager* treeManagerLocal = GetApzcTreeManager(); if (!treeManagerLocal) { - return; + return false; } // Obey overscroll-behavior. @@ -3524,12 +3526,12 @@ void AsyncPanZoomController::CallDispatchScroll( } if (aStartPoint == endPoint) { // Handoff not allowed in either direction - don't even bother. - return; + return false; } } - treeManagerLocal->DispatchScroll(this, aStartPoint, endPoint, - aOverscrollHandoffState); + return treeManagerLocal->DispatchScroll(this, aStartPoint, endPoint, + aOverscrollHandoffState); } void AsyncPanZoomController::RecordScrollPayload(const TimeStamp& aTimeStamp) { diff --git a/gfx/layers/apz/src/AsyncPanZoomController.h b/gfx/layers/apz/src/AsyncPanZoomController.h index 86dde16ac076..dd2ef6ca8962 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.h +++ b/gfx/layers/apz/src/AsyncPanZoomController.h @@ -1534,7 +1534,7 @@ class AsyncPanZoomController { * Guards against the case where the APZC is being concurrently destroyed * (and thus mTreeManager is being nulled out). */ - void CallDispatchScroll(ParentLayerPoint& aStartPoint, + bool CallDispatchScroll(ParentLayerPoint& aStartPoint, ParentLayerPoint& aEndPoint, OverscrollHandoffState& aOverscrollHandoffState);