Skip to content
Permalink
Browse files
Add support for block direction grow
https://bugs.webkit.org/show_bug.cgi?id=240776

Reviewed by Antti Koivisto.

This is a basic block direction grow support (e.g. default block direction (top->bottom) with flex direction of column) when
flex box's height is fixed.

* Source/WebCore/layout/formattingContexts/FormattingConstraints.h:
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::updateRenderers const):

Canonical link: https://commits.webkit.org/250862@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294638 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed May 23, 2022
1 parent 897e10e commit 5f02aee533342afcd6bbb8c0aaee1818a048abc7
Showing 3 changed files with 13 additions and 8 deletions.
@@ -66,7 +66,7 @@ struct ConstraintsForInFlowContent {
private:
OptionSet<BaseTypeFlag> baseTypeFlags() const { return OptionSet<BaseTypeFlag>::fromRaw(m_baseTypeFlags); }

unsigned m_baseTypeFlags : 2; // OptionSet<BaseTypeFlag>
unsigned m_baseTypeFlags : 3; // OptionSet<BaseTypeFlag>
HorizontalConstraints m_horizontal;
LayoutUnit m_logicalTop;
};
@@ -209,36 +209,40 @@ void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsF
auto logicalFlexItemList = convertFlexItemsToLogicalSpace();

auto totalGrowth = 0.f;
auto totalFixedWidth = LayoutUnit { };
auto totalFixedSpace = LayoutUnit { };

for (auto& logicalFlexItem : logicalFlexItemList) {
totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
// FIXME: Use min/max here.
totalFixedWidth += logicalFlexItem.rect.width();
totalFixedSpace += logicalFlexItem.rect.width();
}

auto flexConstraints = downcast<ConstraintsForFlexContent>(constraints);
auto logicalLeft = LayoutUnit { };
auto logicalTop = LayoutUnit { };
auto availableWidth = constraints.horizontal().logicalWidth;
auto flexibleWidth = availableWidth - totalFixedWidth;
auto flexDirection = root().style().flexDirection();
auto flexDirectionIsInlineAxis = flexDirection == FlexDirection::Row || flexDirection == FlexDirection::RowReverse;
auto availableSpace = std::optional<LayoutUnit> { flexDirectionIsInlineAxis ? std::make_optional(flexConstraints.horizontal().logicalWidth) : flexConstraints.availableVerticalSpace() };
auto flexibleSpace = availableSpace.value_or(0_lu) - totalFixedSpace;

for (auto& logicalFlexItem : logicalFlexItemList) {
logicalFlexItem.rect.setTopLeft({ logicalLeft, logicalTop });
logicalLeft = logicalFlexItem.rect.right();
auto growFlexItemIfApplicable = [&] {
if (flexibleWidth <= 0)
if (flexibleSpace <= 0)
return;
auto grow = logicalFlexItem.layoutBox->style().flexGrow();
if (!grow)
return;
// This value specifies the flex grow factor, which determines how much the flex item will grow relative to the
// rest of the flex items in the flex container when positive free space is distributed.
logicalFlexItem.rect.setWidth(LayoutUnit { availableWidth * grow / totalGrowth });
ASSERT(availableSpace.has_value());
logicalFlexItem.rect.setWidth(LayoutUnit { *availableSpace * grow / totalGrowth });
// FIXME: constrain logical width on min width.
};
growFlexItemIfApplicable();
}
setFlexItemsGeometry(logicalFlexItemList, downcast<ConstraintsForFlexContent>(constraints));
setFlexItemsGeometry(logicalFlexItemList, flexConstraints);
}

IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstraintsForIntegration()
@@ -139,6 +139,7 @@ void FlexLayout::updateRenderers() const
auto borderBox = Layout::BoxGeometry::borderBoxRect(flexItemGeometry);
renderer.setLocation(borderBox.topLeft());
renderer.setWidth(borderBox.width());
renderer.setHeight(borderBox.height());
}
}

0 comments on commit 5f02aee

Please sign in to comment.