Skip to content
Permalink
Browse files
Start using min/max content size for flexing
https://bugs.webkit.org/show_bug.cgi?id=240872

Reviewed by Antti Koivisto.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::updateFormattingRootGeometryAndInvalidate):
(WebCore::LayoutIntegration::FlexLayout::updateFlexItemDimensions):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h:
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):

Canonical link: https://commits.webkit.org/250923@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294755 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed May 24, 2022
1 parent eea2032 commit c3e23dad47e599462191db89505a216c249d9ff6
Showing 4 changed files with 20 additions and 10 deletions.
@@ -206,15 +206,15 @@ void FlexFormattingContext::setFlexItemsGeometry(const LogicalFlexItems& logical

void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
{
auto& formattingState = this->formattingState();
auto logicalFlexItemList = convertFlexItemsToLogicalSpace();

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

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

auto flexConstraints = downcast<ConstraintsForFlexContent>(constraints);
@@ -237,7 +237,8 @@ void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsF
// 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.
ASSERT(availableSpace.has_value());
logicalFlexItem.rect.setWidth(LayoutUnit { *availableSpace * grow / totalGrowth });
// FIXME: This is still slighly incorrect.
logicalFlexItem.rect.setWidth(LayoutUnit { formattingState.intrinsicWidthConstraintsForBox(*logicalFlexItem.layoutBox)->minimum + (flexibleSpace * grow / totalGrowth) });
// FIXME: constrain logical width on min width.
};
growFlexItemIfApplicable();
@@ -34,6 +34,7 @@
#include "HitTestRequest.h"
#include "HitTestResult.h"
#include "LayoutBoxGeometry.h"
#include "LayoutChildIterator.h"
#include "RenderFlexibleBox.h"

namespace WebCore {
@@ -75,9 +76,9 @@ static inline Layout::Edges flexBoxLogicalPadding(const RenderBoxModelObject& re

void FlexLayout::updateFormattingRootGeometryAndInvalidate()
{
auto& flexBoxRenderer = this->flexBoxRenderer();

auto updateGeometry = [&](auto& root) {
auto& flexBoxRenderer = this->flexBoxRenderer();

auto isLeftToRightInlineDirection = flexBoxRenderer.style().isLeftToRightDirection();
auto writingMode = flexBoxRenderer.style().writingMode();

@@ -87,19 +88,26 @@ void FlexLayout::updateFormattingRootGeometryAndInvalidate()
root.setHorizontalMargin({ });
root.setVerticalMargin({ });
};
return updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));

for (auto& flexItem : Layout::childrenOfType<Layout::Box>(rootLayoutBox()))
m_flexFormattingState.clearIntrinsicWidthConstraints(flexItem);
}

void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem)
void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize)
{
auto& boxGeometry = m_layoutState.ensureGeometryForBox(m_boxTree.layoutBoxForRenderer(flexItem));
auto& layoutBox = m_boxTree.layoutBoxForRenderer(flexItem);
auto& boxGeometry = m_layoutState.ensureGeometryForBox(layoutBox);

boxGeometry.setContentBoxWidth(flexItem.contentWidth());
boxGeometry.setContentBoxHeight(flexItem.contentHeight());
boxGeometry.setVerticalMargin({ flexItem.marginTop(), flexItem.marginBottom() });
boxGeometry.setHorizontalMargin({ flexItem.marginLeft(), flexItem.marginRight() });
boxGeometry.setBorder({ { flexItem.borderLeft(), flexItem.borderRight() }, { flexItem.borderTop(), flexItem.borderBottom() } });
boxGeometry.setPadding(Layout::Edges { { flexItem.paddingLeft(), flexItem.paddingRight() }, { flexItem.paddingTop(), flexItem.paddingBottom() } });

// FIXME: We may need to differentiate preferred and min/max content size.
m_flexFormattingState.setIntrinsicWidthConstraintsForBox(layoutBox, { minimumContentSize, maximumContentSize });
}

void FlexLayout::updateStyle(const RenderBlock&, const RenderStyle&)
@@ -51,7 +51,7 @@ class FlexLayout : public CanMakeCheckedPtr {
FlexLayout(RenderFlexibleBox&);

void updateFormattingRootGeometryAndInvalidate();
void updateFlexItemDimensions(const RenderBlock&);
void updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize);
void updateStyle(const RenderBlock&, const RenderStyle& oldStyle);

std::pair<LayoutUnit, LayoutUnit> computeIntrinsicWidthConstraints();
@@ -2356,7 +2356,8 @@ void RenderFlexibleBox::layoutUsingFlexFormattingContext()

for (auto& flexItem : childrenOfType<RenderBlock>(*this)) {
flexItem.layoutIfNeeded();
m_flexLayout->updateFlexItemDimensions(flexItem);
auto minMaxContentSize = computeFlexItemMinMaxSizes(flexItem);
m_flexLayout->updateFlexItemDimensions(flexItem, minMaxContentSize.first, minMaxContentSize.second);
}
m_flexLayout->layout();
}

0 comments on commit c3e23da

Please sign in to comment.