Changeset 294463 in webkit


Ignore:
Timestamp:
May 18, 2022 8:05:09 PM (2 years ago)
Author:
Alan Bujtas
Message:

Add support for simple 'flex-grow'
https://bugs.webkit.org/show_bug.cgi?id=240561

Reviewed by Antti Koivisto.

This is a basic "flex grow" implementation ignoring min/max values.

  • Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:

(WebCore::Layout::FlexFormattingContext::setFlexItemsGeometry):
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):

  • Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:

(WebCore::LayoutIntegration::FlexLayout::updateRenderers const):

Canonical link: https://commits.webkit.org/250725@main

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

Legend:

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

    r294412 r294463  
    198198        }
    199199        flexItemGeometry.setLogicalTopLeft(topLeft);
     200        if (direction == FlexDirection::Row || direction == FlexDirection::RowReverse)
     201            flexItemGeometry.setContentBoxWidth(logicalFlexItem.rect.width() - flexItemGeometry.horizontalMarginBorderAndPadding());
     202        else
     203            flexItemGeometry.setContentBoxHeight(logicalFlexItem.rect.width() - flexItemGeometry.verticalMarginBorderAndPadding());
    200204    }
    201205}
     
    204208{
    205209    auto logicalFlexItemList = convertFlexItemsToLogicalSpace();
     210
     211    auto totalGrowth = 0.f;
     212    auto totalFixedWidth = LayoutUnit { };
     213
     214    for (auto& logicalFlexItem : logicalFlexItemList) {
     215        totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
     216        // FIXME: Use min/max here.
     217        totalFixedWidth += logicalFlexItem.rect.width();
     218    }
    206219
    207220    auto logicalLeft = LayoutUnit { };
    208221    auto logicalTop = LayoutUnit { };
     222    auto availableWidth = constraints.horizontal().logicalWidth;
     223    auto flexibleWidth = availableWidth - totalFixedWidth;
    209224
    210225    for (auto& logicalFlexItem : logicalFlexItemList) {
    211226        logicalFlexItem.rect.setTopLeft({ logicalLeft, logicalTop });
    212227        logicalLeft = logicalFlexItem.rect.right();
     228        auto growFlexItemIfApplicable = [&] {
     229            if (flexibleWidth <= 0)
     230                return;
     231            auto grow = logicalFlexItem.layoutBox->style().flexGrow();
     232            if (!grow)
     233                return;
     234            // This value specifies the flex grow factor, which determines how much the flex item will grow relative to the
     235            // rest of the flex items in the flex container when positive free space is distributed.
     236            logicalFlexItem.rect.setWidth(LayoutUnit { availableWidth * grow / totalGrowth });
     237            // FIXME: constrain logical width on min width.
     238        };
     239        growFlexItemIfApplicable();
    213240    }
    214241    setFlexItemsGeometry(logicalFlexItemList, constraints);
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp

    r294210 r294463  
    132132
    133133        auto& renderer = downcast<RenderBox>(*boxAndRenderer.renderer);
    134         renderer.setLocation(Layout::BoxGeometry::borderBoxTopLeft(m_flexFormattingState.boxGeometry(layoutBox)));
     134        auto& flexItemGeometry = m_flexFormattingState.boxGeometry(layoutBox);
     135        auto borderBox = Layout::BoxGeometry::borderBoxRect(flexItemGeometry);
     136        renderer.setLocation(borderBox.topLeft());
     137        renderer.setWidth(borderBox.width());
    135138    }
    136139}
Note: See TracChangeset for help on using the changeset viewer.