Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5de9040a20f5aec2a2fdb2ae097bcf67561ab82c
      
https://github.com/WebKit/WebKit/commit/5de9040a20f5aec2a2fdb2ae097bcf67561ab82c
  Author: Alan Baradlay <[email protected]>
  Date:   2026-07-27 (Mon, 27 Jul 2026)

  Changed paths:
    M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
    M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h
    M Source/WebCore/layout/formattingContexts/flex/FlexLayoutState.h
    M Source/WebCore/layout/integration/flex/FlexIntegrationUtils.cpp
    M Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp
    M Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h
    M Source/WebCore/rendering/RenderBlock.cpp
    M Source/WebCore/rendering/RenderFlexibleBox.cpp

  Log Message:
  -----------
  [cleanup] Have the flex algorithm own which margins it trimmed
https://bugs.webkit.org/show_bug.cgi?id=320370

Reviewed by Antti Koivisto.

Recording a trimmed margin went out through the renderer and back: the 
formatting context called
FlexIntegrationUtils::trimCrossAxisMarginStart, which called an 
addItemOnFirstFlexLine forwarder next to
it, which reached FlexLayout through RenderFlexibleBox::flexLayout() to reach a 
set FlexLayout held. Five
hops to add an item to a set, leaving the integration layer twice on the way.

Put the sets on FlexLayoutState, which the integration already holds a 
reference to for the duration of
the algorithm, and the recording becomes 
flexLayoutState().addItemOnFirstFlexLine(...). FlexLayout keeps
what the algorithm produced -- in FlexFormattingContext::Result, alongside the 
other three things it hands
back -- because the queries do not all arrive while it is running:

- Before layout: the container sizes itself, and RenderFlexibleBox trims the 
first and last in-flow
  child's inline margins so they stay out of its intrinsic widths.
- During: an item asks as it lays out, which is mid-algorithm, so the sets are 
still filling in.
- After: the scrollbar reconciliation relayout runs an item's layoutBlock 
again, and a flex item can be
  a subtree layout root on a later pass.

The pre-layout answer no longer needs storing. It is the first and last in-flow 
child and nothing else,
which follows from style, so compute it where it is needed instead of keeping a 
member that
RenderFlexibleBox has to seed at the right point in layoutBlock and clear at 
the right time.
initializeMarginTrimState and its call site go away with it.

That also fixes the reset. Clearing lived in initializeMarginTrimState, which 
layoutBlock only called
when the container had a margin-trim value -- so removing margin-trim from an 
element left the previous
layout's entries in place indefinitely.

While here, make FlexLayout's copy of FlexFormattingContext::Result an 
optional. Assigning an empty
Result at the start of layout() left readers unable to tell "the algorithm has 
not run" from "it ran and
produced zeroes", and a flex container can be painted, hit-tested or asked for 
a baseline before its
first layout.

Also rename the two functions that build the two different kinds of flex item, 
since both were called
"flex items": buildFlexItemList produces the ordered list of in-flow children 
(FlexItemList), and
buildFlexLayoutItems produces what the formatting context works on 
(FlexLayoutItems). The margin
resolution moves into the latter, so the two walks over the item list become 
one, and
prepareFlexItemForPositionedLayout becomes 
prepareOutOfFlowBoxForPositionedLayout -- its argument is
explicitly not a flex item.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::FlexFormattingContext::layout):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
* Source/WebCore/layout/formattingContexts/flex/FlexLayoutState.h:
* Source/WebCore/layout/integration/flex/FlexIntegrationUtils.cpp:
(WebCore::LayoutIntegration::FlexIntegrationUtils::trimMainAxisMarginStart):
(WebCore::LayoutIntegration::FlexIntegrationUtils::trimMainAxisMarginEnd):
(WebCore::LayoutIntegration::FlexIntegrationUtils::trimCrossAxisMarginStart):
(WebCore::LayoutIntegration::FlexIntegrationUtils::trimCrossAxisMarginEnd):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::prepareOutOfFlowBoxForPositionedLayout):
(WebCore::LayoutIntegration::FlexLayout::buildFlexLayoutItems):
(WebCore::LayoutIntegration::FlexLayout::marginTrimItemsBeforeFlexLayout):
(WebCore::LayoutIntegration::FlexLayout::isFlexItemEligibleForMarginTrim):
(WebCore::LayoutIntegration::FlexLayout::buildFlexItemList):
(WebCore::LayoutIntegration::FlexLayout::adjustAllowedLayoutOverflow):
(WebCore::LayoutIntegration::FlexLayout::layout):
(WebCore::LayoutIntegration::FlexLayout::firstLineBaseline):
(WebCore::LayoutIntegration::FlexLayout::lastLineBaseline):
(WebCore::LayoutIntegration::FlexLayout::flexItemForFirstBaseline):
(WebCore::LayoutIntegration::FlexLayout::flexItemForLastBaseline):
(WebCore::LayoutIntegration::FlexLayout::initializeMarginTrimState): Deleted.
(WebCore::LayoutIntegration::FlexLayout::collectFlexItems): Deleted.
(WebCore::LayoutIntegration::FlexLayout::prepareFlexItemsAndMargins): Deleted.
(WebCore::LayoutIntegration::FlexLayout::prepareFlexItemForPositionedLayout): 
Deleted.
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h:
* Source/WebCore/rendering/RenderBlock.cpp:
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutBlock):

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



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

Reply via email to