Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 4af6fb574fa397319707a1221b9767526ea03722
https://github.com/WebKit/WebKit/commit/4af6fb574fa397319707a1221b9767526ea03722
Author: Alan Baradlay <[email protected]>
Date: 2026-07-23 (Thu, 23 Jul 2026)
Changed paths:
M Source/WebCore/Headers.cmake
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h
A Source/WebCore/layout/formattingContexts/flex/FlexLayoutState.h
M Source/WebCore/rendering/RenderFlexibleBox.cpp
M Source/WebCore/rendering/RenderFlexibleBox.h
Log Message:
-----------
[cleanup] Replace RenderFlexibleBox's per-layout phase bools with a single
monotonic FlexLayoutState
https://bugs.webkit.org/show_bug.cgi?id=320044
Reviewed by Antti Koivisto.
RenderFlexibleBox tracked where it was in the flex layout algorithm with five
independent booleans -- m_inLayout, m_afterMainAxisItemSizing,
m_afterCrossAxisItemSizing, m_inPostFlexUpdateScrollbarLayout and
m_isComputingFlexBaseSizes -- each flipped on and off by a SetForScope object
that
FlexFormattingContext reached through the container
(scopedComputingFlexBaseSizes,
scopedAfterMainAxisItemSizing, scopedAfterCrossAxisItemSizing). The
percentage-resolution cascade in canUseFlexItemForPercentageResolution then had
to
test them in a hand-maintained priority order.
Replace all five with a single FlexLayoutState that holds one monotonically
advancing Phase enum. m_flexLayoutState is a std::optional the container owns,
engaged via SetForScope only while a layout is running (std::nullopt otherwise,
so
there is no separate "in layout" bool). FlexFormattingContext::layout() advances
the phase at the entry of each pipeline step it runs, and readers ask either
"at or
past phase X" (phase() >= X) or "in phase X" (phase() == X):
PreparingFlexItems -> ComputingFlexBaseSizes -> CollectingLines ->
ResolvingFlexibleLengths -> MainAxisItemSizing -> CrossSizing ->
MainAxisAlignment -> CrossAxisItemSizing -> CrossAxisAlignment ->
PostFlexScrollbarLayout
This is behavior-preserving. The state is only consulted while a flex item is
being laid out -- flex base size computation, the main-axis item layout pass,
the
cross-axis stretch relayout, and the post-flex scrollbar relayout -- and in each
of those windows the phase resolves to the same answer the old scoped bool gave.
The phase does linger into the surrounding no-layout regions (advancing is
one-way), but no read observes it there, so the coarser lifetime is not
observable.
Because setPhase only advances, the main-axis item layout is split so the phase
is
owned in exactly one place: layoutFlexItems() is the MainAxisItemSizing pipeline
step and the sole phase setter, while the reusable per-item loop
layoutFlexItemsWithMainSizes() sets no phase. The multiline-column re-run in
distributeMainAxisFreeSpaceForMultilineColumnIfNeeded() calls the latter, so it
relayouts within whatever phase main alignment left it in rather than trying
(and
failing, since advancing is one-way) to rewind to MainAxisItemSizing.
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/layout/formattingContexts/flex/FlexLayoutState.h: Added.
(WebCore::FlexLayoutState::phase const):
(WebCore::FlexLayoutState::setPhase):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::FlexFormattingContext::layout):
(WebCore::FlexFormattingContext::computeFlexBaseAndHypotheticalMainSizes):
(WebCore::FlexFormattingContext::computeFlexLines):
(WebCore::FlexFormattingContext::computeMainSizeForFlexItems):
(WebCore::FlexFormattingContext::layoutFlexItems):
(WebCore::FlexFormattingContext::layoutFlexItemsWithMainSizes):
(WebCore::FlexFormattingContext::hypotheticalCrossSizeForFlexItems):
(WebCore::FlexFormattingContext::distributeMainAxisFreeSpaceForMultilineColumnIfNeeded):
(WebCore::FlexFormattingContext::handleMainAxisAlignment):
(WebCore::FlexFormattingContext::computeCrossSizeForFlexItems):
(WebCore::FlexFormattingContext::handleCrossAxisAlignmentForFlexItems):
(WebCore::FlexFormattingContext::flexBaseSizeForFlexItem):
(WebCore::FlexFormattingContext::applyStretchAlignmentToFlexItem):
(WebCore::FlexFormattingContext::flexLayoutState const):
* Source/WebCore/rendering/RenderFlexibleBox.h:
(WebCore::RenderFlexibleBox::isComputingFlexBaseSizes const):
(WebCore::RenderFlexibleBox::isInCrossAxisStretchLayout const):
(WebCore::RenderFlexibleBox::flexLayoutState):
(WebCore::RenderFlexibleBox::scopedComputingFlexBaseSizes): Deleted.
(WebCore::RenderFlexibleBox::scopedAfterMainAxisItemSizing): Deleted.
(WebCore::RenderFlexibleBox::scopedAfterCrossAxisItemSizing): Deleted.
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutBlock):
(WebCore::RenderFlexibleBox::canUseFlexItemForPercentageResolution):
(WebCore::RenderFlexibleBox::layoutFlexItemWithMainSize):
(WebCore::RenderFlexibleBox::canComputePercentageFlexBasis):
Canonical link: https://commits.webkit.org/317788@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications