Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: ff1e94f74356e1ce4245e2a157e1c3e6a2889545
https://github.com/WebKit/WebKit/commit/ff1e94f74356e1ce4245e2a157e1c3e6a2889545
Author: Ahmad Saleem <[email protected]>
Date: 2026-07-31 (Fri, 31 Jul 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/snap-to-different-targets-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-to-combination-of-two-elements-2-expected.txt
M Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp
M Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h
M Source/WebCore/platform/ScrollSnapAnimatorState.cpp
M Source/WebCore/platform/ScrollSnapAnimatorState.h
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
Log Message:
-----------
[CSS Scroll Snap] Re-snap should prefer the block-axis box when the two axes
conflict
https://bugs.webkit.org/show_bug.cgi?id=320406
rdar://183366125
Reviewed by Simon Fraser.
Re-snapping after a layout change selects a snap target per axis
independently. When the block-axis box and inline-axis box differ and
cannot both be snapped (snapping to one leaves the other outside the
snapport), css-scroll-snap requires resolving to a single box: "it must
prefer the focused box, followed by the targeted box, followed by the
block axis if neither box is focused or targeted" [1]. WebKit kept the
two independently-selected boxes, so the scroller followed neither.
Detect the conflict in resnapAfterLayout(): form the combined snap
position (the inline box's offset in one axis, the block box's offset in
the other) and check whether both areas still intersect the snapport
there. If they do, both boxes can be snapped and per-axis selection
stands. If they do not, collapse both axes onto one box, preferring
focused, then targeted, then the block-axis box. Which physical axis is
the block axis depends on the snap container's writing mode, so plumb
scrollerHasVerticalWritingMode onto LayoutScrollSnapOffsetsInfo (computed
where offsets are built and serialized to the scrolling thread).
Resolving the conflict needs a box's snap area as well as its offset, and
it needs the focused/targeted preference over a restricted set of boxes,
so two lookups are factored out for it: snapOffsetAndAreaIndicesForNode()
finds a box's offset and its own area in one pass over the offset's areas
(snapOffsetIndexForNode() now projects it), and flaggedNodeForAxis() finds
an axis's focused or targeted box under a caller-supplied filter, shared
with focusedOrTargetedNodeForAxis() and focusedOrTargetedBox().
[1] https://drafts.csswg.org/css-scroll-snap/#re-snap
*
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/snap-to-different-targets-expected.txt:
Progression
*
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-to-combination-of-two-elements-2-expected.txt:
Rebaseline (matches Chrome)
* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:
(WebCore::updateSnapOffsetsForScrollableArea):
(WebCore::convertOffsetInfo):
* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h:
(WebCore::ScrollSnapOffsetsInfo::blockAxis const):
(WebCore::ScrollSnapOffsetsInfo::isEqual const):
* Source/WebCore/platform/ScrollSnapAnimatorState.cpp:
(WebCore::ScrollSnapAnimatorState::snapOffsetAndAreaIndicesForNode const):
(WebCore::ScrollSnapAnimatorState::snapOffsetIndexForNode const):
(WebCore::ScrollSnapAnimatorState::flaggedNodeForAxis const):
(WebCore::ScrollSnapAnimatorState::focusedOrTargetedNodeForAxis const):
(WebCore::ScrollSnapAnimatorState::focusedOrTargetedBox const):
(WebCore::ScrollSnapAnimatorState::snapAreaAndOffsetForNode const):
(WebCore::ScrollSnapAnimatorState::resolvePreferredBoxForAxisConflict const):
(WebCore::ScrollSnapAnimatorState::resnapAfterLayout):
* Source/WebCore/platform/ScrollSnapAnimatorState.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
Canonical link: https://commits.webkit.org/318343@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications