Skip to content

[List Marker] Collapse anonymous blocks for outside marker when blockification prevents line-box parenting#60215

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
yulunwu2:radar_165933903
Mar 14, 2026
Merged

[List Marker] Collapse anonymous blocks for outside marker when blockification prevents line-box parenting#60215
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
yulunwu2:radar_165933903

Conversation

@yulunwu2
Copy link
Contributor

@yulunwu2 yulunwu2 commented Mar 9, 2026

376d3ef

[List Marker] Collapse anonymous blocks for outside marker when blockification prevents line-box parenting
https://bugs.webkit.org/show_bug.cgi?id=309925
<rdar://165933903>

Reviewed by Alan Baradlay.

findParentOfEmptyOrFirstLineBox sometimes fails to find a suitable line-box
parent when a list item contains a flex or grid container because flex/grid
containers blockify inline content like <svg> and <img>. In this case, we
fall back to creating an anonymous block to parent the list marker. However,
this causes layout issues because the anonymous block's inherited line height
pushes the visible content down (and no longer next to the list marker).

This fixes the issue by detecting parenting failure due to blockification
and flagging the marker to collapse its parent block.

* LayoutTests/fast/lists/list-marker-outside-flex-collapse-anonymous-block-expected.html: Added.
* LayoutTests/fast/lists/list-marker-outside-flex-collapse-anonymous-block.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineQuirks.cpp:
(WebCore::Layout::InlineQuirks::shouldCollapseLineBoxHeight const):
* Source/WebCore/layout/integration/LayoutIntegrationBoxTreeUpdater.cpp:
(WebCore::LayoutIntegration::updateListMarkerAttributes):
(WebCore::LayoutIntegration::BoxTreeUpdater::createLayoutBox):
* Source/WebCore/layout/layouttree/LayoutElementBox.h:
(WebCore::Layout::ElementBox::shouldCollapseAnonymousBlockParentForListMarker const):
* Source/WebCore/rendering/RenderListMarker.h:
* Source/WebCore/rendering/updating/RenderTreeBuilderList.cpp:
(WebCore::findParentOfEmptyOrFirstLineBox):
(WebCore::parentCandidateForMarker):
(WebCore::RenderTreeBuilder::List::updateItemMarker):

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

53a8ef8

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@yulunwu2 yulunwu2 self-assigned this Mar 9, 2026
@yulunwu2 yulunwu2 added the Layout and Rendering For bugs with layout and rendering of Web pages. label Mar 9, 2026
@yulunwu2 yulunwu2 requested a review from alanbaradlay March 9, 2026 22:05
@webkit-ews-buildbot
Copy link
Collaborator

macOS Safer C++ Build #85184 (a0907e7)

❌ Found 1 failing file with 2 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 11, 2026
@webkit-ews-buildbot
Copy link
Collaborator

iOS Safer C++ Build #3416 (a0907e7)

❌ Found 1 failing file with 2 issues. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

if (rootBox.isAnonymous() && lineContent[0].isListMarkerOutside()) {
// When an outside marker ends up in an anonymous block because blockification (e.g., by a flex/grid container)
// prevented finding a line box parent, collapse the line box so it doesn't inflate the list item.
auto* markerRenderer = dynamicDowncast<RenderListMarker>(lineContent[0].layoutBox().rendererForIntegration());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try not to access renderers from inside IFC -well except the integration layer- but transfer such states from renderers to layout boxes while building the tree. ElementBox already has examples like this see setListMarkerLayoutBounds. I would also fold this logic under if (lineContent[0].isListMarkerOutside()... -few lines above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the review!

@yulunwu2 yulunwu2 removed the merging-blocked Applied to prevent a change from being merged label Mar 11, 2026
@yulunwu2 yulunwu2 requested a review from alanbaradlay March 11, 2026 22:00
@yulunwu2 yulunwu2 changed the title [List Marker] Collapse anonymous block height for outside marker when blockification prevents line-box parenting [List Marker] Collapse anonymous block height for outside marker when a block child prevents line-box parenting Mar 13, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@yulunwu2 yulunwu2 removed the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@yulunwu2 yulunwu2 changed the title [List Marker] Collapse anonymous block height for outside marker when a block child prevents line-box parenting [List Marker] Collapse anonymous block height for outside marker when blockification prevents line-box parenting Mar 13, 2026
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@yulunwu2 yulunwu2 removed the merging-blocked Applied to prevent a change from being merged label Mar 13, 2026
@yulunwu2 yulunwu2 changed the title [List Marker] Collapse anonymous block height for outside marker when blockification prevents line-box parenting [List Marker] Collapse anonymous blocks for outside marker when blockification prevents line-box parenting Mar 13, 2026
@yulunwu2 yulunwu2 requested a review from alanbaradlay March 13, 2026 23:38
if (!lineContent[0].isListMarkerOutside()) {
ASSERT(lineContent[0].isListMarkerInside());
auto& marker = lineContent[0];
auto* markerBox = dynamicDowncast<Layout::ElementBox>(lineContent[0].layoutBox());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marker.layoutBox()

@yulunwu2 yulunwu2 added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Mar 14, 2026
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Mar 14, 2026
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #86611.

…ification prevents line-box parenting

https://bugs.webkit.org/show_bug.cgi?id=309925
<rdar://165933903>

Reviewed by Alan Baradlay.

findParentOfEmptyOrFirstLineBox sometimes fails to find a suitable line-box
parent when a list item contains a flex or grid container because flex/grid
containers blockify inline content like <svg> and <img>. In this case, we
fall back to creating an anonymous block to parent the list marker. However,
this causes layout issues because the anonymous block's inherited line height
pushes the visible content down (and no longer next to the list marker).

This fixes the issue by detecting parenting failure due to blockification
and flagging the marker to collapse its parent block.

* LayoutTests/fast/lists/list-marker-outside-flex-collapse-anonymous-block-expected.html: Added.
* LayoutTests/fast/lists/list-marker-outside-flex-collapse-anonymous-block.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineQuirks.cpp:
(WebCore::Layout::InlineQuirks::shouldCollapseLineBoxHeight const):
* Source/WebCore/layout/integration/LayoutIntegrationBoxTreeUpdater.cpp:
(WebCore::LayoutIntegration::updateListMarkerAttributes):
(WebCore::LayoutIntegration::BoxTreeUpdater::createLayoutBox):
* Source/WebCore/layout/layouttree/LayoutElementBox.h:
(WebCore::Layout::ElementBox::shouldCollapseAnonymousBlockParentForListMarker const):
* Source/WebCore/rendering/RenderListMarker.h:
* Source/WebCore/rendering/updating/RenderTreeBuilderList.cpp:
(WebCore::findParentOfEmptyOrFirstLineBox):
(WebCore::parentCandidateForMarker):
(WebCore::RenderTreeBuilder::List::updateItemMarker):

Canonical link: https://commits.webkit.org/309272@main
@webkit-commit-queue
Copy link
Collaborator

Committed 309272@main (376d3ef): https://commits.webkit.org/309272@main

Reviewed commits have been landed. Closing PR #60215 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 376d3ef into WebKit:main Mar 14, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Layout and Rendering For bugs with layout and rendering of Web pages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants