Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 689b91ff1913069d73cf1700b733c14e41e05c25
      
https://github.com/WebKit/WebKit/commit/689b91ff1913069d73cf1700b733c14e41e05c25
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-06-26 (Fri, 26 Jun 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-main-frame-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-positioned-expected.txt
    M LayoutTests/platform/mac/TestExpectations
    M Source/WebCore/page/LocalFrameView.cpp
    M Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp
    M Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h
    M Source/WebCore/platform/ScrollSnapAnimatorState.cpp
    M Source/WebCore/rendering/RenderLayerScrollableArea.cpp
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in

  Log Message:
  -----------
  [CSS Scroll Snap] Re-snap does not prefer the focused or fragment-targeted 
snap area among multiple aligned snap targets
https://bugs.webkit.org/show_bug.cgi?id=317481
rdar://180108825

Reviewed by Simon Fraser.

When several snap areas resolve to the same snap offset (an aligned "tie"), the
re-snap performed after a layout change must follow the highest-priority box per
https://drafts.csswg.org/css-scroll-snap-1/#re-snap: a focused box, then a
fragment-targeted (:target) box, then the box first in tree order.

WebCore only tracked focused boxes, and only re-chose a target when the tie
collapsed to a single box. So a fragment-targeted box was never preferred, and
when nothing was focused the choice fell back to an arbitrary hash-set order.

Track the document's fragment-targeted element through the snap-offset pipeline,
mirroring the existing focused-element handling:

- Add SnapOffset::isTarget, populated from Document::cssTarget(), and serialize
  it so the async scrolling tree observes it as well.
- Accumulate isFocused/isTarget across every area that shares an offset (not
  just the first one added), and point the offset's snapTargetID at the
  highest-priority box (focused, then targeted, then first added) so re-snapping
  resolves to it.
- During re-snap, when the scroller was snapped to multiple aligned boxes, 
follow
  a focused or targeted box to its post-layout offset even if other boxes remain
  aligned at the old offset. With no such explicit preference, behavior is
  unchanged: a target is only re-chosen once the tie collapses to a single box.

* LayoutTests/platform/mac/TestExpectations: Unskip now passing test
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-expected.txt:
 Progressions
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-main-frame-expected.txt:
 Ditto
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/snap-after-relayout/multiple-aligned-targets/prefer-targeted-element-positioned-expected.txt:
 Ditto
* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::LocalFrameView::updateSnapOffsets): Pass the fragment-targeted element
* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:
(WebCore::updateSnapOffsetsForScrollableArea): Accept the targeted element;
accumulate isFocused/isTarget and choose the representative snapTargetID,
preferring focused over targeted over the first box in tree order.
(WebCore::convertOffsetInfo):
* Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h:
(WebCore::operator<<):
* Source/WebCore/platform/ScrollSnapAnimatorState.cpp:
(WebCore::ScrollSnapAnimatorState::preserveCurrentTargetForAxis):
(WebCore::preferredSnapTarget): Return the focused-then-targeted box, if any.
(WebCore::chooseBoxToResnapTo): Use preferredSnapTarget before the fallback.
(WebCore::ScrollSnapAnimatorState::resnapAfterLayout): Follow a preferred box
even while peers remain aligned.
* Source/WebCore/rendering/RenderLayerScrollableArea.cpp:
(WebCore::RenderLayerScrollableArea::updateSnapOffsets): Pass the 
fragment-targeted element.
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:

Canonical link: https://commits.webkit.org/315880@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to