Changeset 278865 in webkit


Ignore:
Timestamp:
Jun 15, 2021 2:19:23 AM (13 months ago)
Author:
svillar@igalia.com
Message:

[css-flexbox] Do not compute the min-max sizes of flex items twice
https://bugs.webkit.org/show_bug.cgi?id=226463

Reviewed by Simon Fraser.

When determining the flex base size, the item’s min and max main sizes are ignored (no clamping occurs).
Those limits are used to compute the item's hypothetical main size and also later when the flexible
lengths are resolved. The thing is that we were running the code that clamps the flex item size twice instead
of computing those limits once and apply them twice.

From now one, we just compute them once and store the limits in a std::pair in the FlexItem class. This means
that the FlexItem is able to compute the hypothetical main size on its own and does not need it to be passed
as an argument.

No new tests as this is already being tested by dozens of tests.

  • rendering/FlexibleBoxAlgorithm.cpp:

(WebCore::FlexItem::FlexItem):
(WebCore::FlexItem::constrainSizeByMinMax const): Clamp the passed in size by the stored min & max sizes.

  • rendering/FlexibleBoxAlgorithm.h:
  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::computeFlexItemMinMaxSizes): Renamed from adjustChildSizeForMinAndMax and
without the childSize argument which is no longer needed.
(WebCore::RenderFlexibleBox::constructFlexItem): Use constrainSizeByMinMax.
(WebCore::RenderFlexibleBox::resolveFlexibleLengths): Ditto.
(WebCore::RenderFlexibleBox::adjustChildSizeForMinAndMax): Deleted.

  • rendering/RenderFlexibleBox.h:
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278864 r278865  
     12021-05-31  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Do not compute the min-max sizes of flex items twice
     4        https://bugs.webkit.org/show_bug.cgi?id=226463
     5
     6        Reviewed by Simon Fraser.
     7
     8        When determining the flex base size, the item’s min and max main sizes are ignored (no clamping occurs).
     9        Those limits are used to compute the item's hypothetical main size and also later when the flexible
     10        lengths are resolved. The thing is that we were running the code that clamps the flex item size twice instead
     11        of computing those limits once and apply them twice.
     12
     13        From now one, we just compute them once and store the limits in a std::pair in the FlexItem class. This means
     14        that the FlexItem is able to compute the hypothetical main size on its own and does not need it to be passed
     15        as an argument.
     16
     17        No new tests as this is already being tested by dozens of tests.
     18
     19        * rendering/FlexibleBoxAlgorithm.cpp:
     20        (WebCore::FlexItem::FlexItem):
     21        (WebCore::FlexItem::constrainSizeByMinMax const): Clamp the passed in size by the stored min & max sizes.
     22        * rendering/FlexibleBoxAlgorithm.h:
     23        * rendering/RenderFlexibleBox.cpp:
     24        (WebCore::RenderFlexibleBox::computeFlexItemMinMaxSizes): Renamed from adjustChildSizeForMinAndMax and
     25        without the childSize argument which is no longer needed.
     26        (WebCore::RenderFlexibleBox::constructFlexItem): Use constrainSizeByMinMax.
     27        (WebCore::RenderFlexibleBox::resolveFlexibleLengths): Ditto.
     28        (WebCore::RenderFlexibleBox::adjustChildSizeForMinAndMax): Deleted.
     29        * rendering/RenderFlexibleBox.h:
     30
    1312021-06-11  Sergio Villar Senin  <svillar@igalia.com>
    232
  • trunk/Source/WebCore/rendering/FlexibleBoxAlgorithm.cpp

    r278659 r278865  
    3636namespace WebCore {
    3737
    38 FlexItem::FlexItem(RenderBox& box, LayoutUnit flexBaseContentSize, LayoutUnit hypotheticalMainContentSize, LayoutUnit mainAxisBorderAndPadding, LayoutUnit mainAxisMargin, bool everHadLayout)
     38FlexItem::FlexItem(RenderBox& box, LayoutUnit flexBaseContentSize, LayoutUnit mainAxisBorderAndPadding, LayoutUnit mainAxisMargin, std::pair<LayoutUnit, LayoutUnit> minMaxSizes, bool everHadLayout)
    3939    : box(box)
    4040    , flexBaseContentSize(flexBaseContentSize)
    41     , hypotheticalMainContentSize(hypotheticalMainContentSize)
    4241    , mainAxisBorderAndPadding(mainAxisBorderAndPadding)
    4342    , mainAxisMargin(mainAxisMargin)
     43    , minMaxSizes(minMaxSizes)
     44    , hypotheticalMainContentSize(constrainSizeByMinMax(flexBaseContentSize))
     45    , frozen(false)
    4446    , everHadLayout(everHadLayout)
    4547{
     
    8789}
    8890
     91LayoutUnit FlexItem::constrainSizeByMinMax(const LayoutUnit size) const
     92{
     93    return std::max(minMaxSizes.first, std::min(size, minMaxSizes.second));
     94}
     95
    8996} // namespace WebCore
  • trunk/Source/WebCore/rendering/FlexibleBoxAlgorithm.h

    r278659 r278865  
    4242class FlexItem {
    4343public:
    44     FlexItem(RenderBox&, LayoutUnit flexBaseContentSize, LayoutUnit hypotheticalMainContentSize, LayoutUnit mainAxisBorderAndPadding, LayoutUnit mainAxisMargin, bool everHadLayout);
     44    FlexItem(RenderBox&, LayoutUnit flexBaseContentSize, LayoutUnit mainAxisBorderAndPadding, LayoutUnit mainAxisMargin, std::pair<LayoutUnit, LayoutUnit> minMaxSizes, bool everHadLayout);
    4545
    4646    LayoutUnit hypotheticalMainAxisMarginBoxSize() const
     
    5959    }
    6060
     61    LayoutUnit constrainSizeByMinMax(const LayoutUnit) const;
     62
    6163    RenderBox& box;
    6264    const LayoutUnit flexBaseContentSize;
    63     const LayoutUnit hypotheticalMainContentSize;
    6465    const LayoutUnit mainAxisBorderAndPadding;
    6566    const LayoutUnit mainAxisMargin;
     67    const std::pair<LayoutUnit, LayoutUnit> minMaxSizes;
     68    const LayoutUnit hypotheticalMainContentSize;
    6669    LayoutUnit flexedContentSize;
    6770    bool frozen { false };
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r278659 r278865  
    12021202}
    12031203
    1204 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox& child, LayoutUnit childSize)
     1204std::pair<LayoutUnit, LayoutUnit> RenderFlexibleBox::computeFlexItemMinMaxSizes(RenderBox& child)
    12051205{
    12061206    Length max = mainSizeLengthForChild(MaxSize, child);
    12071207    std::optional<LayoutUnit> maxExtent = std::nullopt;
    1208     if (max.isSpecifiedOrIntrinsic()) {
     1208    if (max.isSpecifiedOrIntrinsic())
    12091209        maxExtent = computeMainAxisExtentForChild(child, MaxSize, max);
    1210         childSize = std::min(childSize, maxExtent.value_or(childSize));
    1211     }
    12121210
    12131211    Length min = mainSizeLengthForChild(MinSize, child);
    12141212    // Intrinsic sizes in child's block axis are handled by the min-size:auto code path.
    12151213    if (min.isSpecified() || (min.isIntrinsic() && mainAxisIsChildInlineAxis(child)))
    1216         return std::max(childSize, std::max(0_lu, computeMainAxisExtentForChild(child, MinSize, min).value_or(childSize)));
     1214        return { computeMainAxisExtentForChild(child, MinSize, min).value_or(0_lu), maxExtent.value_or(LayoutUnit::max()) };
    12171215   
    12181216    if (shouldApplyMinSizeAutoForChild(child)) {
     
    12351233            ASSERT(resolvedMainSize >= 0);
    12361234            LayoutUnit specifiedSize = std::min(resolvedMainSize, maxExtent.value_or(resolvedMainSize));
    1237             return std::max(childSize, std::min(specifiedSize, contentSize));
     1235            return { std::min(specifiedSize, contentSize), maxExtent.value_or(LayoutUnit::max()) };
    12381236        }
    12391237
     
    12411239            LayoutUnit transferredSize = computeMainSizeFromAspectRatioUsing(child, childCrossSizeLength);
    12421240            transferredSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, transferredSize);
    1243             return std::max(childSize, std::min(transferredSize, contentSize));
    1244         }
    1245 
    1246         return std::max(childSize, contentSize);
    1247     }
    1248 
    1249     return std::max(0_lu, childSize);
     1241            return { std::min(transferredSize, contentSize), maxExtent.value_or(LayoutUnit::max()) };
     1242        }
     1243
     1244        return { contentSize, maxExtent.value_or(LayoutUnit::max()) };
     1245    }
     1246
     1247    return { 0_lu, maxExtent.value_or(LayoutUnit::max()) };
    12501248}
    12511249   
     
    13351333    LayoutUnit borderAndPadding = isHorizontalFlow() ? child.horizontalBorderAndPaddingExtent() : child.verticalBorderAndPaddingExtent();
    13361334    LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child, borderAndPadding);
    1337     LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMax(child, childInnerFlexBaseSize);
    13381335    LayoutUnit margin = isHorizontalFlow() ? child.horizontalMarginExtent() : child.verticalMarginExtent();
    1339     return FlexItem(child, childInnerFlexBaseSize, childMinMaxAppliedMainAxisExtent, borderAndPadding, margin, childHadLayout);
     1336    return FlexItem(child, childInnerFlexBaseSize, borderAndPadding, margin, computeFlexItemMinMaxSizes(child), childHadLayout);
    13401337}
    13411338   
     
    14111408        if (std::isfinite(extraSpace))
    14121409            childSize += LayoutUnit::fromFloatRound(extraSpace);
    1413        
    1414         LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(child, childSize);
     1410
     1411        LayoutUnit adjustedChildSize = flexItem.constrainSizeByMinMax(childSize);
    14151412        ASSERT(adjustedChildSize >= 0);
    14161413        flexItem.flexedContentSize = adjustedChildSize;
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r278450 r278865  
    175175    LayoutUnit computeChildMarginValue(Length margin);
    176176    void prepareOrderIteratorAndMargins();
    177     LayoutUnit adjustChildSizeForMinAndMax(RenderBox& child, LayoutUnit childSize);
     177    std::pair<LayoutUnit, LayoutUnit> computeFlexItemMinMaxSizes(RenderBox& child);
    178178    LayoutUnit adjustChildSizeForAspectRatioCrossAxisMinAndMax(const RenderBox& child, LayoutUnit childSize);
    179179    FlexItem constructFlexItem(RenderBox&, bool relayoutChildren);
Note: See TracChangeset for help on using the changeset viewer.