From 6651ba71a33be49625d6ff7b0bb32e795a62b9be Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Thu, 20 Aug 2020 00:10:09 +0000 Subject: [PATCH] Bug 1633322 - Turn APZEventResult::mHandledByRootApzc into a Maybe. r=kats,geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D79930 --- gfx/layers/apz/public/APZInputBridge.h | 9 ++++-- gfx/layers/apz/src/APZCTreeManager.cpp | 30 ++++++++++++------- gfx/layers/apz/src/APZCTreeManager.h | 2 +- gfx/layers/apz/src/APZInputBridge.cpp | 1 - .../apz/test/gtest/TestEventRegions.cpp | 4 +-- widget/android/nsWindow.cpp | 15 ++++++---- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/gfx/layers/apz/public/APZInputBridge.h b/gfx/layers/apz/public/APZInputBridge.h index 56f961a10b08..49016ca44771 100644 --- a/gfx/layers/apz/public/APZInputBridge.h +++ b/gfx/layers/apz/public/APZInputBridge.h @@ -60,10 +60,13 @@ struct APZEventResult { */ ScrollableLayerGuid mTargetGuid; /** - * This is set to true if we know for sure that the event will be handled - * by the root content APZC. + * This is: + * - set to true if we know for sure that the event will be handled + * by the root content APZC; + * - set to false if we know for sure it will not be; + * - left empty if we are unsure. */ - bool mHandledByRootApzc; + Maybe mHandledByRootApzc; /** * If this event started or was added to an input block, the id of that * input block, otherwise InputBlockState::NO_BLOCK_ID. diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index cc1b64166b84..1316bdf6f191 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -1543,7 +1543,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { // Update the out-parameters so they are what the caller expects. hit.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = hit.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = hit.HandledByRoot(); if (!hitScrollbar) { // The input was not targeted at a scrollbar, so we untransform it @@ -1628,7 +1628,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { // Update the out-parameters so they are what the caller expects. hit.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = hit.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = hit.HandledByRoot(); wheelInput.mOrigin = *untransformedOrigin; } break; @@ -1687,7 +1687,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { // Update the out-parameters so they are what the caller expects. hit.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = hit.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = hit.HandledByRoot(); panInput.mPanStartPoint = *untransformedStartPoint; panInput.mPanDisplacement = *untransformedDisplacement; @@ -1736,7 +1736,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { // Update the out-parameters so they are what the caller expects. hit.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = hit.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = hit.HandledByRoot(); pinchInput.mFocusPoint = *untransformedFocusPoint; } break; @@ -1766,7 +1766,7 @@ APZEventResult APZCTreeManager::ReceiveInputEvent(InputData& aEvent) { // Update the out-parameters so they are what the caller expects. hit.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = hit.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = hit.HandledByRoot(); tapInput.mPoint = *untransformedPoint; } break; @@ -2037,7 +2037,7 @@ APZEventResult APZCTreeManager::ProcessTouchInput(MultiTouchInput& aInput) { CompositorHitTestInvisibleToHit); mTouchBlockHitResult.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = mTouchBlockHitResult.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = mTouchBlockHitResult.HandledByRoot(); result.mStatus = mInputQueue->ReceiveInputEvent( mTouchBlockHitResult.mTargetApzc, TargetConfirmationFlags{mTouchBlockHitResult.mHitResult}, aInput, @@ -2138,7 +2138,7 @@ APZEventResult APZCTreeManager::ProcessTouchInputForScrollbarDrag( } mTouchBlockHitResult.mTargetApzc->GetGuid(&result.mTargetGuid); - result.mHandledByRootApzc = mTouchBlockHitResult.TargetIsConfirmedRoot(); + result.mHandledByRootApzc = mTouchBlockHitResult.HandledByRoot(); // Since the input was targeted at a scrollbar: // - The original touch event (which will be sent on to content) will @@ -3939,9 +3939,19 @@ APZCTreeManager::StickyPositionInfo::StickyPositionInfo( mStickyScrollRangeOuter = aNode->GetStickyScrollRangeOuter(); } -bool APZCTreeManager::HitTestResult::TargetIsConfirmedRoot() const { - return (mHitResult & CompositorHitTestDispatchToContent).isEmpty() && - mTargetApzc->IsRootContent(); +Maybe APZCTreeManager::HitTestResult::HandledByRoot() const { + if (!mTargetApzc->IsRootContent()) { + // If the initial target is not the root, this will definitely not be + // handled by the root. (The confirmed target is either the initial + // target, or a descendant.) + return Some(false); + } else if ((mHitResult & CompositorHitTestDispatchToContent).isEmpty()) { + // If the initial target is the root and we don't need to dispatch to + // content, the event will definitely be handled by the root. + return Some(true); + } + // Otherwise, we're not sure. + return Nothing(); } } // namespace layers diff --git a/gfx/layers/apz/src/APZCTreeManager.h b/gfx/layers/apz/src/APZCTreeManager.h index 2a1d07039f90..3e4c73e22598 100644 --- a/gfx/layers/apz/src/APZCTreeManager.h +++ b/gfx/layers/apz/src/APZCTreeManager.h @@ -558,7 +558,7 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge { // Make it move-only. HitTestResult(HitTestResult&&) = default; HitTestResult& operator=(HitTestResult&&) = default; - bool TargetIsConfirmedRoot() const; + Maybe HandledByRoot() const; }; /* Some helper functions to find an APZC given some identifying input. These diff --git a/gfx/layers/apz/src/APZInputBridge.cpp b/gfx/layers/apz/src/APZInputBridge.cpp index 7824691c8e3e..5b6f2a58ac9e 100644 --- a/gfx/layers/apz/src/APZInputBridge.cpp +++ b/gfx/layers/apz/src/APZInputBridge.cpp @@ -25,7 +25,6 @@ namespace layers { APZEventResult::APZEventResult() : mStatus(nsEventStatus_eIgnore), - mHandledByRootApzc(false), mInputBlockId(InputBlockState::NO_BLOCK_ID) {} static bool WillHandleMouseEvent(const WidgetMouseEventBase& aEvent) { diff --git a/gfx/layers/apz/test/gtest/TestEventRegions.cpp b/gfx/layers/apz/test/gtest/TestEventRegions.cpp index f8e79f4bb27f..c8972e965a83 100644 --- a/gfx/layers/apz/test/gtest/TestEventRegions.cpp +++ b/gfx/layers/apz/test/gtest/TestEventRegions.cpp @@ -338,11 +338,11 @@ TEST_F(APZEventRegionsTester, HandledByRootApzcFlag) { APZEventResult result = TouchDown(manager, ScreenIntPoint(50, 25), mcc->Time()); TouchUp(manager, ScreenIntPoint(50, 25), mcc->Time()); - EXPECT_TRUE(result.mHandledByRootApzc); + EXPECT_EQ(result.mHandledByRootApzc, Some(true)); // Tap the bottom half and check that we report that we're not // sure whether the event was handled by the root APZC. result = TouchDown(manager, ScreenIntPoint(50, 75), mcc->Time()); TouchUp(manager, ScreenIntPoint(50, 75), mcc->Time()); - EXPECT_FALSE(result.mHandledByRootApzc); + EXPECT_EQ(result.mHandledByRootApzc, Nothing()); } diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 2dda5f4cddec..e8fc22e83b5f 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -878,8 +878,9 @@ class nsWindow::NPZCSupport final WheelDeltaAdjustmentStrategy::eNone); APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input); - int32_t ret = result.mHandledByRootApzc ? INPUT_RESULT_HANDLED - : INPUT_RESULT_HANDLED_CONTENT; + int32_t ret = (result.mHandledByRootApzc == Some(true)) + ? INPUT_RESULT_HANDLED + : INPUT_RESULT_HANDLED_CONTENT; if (result.mStatus == nsEventStatus_eConsumeNoDefault) { return ret; @@ -1000,8 +1001,9 @@ class nsWindow::NPZCSupport final GetEventTimeStamp(aTime), GetModifiers(aMetaState)); APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input); - int32_t ret = result.mHandledByRootApzc ? INPUT_RESULT_HANDLED - : INPUT_RESULT_HANDLED_CONTENT; + int32_t ret = (result.mHandledByRootApzc == Some(true)) + ? INPUT_RESULT_HANDLED + : INPUT_RESULT_HANDLED_CONTENT; if (result.mStatus == nsEventStatus_eConsumeNoDefault) { return ret; @@ -1125,8 +1127,9 @@ class nsWindow::NPZCSupport final } APZEventResult result = controller->InputBridge()->ReceiveInputEvent(input); - int32_t ret = result.mHandledByRootApzc ? INPUT_RESULT_HANDLED - : INPUT_RESULT_HANDLED_CONTENT; + int32_t ret = (result.mHandledByRootApzc == Some(true)) + ? INPUT_RESULT_HANDLED + : INPUT_RESULT_HANDLED_CONTENT; if (result.mStatus == nsEventStatus_eConsumeNoDefault) { return ret;