Changeset 294755 in webkit


Ignore:
Timestamp:
May 24, 2022 12:12:38 PM (2 years ago)
Author:
Alan Bujtas
Message:

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

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp

    r294638 r294755  
    207207void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
    208208{
     209    auto& formattingState = this->formattingState();
    209210    auto logicalFlexItemList = convertFlexItemsToLogicalSpace();
    210211
     
    214215    for (auto& logicalFlexItem : logicalFlexItemList) {
    215216        totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
    216         // FIXME: Use min/max here.
    217         totalFixedSpace += logicalFlexItem.rect.width();
     217        totalFixedSpace += formattingState.intrinsicWidthConstraintsForBox(*logicalFlexItem.layoutBox)->minimum;
    218218    }
    219219
     
    238238            // rest of the flex items in the flex container when positive free space is distributed.
    239239            ASSERT(availableSpace.has_value());
    240             logicalFlexItem.rect.setWidth(LayoutUnit { *availableSpace * grow / totalGrowth });
     240            // FIXME: This is still slighly incorrect.
     241            logicalFlexItem.rect.setWidth(LayoutUnit { formattingState.intrinsicWidthConstraintsForBox(*logicalFlexItem.layoutBox)->minimum + (flexibleSpace * grow / totalGrowth) });
    241242            // FIXME: constrain logical width on min width.
    242243        };
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp

    r294638 r294755  
    3535#include "HitTestResult.h"
    3636#include "LayoutBoxGeometry.h"
     37#include "LayoutChildIterator.h"
    3738#include "RenderFlexibleBox.h"
    3839
     
    7677void FlexLayout::updateFormattingRootGeometryAndInvalidate()
    7778{
    78     auto& flexBoxRenderer = this->flexBoxRenderer();
     79    auto updateGeometry = [&](auto& root) {
     80        auto& flexBoxRenderer = this->flexBoxRenderer();
    7981
    80     auto updateGeometry = [&](auto& root) {
    8182        auto isLeftToRightInlineDirection = flexBoxRenderer.style().isLeftToRightDirection();
    8283        auto writingMode = flexBoxRenderer.style().writingMode();
     
    8889        root.setVerticalMargin({ });
    8990    };
    90     return updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
     91    updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
     92
     93    for (auto& flexItem : Layout::childrenOfType<Layout::Box>(rootLayoutBox()))
     94        m_flexFormattingState.clearIntrinsicWidthConstraints(flexItem);
    9195}
    9296
    93 void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem)
     97void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize)
    9498{
    95     auto& boxGeometry = m_layoutState.ensureGeometryForBox(m_boxTree.layoutBoxForRenderer(flexItem));
     99    auto& layoutBox = m_boxTree.layoutBoxForRenderer(flexItem);
     100    auto& boxGeometry = m_layoutState.ensureGeometryForBox(layoutBox);
    96101
    97102    boxGeometry.setContentBoxWidth(flexItem.contentWidth());
     
    101106    boxGeometry.setBorder({ { flexItem.borderLeft(), flexItem.borderRight() }, { flexItem.borderTop(), flexItem.borderBottom() } });
    102107    boxGeometry.setPadding(Layout::Edges { { flexItem.paddingLeft(), flexItem.paddingRight() }, { flexItem.paddingTop(), flexItem.paddingBottom() } });
     108
     109    // FIXME: We may need to differentiate preferred and min/max content size.
     110    m_flexFormattingState.setIntrinsicWidthConstraintsForBox(layoutBox, { minimumContentSize, maximumContentSize });
    103111}
    104112
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h

    r294193 r294755  
    5252
    5353    void updateFormattingRootGeometryAndInvalidate();
    54     void updateFlexItemDimensions(const RenderBlock&);
     54    void updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize);
    5555    void updateStyle(const RenderBlock&, const RenderStyle& oldStyle);
    5656
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r294744 r294755  
    23572357    for (auto& flexItem : childrenOfType<RenderBlock>(*this)) {
    23582358        flexItem.layoutIfNeeded();
    2359         m_flexLayout->updateFlexItemDimensions(flexItem);
     2359        auto minMaxContentSize = computeFlexItemMinMaxSizes(flexItem);
     2360        m_flexLayout->updateFlexItemDimensions(flexItem, minMaxContentSize.first, minMaxContentSize.second);
    23602361    }
    23612362    m_flexLayout->layout();
Note: See TracChangeset for help on using the changeset viewer.