Changeset 294638 in webkit


Ignore:
Timestamp:
May 23, 2022 6:49:05 AM (2 years ago)
Author:
Alan Bujtas
Message:

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

Location:
trunk/Source/WebCore/layout
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/layout/formattingContexts/FormattingConstraints.h

    r294623 r294638  
    6767    OptionSet<BaseTypeFlag> baseTypeFlags() const { return OptionSet<BaseTypeFlag>::fromRaw(m_baseTypeFlags); }
    6868
    69     unsigned m_baseTypeFlags : 2; // OptionSet<BaseTypeFlag>
     69    unsigned m_baseTypeFlags : 3; // OptionSet<BaseTypeFlag>
    7070    HorizontalConstraints m_horizontal;
    7171    LayoutUnit m_logicalTop;
  • trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp

    r294623 r294638  
    210210
    211211    auto totalGrowth = 0.f;
    212     auto totalFixedWidth = LayoutUnit { };
     212    auto totalFixedSpace = LayoutUnit { };
    213213
    214214    for (auto& logicalFlexItem : logicalFlexItemList) {
    215215        totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
    216216        // FIXME: Use min/max here.
    217         totalFixedWidth += logicalFlexItem.rect.width();
    218     }
    219 
     217        totalFixedSpace += logicalFlexItem.rect.width();
     218    }
     219
     220    auto flexConstraints = downcast<ConstraintsForFlexContent>(constraints);
    220221    auto logicalLeft = LayoutUnit { };
    221222    auto logicalTop = LayoutUnit { };
    222     auto availableWidth = constraints.horizontal().logicalWidth;
    223     auto flexibleWidth = availableWidth - totalFixedWidth;
     223    auto flexDirection = root().style().flexDirection();
     224    auto flexDirectionIsInlineAxis = flexDirection == FlexDirection::Row || flexDirection == FlexDirection::RowReverse;
     225    auto availableSpace = std::optional<LayoutUnit> { flexDirectionIsInlineAxis ? std::make_optional(flexConstraints.horizontal().logicalWidth) : flexConstraints.availableVerticalSpace() };
     226    auto flexibleSpace = availableSpace.value_or(0_lu) - totalFixedSpace;
    224227
    225228    for (auto& logicalFlexItem : logicalFlexItemList) {
     
    227230        logicalLeft = logicalFlexItem.rect.right();
    228231        auto growFlexItemIfApplicable = [&] {
    229             if (flexibleWidth <= 0)
     232            if (flexibleSpace <= 0)
    230233                return;
    231234            auto grow = logicalFlexItem.layoutBox->style().flexGrow();
     
    234237            // This value specifies the flex grow factor, which determines how much the flex item will grow relative to the
    235238            // rest of the flex items in the flex container when positive free space is distributed.
    236             logicalFlexItem.rect.setWidth(LayoutUnit { availableWidth * grow / totalGrowth });
     239            ASSERT(availableSpace.has_value());
     240            logicalFlexItem.rect.setWidth(LayoutUnit { *availableSpace * grow / totalGrowth });
    237241            // FIXME: constrain logical width on min width.
    238242        };
    239243        growFlexItemIfApplicable();
    240244    }
    241     setFlexItemsGeometry(logicalFlexItemList, downcast<ConstraintsForFlexContent>(constraints));
     245    setFlexItemsGeometry(logicalFlexItemList, flexConstraints);
    242246}
    243247
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp

    r294623 r294638  
    140140        renderer.setLocation(borderBox.topLeft());
    141141        renderer.setWidth(borderBox.width());
     142        renderer.setHeight(borderBox.height());
    142143    }
    143144}
Note: See TracChangeset for help on using the changeset viewer.