From 1c40fa8a531e759d9f7c74e4fec5a1c624e258eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jul 2024 22:45:49 +0000 Subject: [PATCH] Bug 1905426 - Refine zero-scroll-offset scroll anchoring heuristic to match blink. r=hiro, a=dmeehan See link in the comment. We were checking both offsets, but blink only checks one. In this case, the page has a table with `overflow-x: auto` and `overflow-y: hidden`. They implement a custom virtual scrolling on the vertical axis, and scroll-anchoring interacts poorly with it. Adapt zero-scroll-offset.html to test for this. Differential Revision: https://phabricator.services.mozilla.com/D217201 --- layout/generic/ScrollAnchorContainer.cpp | 11 +++- ...ffset.html => zero-scroll-offset-001.html} | 0 .../zero-scroll-offset-002.html | 56 +++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) rename testing/web-platform/tests/css/css-scroll-anchoring/{zero-scroll-offset.html => zero-scroll-offset-001.html} (100%) create mode 100644 testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-002.html diff --git a/layout/generic/ScrollAnchorContainer.cpp b/layout/generic/ScrollAnchorContainer.cpp index 6855abfd85fd..6bf88a8b6063 100644 --- a/layout/generic/ScrollAnchorContainer.cpp +++ b/layout/generic/ScrollAnchorContainer.cpp @@ -230,11 +230,16 @@ bool ScrollAnchorContainer::CanMaintainAnchor() const { return false; } - // Or if the scroll frame has not been scrolled from the logical origin. This - // is not in the specification [1], but Blink does this. + // Or if the scroll frame has not been scrolled from the logical origin of the + // block axis. This is not in the specification [1], but Blink does this [2]. // // [1] https://github.com/w3c/csswg-drafts/issues/3319 - if (Frame()->GetLogicalScrollPosition() == nsPoint()) { + // [2] + // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/layout/scroll_anchor.cc;l=551;drc=f1eab630d343484302ee9bea91f515f1a1dd0891 + const nsPoint pos = Frame()->GetLogicalScrollPosition(); + const nscoord blockOffset = + Frame()->GetWritingMode().IsVertical() ? pos.x : pos.y; + if (blockOffset == 0) { return false; } diff --git a/testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset.html b/testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-001.html similarity index 100% rename from testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset.html rename to testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-001.html diff --git a/testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-002.html b/testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-002.html new file mode 100644 index 000000000000..b1da4560c6d8 --- /dev/null +++ b/testing/web-platform/tests/css/css-scroll-anchoring/zero-scroll-offset-002.html @@ -0,0 +1,56 @@ + + + Test that scroll anchoring is suppressed when scroll offset is zero in the block axis, even if the inline axis scroll offset isn't. + + + + + + + + + +
abc
+