From 83ab6a777ba163a72fe343c41bafbc3b53817f3d Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Mon, 4 Jul 2022 18:14:59 +0000 Subject: [PATCH] Bug 1753019 - Adjust sticky position elements for the dynamic toolbar. r=botond Use the animation id from the stacking context to find the hit-testing tree node for hit tests of elements that are sticky positioned. Then use this hit-testing tree node reference to apply APZ transforms if the sticky positioned element is stuck to the root content. Differential Revision: https://phabricator.services.mozilla.com/D150047 --- gfx/layers/apz/src/APZCTreeManager.cpp | 19 +++++++++++++++++++ gfx/layers/apz/src/WRHitTester.cpp | 6 ++++-- layout/painting/nsDisplayList.cpp | 11 +++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index e68b88bb74d3..a1212e43e2c2 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -2039,6 +2039,17 @@ void APZCTreeManager::ProcessTouchInput(InputHandlingState& aState, touchData.mScreenPoint -= RoundedToInt(apz::ComputeFixedMarginsOffset( GetCompositorFixedLayerMargins(lock), mTouchBlockHitResult.mFixedPosSides, mGeckoFixedLayerMargins)); + } else if (mTouchBlockHitResult.mNode && + mTouchBlockHitResult.mNode->GetStickyPositionAnimationId()) { + SideBits sideBits = SideBits::eNone; + { + RecursiveMutexAutoLock lock(mTreeLock); + sideBits = + SidesStuckToRootContent(mTouchBlockHitResult.mNode.Get(lock)); + } + MutexAutoLock lock(mMapLock); + touchData.mScreenPoint -= RoundedToInt(apz::ComputeFixedMarginsOffset( + GetCompositorFixedLayerMargins(lock), sideBits, ScreenMargin())); } } } @@ -3239,6 +3250,14 @@ Maybe APZCTreeManager::ConvertToGecko( *geckoPoint -= RoundedToInt(apz::ComputeFixedMarginsOffset( GetCompositorFixedLayerMargins(mapLock), mTouchBlockHitResult.mFixedPosSides, mGeckoFixedLayerMargins)); + } else if (mTouchBlockHitResult.mNode && + mTouchBlockHitResult.mNode->GetStickyPositionAnimationId()) { + SideBits sideBits = + SidesStuckToRootContent(mTouchBlockHitResult.mNode.Get(lock)); + + MutexAutoLock mapLock(mMapLock); + *geckoPoint -= RoundedToInt(apz::ComputeFixedMarginsOffset( + GetCompositorFixedLayerMargins(mapLock), sideBits, ScreenMargin())); } } return geckoPoint; diff --git a/gfx/layers/apz/src/WRHitTester.cpp b/gfx/layers/apz/src/WRHitTester.cpp index 13401c189f82..5973f3a24da4 100644 --- a/gfx/layers/apz/src/WRHitTester.cpp +++ b/gfx/layers/apz/src/WRHitTester.cpp @@ -207,13 +207,15 @@ IAPZHitTester::HitTestResult WRHitTester::GetAPZCAtPoint( positionedNode = BreadthFirstSearch( GetRootNode(), [&](HitTestingTreeNode* aNode) { - return aNode->GetFixedPositionAnimationId() == animationId; + return (aNode->GetFixedPositionAnimationId() == animationId || + aNode->GetStickyPositionAnimationId() == animationId); }); if (positionedNode) { MOZ_ASSERT(positionedNode->GetLayersId() == chosenResult->mLayersId, "Found node layers id does not match the hit result"); - MOZ_ASSERT(positionedNode->GetFixedPositionAnimationId().isSome(), + MOZ_ASSERT((positionedNode->GetFixedPositionAnimationId().isSome() || + positionedNode->GetStickyPositionAnimationId().isSome()), "A a matching fixed/sticky position node should be found"); InitializeHitTestingTreeNodeAutoLock(hit.mNode, aProofOfTreeLock, positionedNode); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index cf142c5d4a82..16d2861cbd54 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -5250,7 +5250,8 @@ bool nsDisplayOwnLayer::CreateWebRenderCommands( (IsScrollThumbLayer() || IsZoomingLayer() || (IsFixedPositionLayer() && ShouldFixedAndStickyContentGetAnimationIds()) || - (IsStickyPositionLayer() && HasDynamicToolbar()) || + (IsStickyPositionLayer() && + ShouldFixedAndStickyContentGetAnimationIds()) || (IsRootScrollbarContainer() && HasDynamicToolbar())); if (needsProp) { @@ -5279,7 +5280,8 @@ bool nsDisplayOwnLayer::CreateWebRenderCommands( if (IsZoomingLayer() || ((IsFixedPositionLayer() && ShouldFixedAndStickyContentGetAnimationIds()) || - (IsStickyPositionLayer() && HasDynamicToolbar()) || + (IsStickyPositionLayer() && + ShouldFixedAndStickyContentGetAnimationIds()) || (IsRootScrollbarContainer() && HasDynamicToolbar()))) { params.is_2d_scale_translation = true; params.should_snap = true; @@ -5299,7 +5301,8 @@ bool nsDisplayOwnLayer::UpdateScrollData(WebRenderScrollData* aData, (IsScrollThumbLayer() || IsScrollbarContainer() || IsZoomingLayer() || (IsFixedPositionLayer() && ShouldFixedAndStickyContentGetAnimationIds()) || - (IsStickyPositionLayer() && HasDynamicToolbar())); + (IsStickyPositionLayer() && + ShouldFixedAndStickyContentGetAnimationIds())); if (!isRelevantToApz) { return false; @@ -5319,7 +5322,7 @@ bool nsDisplayOwnLayer::UpdateScrollData(WebRenderScrollData* aData, return true; } - if (IsStickyPositionLayer() && HasDynamicToolbar()) { + if (IsStickyPositionLayer() && ShouldFixedAndStickyContentGetAnimationIds()) { aLayerData->SetStickyPositionAnimationId(mWrAnimationId); return true; }