1[cleanup] Replace RenderFlexibleBox's per-layout phase bools with a single monotonic FlexLayoutState
2https://bugs.webkit.org/show_bug.cgi?id=320044
3
4Reviewed by NOBODY (OOPS!).
5
6RenderFlexibleBox tracked where it was in the flex layout algorithm with five
7independent booleans -- m_inLayout, m_afterMainAxisItemSizing,
8m_afterCrossAxisItemSizing, m_inPostFlexUpdateScrollbarLayout and
9m_isComputingFlexBaseSizes -- each flipped on and off by a SetForScope object that
10FlexFormattingContext reached through the container (scopedComputingFlexBaseSizes,
11scopedAfterMainAxisItemSizing, scopedAfterCrossAxisItemSizing). The
12percentage-resolution cascade in canUseFlexItemForPercentageResolution then had to
13test them in a hand-maintained priority order.
14
15Replace all five with a single FlexLayoutState that holds one monotonically
16advancing Phase enum. m_flexLayoutState is a std::optional the container owns,
17engaged via SetForScope only while a layout is running (std::nullopt otherwise, so
18there is no separate "in layout" bool). FlexFormattingContext::layout() advances
19the phase at the entry of each pipeline step it runs, and readers ask either "at or
20past phase X" (phase() >= X) or "in phase X" (phase() == X):
21
22 PreparingFlexItems -> ComputingFlexBaseSizes -> CollectingLines ->
23 ResolvingFlexibleLengths -> MainAxisItemSizing -> CrossSizing ->
24 MainAxisAlignment -> CrossAxisItemSizing -> CrossAxisAlignment ->
25 PostFlexScrollbarLayout
26
27This is behavior-preserving. The state is only consulted while a flex item is
28being laid out -- flex base size computation, the main-axis item layout pass, the
29cross-axis stretch relayout, and the post-flex scrollbar relayout -- and in each
30of those windows the phase resolves to the same answer the old scoped bool gave.
31The phase does linger into the surrounding no-layout regions (advancing is
32one-way), but no read observes it there, so the coarser lifetime is not
33observable.
34
35Because setPhase only advances, the main-axis item layout is split so the phase is
36owned in exactly one place: layoutFlexItems() is the MainAxisItemSizing pipeline
37step and the sole phase setter, while the reusable per-item loop
38layoutFlexItemsWithMainSizes() sets no phase. The multiline-column re-run in
39distributeMainAxisFreeSpaceForMultilineColumnIfNeeded() calls the latter, so it
40relayouts within whatever phase main alignment left it in rather than trying (and
41failing, since advancing is one-way) to rewind to MainAxisItemSizing.
42
43* Source/WebCore/Headers.cmake:
44* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
45* Source/WebCore/layout/formattingContexts/flex/FlexLayoutState.h: Added.
46(WebCore::FlexLayoutState::phase const):
47(WebCore::FlexLayoutState::setPhase):
48* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
49* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
50(WebCore::FlexFormattingContext::layout):
51(WebCore::FlexFormattingContext::computeFlexBaseAndHypotheticalMainSizes):
52(WebCore::FlexFormattingContext::computeFlexLines):
53(WebCore::FlexFormattingContext::computeMainSizeForFlexItems):
54(WebCore::FlexFormattingContext::layoutFlexItems):
55(WebCore::FlexFormattingContext::layoutFlexItemsWithMainSizes):
56(WebCore::FlexFormattingContext::hypotheticalCrossSizeForFlexItems):
57(WebCore::FlexFormattingContext::distributeMainAxisFreeSpaceForMultilineColumnIfNeeded):
58(WebCore::FlexFormattingContext::handleMainAxisAlignment):
59(WebCore::FlexFormattingContext::computeCrossSizeForFlexItems):
60(WebCore::FlexFormattingContext::handleCrossAxisAlignmentForFlexItems):
61(WebCore::FlexFormattingContext::flexBaseSizeForFlexItem):
62(WebCore::FlexFormattingContext::applyStretchAlignmentToFlexItem):
63(WebCore::FlexFormattingContext::flexLayoutState const):
64* Source/WebCore/rendering/RenderFlexibleBox.h:
65(WebCore::RenderFlexibleBox::isComputingFlexBaseSizes const):
66(WebCore::RenderFlexibleBox::isInCrossAxisStretchLayout const):
67(WebCore::RenderFlexibleBox::flexLayoutState):
68(WebCore::RenderFlexibleBox::scopedComputingFlexBaseSizes): Deleted.
69(WebCore::RenderFlexibleBox::scopedAfterMainAxisItemSizing): Deleted.
70(WebCore::RenderFlexibleBox::scopedAfterCrossAxisItemSizing): Deleted.
71* Source/WebCore/rendering/RenderFlexibleBox.cpp:
72(WebCore::RenderFlexibleBox::layoutBlock):
73(WebCore::RenderFlexibleBox::canUseFlexItemForPercentageResolution):
74(WebCore::RenderFlexibleBox::layoutFlexItemWithMainSize):
75(WebCore::RenderFlexibleBox::canComputePercentageFlexBasis):