tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e6e247e508eeb83950a0b8ae7d4a153be67f7ce0
parent 9453a4960ccd5a54f1791865ee524ac06edf1a98
Author: David Shin <dshin@mozilla.com>
Date:   Fri, 31 Oct 2025 02:19:04 +0000

Bug 1987963: Ensure that we can roll back to previous normal position when we give up on finding fallbacks. r=layout-anchor-positioning-reviewers,layout-reviewers,emilio

Rollback should not happen on "first try" of fallbacks (We have nothing
to fall back to). Modify the last successful fallback to track this.

Differential Revision: https://phabricator.services.mozilla.com/D269679

Diffstat:
Mlayout/generic/AbsoluteContainingBlock.cpp | 29+++++++++++++++++++++++++++++
Mtesting/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-006.html.ini | 3+--
Mtesting/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-007.html.ini | 3+++
Mtesting/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-008.html.ini | 3+++
Mtesting/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-009.html.ini | 1+
Mtesting/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-010.html.ini | 5++---
Mtesting/web-platform/meta/css/css-anchor-position/last-successful-change-fallbacks.html.ini | 3---
7 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp @@ -1095,6 +1095,7 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( }; Maybe<uint32_t> firstTryIndex; + Maybe<nsPoint> firstTryNormalPosition; // TODO(emilio): Right now fallback only applies to position-area, which only // makes a difference with a default anchor... Generalize it? if (aAnchorPosResolutionCache) { @@ -1413,6 +1414,9 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( const auto position = aKidFrame->GetPosition(); // Set initial scroll position. TODO(dshin, bug 1987962): Need // additional work for remembered scroll offset here. + if (!firstTryNormalPosition) { + firstTryNormalPosition = Some(position); + } aKidFrame->SetProperty(nsIFrame::NormalPositionProperty(), position); if (offset != nsPoint{}) { aKidFrame->SetPosition(position - offset); @@ -1464,6 +1468,31 @@ void AbsoluteContainingBlock::ReflowAbsoluteFrame( aStatus.Reset(); } while (true); + [&]() { + if (!isOverflowingCB || !aAnchorPosResolutionCache || + !firstTryNormalPosition) { + return; + } + // We gave up applying fallbacks. Recover previous values, if changed. + // Because we rolled back to first try data, our cache should be up-to-date. + const auto normalPosition = *firstTryNormalPosition; + const auto oldNormalPosition = aKidFrame->GetNormalPosition(); + if (normalPosition != oldNormalPosition) { + aKidFrame->SetProperty(nsIFrame::NormalPositionProperty(), + normalPosition); + } + const auto position = + normalPosition - + aAnchorPosResolutionCache->mReferenceData->mDefaultScrollShift; + const auto oldPosition = aKidFrame->GetPosition(); + if (position == oldPosition) { + return; + } + aKidFrame->SetPosition(position); + aKidFrame->UpdateOverflow(); + nsContainerFrame::PlaceFrameView(aKidFrame); + }(); + // If author asked for `position-visibility: no-overflow` and we overflow // `usedCB`, treat as "strongly hidden". aKidFrame->AddOrRemoveStateBits( diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-006.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-006.html.ini @@ -14,8 +14,7 @@ FAIL [Should use the last (fourth) position option initially] - expected: - if os == "android": FAIL + expected: FAIL [Should still use the last position option as long as it fits.] expected: diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-007.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-007.html.ini @@ -9,3 +9,6 @@ expected: if (os == "mac") and not debug: [PASS, FAIL] FAIL + + [Should use the last position option initially] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-008.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-008.html.ini @@ -9,3 +9,6 @@ expected: if (os == "mac") and not debug: [PASS, FAIL] FAIL + + [Should use the last fallback position initially] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-009.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-009.html.ini @@ -14,3 +14,4 @@ [Should use the last fallback position initially] expected: if os == "android": [PASS, FAIL] + FAIL diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-010.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-scroll-position-try-010.html.ini @@ -1,7 +1,7 @@ [anchor-scroll-position-try-010.html] [Should use the third fallback position with enough space right] expected: - if (os == "android"): [PASS, FAIL] + if os == "android": [PASS, FAIL] FAIL [Should use the second fallback position with enough space above] @@ -13,5 +13,4 @@ FAIL [Should use the last fallback position initially] - expected: - if (os == "android"): FAIL + expected: FAIL diff --git a/testing/web-platform/meta/css/css-anchor-position/last-successful-change-fallbacks.html.ini b/testing/web-platform/meta/css/css-anchor-position/last-successful-change-fallbacks.html.ini @@ -1,6 +1,3 @@ [last-successful-change-fallbacks.html] [No successful position, keep flip-block] expected: FAIL - - [No successful position, last successful invalidated by position-try-fallbacks change] - expected: FAIL