Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 88ef621889239e3f0d189646bee6c7ed6443811d
https://github.com/WebKit/WebKit/commit/88ef621889239e3f0d189646bee6c7ed6443811d
Author: Issac Roy <[email protected]>
Date: 2026-09-21 (Mon, 21 Sep 2026)
Changed paths:
M LayoutTests/TestExpectations
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingUtils.cpp
M Source/WebCore/layout/formattingContexts/flex/FlexFormattingUtils.h
M Source/WebCore/layout/formattingContexts/flex/FlexLineBreaker.cpp
M Source/WebCore/layout/formattingContexts/flex/FlexLineBreaker.h
M Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp
M Tools/TestWebKitAPI/CMakeLists.txt
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
A Tools/TestWebKitAPI/Tests/WebCore/FlexLineBreakerTests.cpp
Log Message:
-----------
[Flex Wrap Balance] Implement flex-line-count
https://bugs.webkit.org/show_bug.cgi?id=323240
rdar://186491976
Reviewed by Alan Baradlay.
flex-line-count puts a floor under the number of lines a balanced container
produces. The line breaker already solves balancing with a dynamic program over
suffixes, so the constraint goes in as a second dimension rather than as a
bisection over line-break sizes: minScores[start][remaining] is the least total
squared free space covering items [start, itemCount) in at least remaining
further lines.
Scores accumulate in a WTF::UInt128. A column flow with an auto height has a
capacity of LayoutUnit::max(), so one line's squared free space reaches
(2^31 - 1)^2, and five such lines overflow 64 bits. Saturating there would make
every candidate compare equal to the sentinel and collapse the argmin to a
single line, so the old accumulator answered one line for a container that
asked for five. 128 bits cannot overflow here: it would take more than 7e19
lines, and SIZE_MAX bounds the item count at 1.8e19.
The candidate scan keeps its <= comparison deliberately. With end ascending,
the last end reaching the minimum wins, which puts as many items as possible on
the earliest line which is the tie-break the spec specifies.
Eight reftests in css-flexbox/balance come off the failing list. Nine remain,
for the intrinsic sizing that is not implemented yet, i.e. the case when we
have flex-line-count but no specified width.
Test: Tools/TestWebKitAPI/Tests/WebCore/FlexLineBreakerTests.cpp
* LayoutTests/TestExpectations:
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::FlexFormattingContext::computeFlexLines):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingUtils.cpp:
(WebCore::FlexFormattingUtils::minimumLineCount):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingUtils.h:
* Source/WebCore/layout/formattingContexts/flex/FlexLineBreaker.cpp:
(WebCore::balancedLineBreaks):
* Source/WebCore/layout/formattingContexts/flex/FlexLineBreaker.h:
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::flexLayoutConstraints const):
* Tools/TestWebKitAPI/CMakeLists.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebCore/FlexLineBreakerTests.cpp: Added.
(TestWebKitAPI::itemSizes):
(TestWebKitAPI::expectLineBreaks):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
GreedyFillsEachLineBeforeMovingOn)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker, NoItemsProducesNoLines)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
EverythingOnOneLineWhenNoMinimumApplies)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker, BalancingBeatsGreedyFilling)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
MinimumLineCountSplitsALineThatWouldOtherwiseFit)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
MinimumLineCountClampsToTheItemCount)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
AnItemWiderThanTheLineGetsALineToItself)):
(TestWebKitAPI::TEST(WebCoreFlexLineBreaker,
IndefiniteAvailableSpaceStillHonorsTheMinimumLineCount)):
Canonical link: https://commits.webkit.org/321545@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications