Skip to content

Commit

Permalink
[FFC] RenderStyle::alignContent().distribution()'s ContentDistributio…
Browse files Browse the repository at this point in the history
…n::Default maps to stretch

https://bugs.webkit.org/show_bug.cgi?id=258778

Reviewed by Antti Koivisto.

1. Lines may stretch when align content is ContentDistribution::Default
2. Fix flipped condition
3. flexItemsWithMarginAuto is the collection of margin auto flex items

* Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp:
(WebCore::Layout::FlexLayout::stretchFlexLines const):
(WebCore::Layout::FlexLayout::handleMainAxisAlignment const):

Canonical link: https://commits.webkit.org/265697@main
  • Loading branch information
alanbaradlay committed Jul 2, 2023
1 parent 8161b33 commit 0bf69cd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,11 @@ void FlexLayout::stretchFlexLines(LinesCrossSizeList& flexLinesCrossSizeList, si
// Handle 'align-content: stretch'.
// If the flex container has a definite cross size, align-content is stretch, and the sum of the flex lines' cross sizes is less than the flex container's inner cross size,
// increase the cross size of each flex line by equal amounts such that the sum of their cross sizes exactly equals the flex container's inner cross size.
if (flexContainerStyle().alignContent().distribution() != ContentDistribution::Stretch || !crossAxis.definiteSize)
auto linesMayStretch = [&] {
auto alignContent = flexContainerStyle().alignContent().distribution();
return alignContent == ContentDistribution::Stretch || alignContent == ContentDistribution::Default;
};
if (!linesMayStretch() || !crossAxis.definiteSize)
return;

auto linesCrossSize = [&] {
Expand All @@ -486,7 +490,7 @@ void FlexLayout::stretchFlexLines(LinesCrossSizeList& flexLinesCrossSizeList, si
size += flexLinesCrossSizeList[lineIndex];
return size;
}();
if (*crossAxis.definiteSize > linesCrossSize)
if (*crossAxis.definiteSize <= linesCrossSize)
return;

auto extraSpace = (*crossAxis.definiteSize - linesCrossSize) / numberOfLines;
Expand Down Expand Up @@ -538,7 +542,7 @@ FlexLayout::PositionAndMarginsList FlexLayout::handleMainAxisAlignment(LayoutUni
auto resolveMarginAuto = [&] {
// 1. If the remaining free space is positive and at least one main-axis margin on this line is auto, distribute the free space equally among these margins.
// Otherwise, set all auto margins to zero.
auto flexItemsWithMarginAuto = Vector<size_t> { flexItems.size() };
auto flexItemsWithMarginAuto = Vector<size_t> { };
size_t autoMarginCount = 0;

for (auto flexItemIndex = lineRange.begin(); flexItemIndex < lineRange.end(); ++flexItemIndex) {
Expand Down

0 comments on commit 0bf69cd

Please sign in to comment.