Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 20ba8be4af52496e49284f7b6bd78fb5d47fc2af
      
https://github.com/WebKit/WebKit/commit/20ba8be4af52496e49284f7b6bd78fb5d47fc2af
  Author: Kiet Ho <kiet...@apple.com>
  Date:   2025-09-17 (Wed, 17 Sep 2025)

  Changed paths:
    M LayoutTests/TestExpectations
    M Source/WebCore/style/AnchorPositionEvaluator.cpp

  Log Message:
  -----------
  [css-anchor-position-1] New default anchor should restart anchor maching to 
pick up the new anchor
rdar://159899182
https://bugs.webkit.org/show_bug.cgi?id=298422

Reviewed by Antti Koivisto.

The default anchor of an anchor-positioned element can change after it has 
reached
the Positioned stage. Given an anchor-positioned element that initially defaults
to anchor --a, and has a position option that defaults to anchor --b:
* The element is first fully resolved (unti Positioned stage) with the base 
style
* The base style causes it to overflow, so it tries the position option
* Now the element defaults to anchor --b, but since stage == Positioned,
  we don't restart the anchor maching process to pick up anchor --b
* Result: the element can't find anchor --b and can't position relative to it.

This is demonstrated in test
imported/w3c/web-platform-tests/css/css-anchor-position/position-try-switch-to-fixed-anchor.html
Fix this by restarting the matching process if we found a new default anchor.

This exposes a bug where an anchor-positioned element can get stuck in
ResolveAnchorFunction stage indefinitely. Take the previous scenario:
* When we find a new default anchor, we set the stage to FindAnchors to restart
  the anchor matching process
* After a layout round, the stage changes to ResolveAnchorFunctions (because the
  element uses anchor function)
* An element can only move from ResolveAnchorFunctions to Resolved if it
  evaluates an anchor function, which moves the stage to Resolved. However,
  we're trying position options, and the position option styles are already
  evaluated ahead of time. So we don't re-evaluate the anchor functions, we
  simply apply the pre-generated style. This means the stage don't have the
  opportunity to move to Resolved.
* The element is then stuck in ResolveAnchorFunctions, because
  AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout
  doesn't move ResolveAnchorFunctions to other stages.

Fix this by changing
AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout
to move elements in ResolveAnchorFunctions stage to Positioned.

Test: 
LayoutTests/imported/w3c/web-platform-tests/css/css-anchor-position/position-try-switch-to-fixed-anchor.html

* LayoutTests/TestExpectations:
* Source/WebCore/style/AnchorPositionEvaluator.cpp:
(WebCore::Style::AnchorPositionEvaluator::findAnchorForAnchorFunctionAndAttemptResolution):
(WebCore::Style::AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout):
(WebCore::Style::AnchorPositionEvaluator::updateAnchorPositionedStateForDefaultAnchorAndPositionVisibility):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to