Title: [285623] trunk
Revision
285623
Author
[email protected]
Date
2021-11-11 01:42:13 -0800 (Thu, 11 Nov 2021)

Log Message

[css-flexbox] Improve & simplify the flex-basis computation
https://bugs.webkit.org/show_bug.cgi?id=230755

Reviewed by Alan Bujtas.

PerformanceTests:

New test case to catch performance regressions with lots of nested (specially column) flexboxes.

* Layout/nested-flexbox.html: Added.

Source/WebCore:

The flex basis computation has some special cases that require us to size the flex items "as if" they had the
length specified by flex-basis property as their main size (either width or height depending on the flex direction).
In order to do that a mechanism similar to the overriding sizes was implemented, but in this case, we're doing
an overriding of the style. That overriding style is used during both layout and preferred width computations if
present.

A new RAII class called ScopedFlexBasisAsChildMainSize sets the overriding before computing the flex base size and
clears it just after the calculations. This is done in the computeFlexBaseSizeForChild() method that was renamed
from computeInnerFlexBaseSizeForChild() as it fits better with the terminology used in the specs.

Flex basis computation is already covered by the WPT test suite, there is no need for extra tests. This patch
fixes the only flex-basis-* test case that was not passing apart from another one.

The original patch was causing severe regressions in sites doing heavy usage of nested flexboxes like twitter.com or
gmail.com because it was removing some caching that is needed in order not to do way too many layouts. The new one does
not have this issue. A new perf test was added in order to detect those eventual regressions. In my laptop the test
achieves 13.5k runs/s while with the original patch is only capable of doing 6k runs/s.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::computePreferredLogicalWidths): Use the overriding style if present.
* rendering/RenderBox.cpp:
(WebCore::RenderBox::overridingLogicalHeightLength const): Added.
(WebCore::RenderBox::setOverridingLogicalHeightLength): Added.
(WebCore::RenderBox::hasOverridingLogicalHeightLength const): Added.
(WebCore::RenderBox::clearOverridingLogicalHeightLength): Added.
(WebCore::RenderBox::overridingLogicalWidthLength const): Added.
(WebCore::RenderBox::setOverridingLogicalWidthLength): Added.
(WebCore::RenderBox::hasOverridingLogicalWidthLength const): Added.
(WebCore::RenderBox::clearOverridingLogicalWidthLength): Added.
(WebCore::RenderBox::computeLogicalWidthInFragment const): Use the overriding style if present.
(WebCore::RenderBox::computeLogicalHeight const): Use the overriding style if present.
* rendering/RenderBox.h:
* rendering/RenderFlexibleBox.cpp:
(WebCore::ScopedFlexBasisAsChildMainSize::ScopedFlexBasisAsChildMainSize): Sets the overriding style.
(WebCore::ScopedFlexBasisAsChildMainSize::~ScopedFlexBasisAsChildMainSize): Clears the overriding style.
(WebCore::RenderFlexibleBox::computeFlexBaseSizeForChild): Renamed from computeInnerFlexBaseSizeForChild().
(WebCore::RenderFlexibleBox::maybeCacheChildMainIntrinsicSize): Refactored from code from
computeInnerFlexBaseSizeForChild().
(WebCore::RenderFlexibleBox::constructFlexItem): Moved code to maybeCacheChildMainIntrinsicSize().
(WebCore::RenderFlexibleBox::computeInnerFlexBaseSizeForChild): Deleted.
* rendering/RenderFlexibleBox.h:

LayoutTests:

* TestExpectations: Unskipped a couple of tests that work fine now.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (285622 => 285623)


--- trunk/LayoutTests/ChangeLog	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/LayoutTests/ChangeLog	2021-11-11 09:42:13 UTC (rev 285623)
@@ -1,3 +1,12 @@
+2021-11-10  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Improve & simplify the flex-basis computation
+        https://bugs.webkit.org/show_bug.cgi?id=230755
+
+        Reviewed by Alan Bujtas.
+
+        * TestExpectations: Unskipped a couple of tests that work fine now.
+
 2021-11-11  Antoine Quint  <[email protected]>
 
         Default computed value for "content" should be "none" for ::before and ::after

Modified: trunk/LayoutTests/TestExpectations (285622 => 285623)


--- trunk/LayoutTests/TestExpectations	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/LayoutTests/TestExpectations	2021-11-11 09:42:13 UTC (rev 285623)
@@ -4276,9 +4276,6 @@
 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-003a.html [ ImageOnlyFailure ]
 webkit.org/b/221479 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-flex-basis-content-004a.html [ ImageOnlyFailure ]
 
-# flex-basis with %.
-webkit.org/b/ imported/w3c/web-platform-tests/css/css-flexbox/flex-basis-011.html [ ImageOnlyFailure ]
-
 # Flex item's min|max content contributions
 webkit.org/b/230747 imported/w3c/web-platform-tests/css/css-flexbox/flex-container-max-content-001.html [ ImageOnlyFailure ]
 webkit.org/b/230747 imported/w3c/web-platform-tests/css/css-flexbox/flex-container-min-content-001.html [ ImageOnlyFailure ]
@@ -4290,7 +4287,6 @@
 webkit.org/b/221480 imported/w3c/web-platform-tests/css/css-flexbox/flexbox-break-request-vert-001b.html [ ImageOnlyFailure ]
 
 # min-size:auto in flexbox.
-webkit.org/b/221481 imported/w3c/web-platform-tests/css/css-flexbox/flex-minimum-height-flex-items-026.html [ ImageOnlyFailure ]
 webkit.org/b/221481 imported/w3c/web-platform-tests/css/css-flexbox/flex-minimum-height-flex-items-029.html [ ImageOnlyFailure ]
 webkit.org/b/221481 imported/w3c/web-platform-tests/css/css-flexbox/flex-minimum-width-flex-items-015.html [ ImageOnlyFailure ]
 

Modified: trunk/PerformanceTests/ChangeLog (285622 => 285623)


--- trunk/PerformanceTests/ChangeLog	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/PerformanceTests/ChangeLog	2021-11-11 09:42:13 UTC (rev 285623)
@@ -1,3 +1,14 @@
+2021-11-10  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Improve & simplify the flex-basis computation
+        https://bugs.webkit.org/show_bug.cgi?id=230755
+
+        Reviewed by Alan Bujtas.
+
+        New test case to catch performance regressions with lots of nested (specially column) flexboxes.
+
+        * Layout/nested-flexbox.html: Added.
+
 2021-11-10  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, fix broken test

Added: trunk/PerformanceTests/Layout/nested-flexbox.html (0 => 285623)


--- trunk/PerformanceTests/Layout/nested-flexbox.html	                        (rev 0)
+++ trunk/PerformanceTests/Layout/nested-flexbox.html	2021-11-11 09:42:13 UTC (rev 285623)
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<style>
+html, body {
+    margin: 0;
+    height: 100%;
+    width: 500px;
+}
+.flex { display: flex; }
+.column { flex-direction: column; }
+.row { flex-direction: row; }
+.flex-item { flex-basis: auto; flex-shrink: 0; }
+
+</style>
+<script src=""
+<script>
+function startTest() {
+    document.body.offsetHeight;
+    var index = 0;
+    PerfTestRunner.measureRunsPerSecond({
+        run: function () {
+            var wrap = document.getElementById("wrap");
+            wrap.style.width = ++index % 2 ? "99%" : "98%";
+            document.body.offsetHeight;
+        }
+    });
+}
+</script>
+</head>
+
+<body _onload_="startTest()">
+<div id="wrap" class="flex column">
+    <div class="flex column flex-item">
+        <div class="flex column flex-item">
+            <div class="flex column flex-item">
+                <div class="flex column flex-item">
+                    <div class="flex row flex-item">
+                        <div class="flex column flex-item">
+                            <div class="flex column flex-item">
+                                <div class="flex column flex-item">
+                                    <div class="flex column flex-item">
+                                        <div class="flex row flex-item">
+                                            <div class="flex column flex-item">
+                                                <div class="flex column flex-item">
+                                                    <div class="flex column flex-item">
+                                                        <div class="flex column flex-item">
+                                                            <div class="flex row flex-item">
+                                                                <span style="display: inline-flex">XXX</span>
+                                                            </div>
+                                                        </div>
+                                                    </div>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</body>
Property changes on: trunk/PerformanceTests/Layout/nested-flexbox.html
___________________________________________________________________

Added: svn:eol-style

+LF \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Modified: trunk/Source/WebCore/ChangeLog (285622 => 285623)


--- trunk/Source/WebCore/ChangeLog	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/ChangeLog	2021-11-11 09:42:13 UTC (rev 285623)
@@ -1,3 +1,52 @@
+2021-11-10  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Improve & simplify the flex-basis computation
+        https://bugs.webkit.org/show_bug.cgi?id=230755
+
+        Reviewed by Alan Bujtas.
+
+        The flex basis computation has some special cases that require us to size the flex items "as if" they had the
+        length specified by flex-basis property as their main size (either width or height depending on the flex direction).
+        In order to do that a mechanism similar to the overriding sizes was implemented, but in this case, we're doing
+        an overriding of the style. That overriding style is used during both layout and preferred width computations if
+        present.
+
+        A new RAII class called ScopedFlexBasisAsChildMainSize sets the overriding before computing the flex base size and
+        clears it just after the calculations. This is done in the computeFlexBaseSizeForChild() method that was renamed
+        from computeInnerFlexBaseSizeForChild() as it fits better with the terminology used in the specs.
+
+        Flex basis computation is already covered by the WPT test suite, there is no need for extra tests. This patch
+        fixes the only flex-basis-* test case that was not passing apart from another one.
+
+        The original patch was causing severe regressions in sites doing heavy usage of nested flexboxes like twitter.com or
+        gmail.com because it was removing some caching that is needed in order not to do way too many layouts. The new one does
+        not have this issue. A new perf test was added in order to detect those eventual regressions. In my laptop the test
+        achieves 13.5k runs/s while with the original patch is only capable of doing 6k runs/s.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::computePreferredLogicalWidths): Use the overriding style if present.
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::overridingLogicalHeightLength const): Added.
+        (WebCore::RenderBox::setOverridingLogicalHeightLength): Added.
+        (WebCore::RenderBox::hasOverridingLogicalHeightLength const): Added.
+        (WebCore::RenderBox::clearOverridingLogicalHeightLength): Added.
+        (WebCore::RenderBox::overridingLogicalWidthLength const): Added.
+        (WebCore::RenderBox::setOverridingLogicalWidthLength): Added.
+        (WebCore::RenderBox::hasOverridingLogicalWidthLength const): Added.
+        (WebCore::RenderBox::clearOverridingLogicalWidthLength): Added.
+        (WebCore::RenderBox::computeLogicalWidthInFragment const): Use the overriding style if present.
+        (WebCore::RenderBox::computeLogicalHeight const): Use the overriding style if present.
+        * rendering/RenderBox.h:
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::ScopedFlexBasisAsChildMainSize::ScopedFlexBasisAsChildMainSize): Sets the overriding style.
+        (WebCore::ScopedFlexBasisAsChildMainSize::~ScopedFlexBasisAsChildMainSize): Clears the overriding style.
+        (WebCore::RenderFlexibleBox::computeFlexBaseSizeForChild): Renamed from computeInnerFlexBaseSizeForChild().
+        (WebCore::RenderFlexibleBox::maybeCacheChildMainIntrinsicSize): Refactored from code from
+        computeInnerFlexBaseSizeForChild().
+        (WebCore::RenderFlexibleBox::constructFlexItem): Moved code to maybeCacheChildMainIntrinsicSize().
+        (WebCore::RenderFlexibleBox::computeInnerFlexBaseSizeForChild): Deleted.
+        * rendering/RenderFlexibleBox.h:
+
 2021-11-11  Antti Koivisto  <[email protected]>
 
         Use narrower types for style scope ordinal and cascade layer priority

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (285622 => 285623)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2021-11-11 09:42:13 UTC (rev 285623)
@@ -2256,9 +2256,10 @@
     m_maxPreferredLogicalWidth = 0;
 
     const RenderStyle& styleToUse = style();
-    if (!isTableCell() && styleToUse.logicalWidth().isFixed() && styleToUse.logicalWidth().value() >= 0
-        && !(isDeprecatedFlexItem() && !styleToUse.logicalWidth().intValue()))
-        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalWidth());
+    auto& lengthToUse = hasOverridingLogicalWidthLength() ? overridingLogicalWidthLength() : styleToUse.logicalWidth();
+    if (!isTableCell() && lengthToUse.isFixed() && lengthToUse.value() >= 0
+        && !(isDeprecatedFlexItem() && !lengthToUse.intValue()))
+        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(lengthToUse);
     else if (shouldComputeLogicalWidthFromAspectRatio())
         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeLogicalWidthFromAspectRatio();
     else

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (285622 => 285623)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2021-11-11 09:42:13 UTC (rev 285623)
@@ -106,6 +106,10 @@
 static OverrideSizeMap* gOverridingLogicalHeightMap = nullptr;
 static OverrideSizeMap* gOverridingLogicalWidthMap = nullptr;
 
+typedef HashMap<const RenderBox*, Length> OverridingLengthMap;
+static OverridingLengthMap* gOverridingLogicalHeightLengthMap = nullptr;
+static OverridingLengthMap* gOverridingLogicalWidthLengthMap = nullptr;
+
 // FIXME: We should store these based on physical direction.
 typedef HashMap<const RenderBox*, std::optional<LayoutUnit>> OverrideOptionalSizeMap;
 static OverrideOptionalSizeMap* gOverridingContainingBlockContentLogicalHeightMap = nullptr;
@@ -1315,6 +1319,54 @@
         gOverridingContainingBlockContentLogicalHeightMap->remove(this);
 }
 
+Length RenderBox::overridingLogicalHeightLength() const
+{
+    ASSERT(hasOverridingLogicalHeightLength());
+    return gOverridingLogicalHeightLengthMap->get(this);
+}
+
+void RenderBox::setOverridingLogicalHeightLength(const Length& height)
+{
+    if (!gOverridingLogicalHeightLengthMap)
+        gOverridingLogicalHeightLengthMap = new OverridingLengthMap();
+    gOverridingLogicalHeightLengthMap->set(this, height);
+}
+
+bool RenderBox::hasOverridingLogicalHeightLength() const
+{
+    return gOverridingLogicalHeightLengthMap && gOverridingLogicalHeightLengthMap->contains(this);
+}
+
+void RenderBox::clearOverridingLogicalHeightLength()
+{
+    if (gOverridingLogicalHeightLengthMap)
+        gOverridingLogicalHeightLengthMap->remove(this);
+}
+
+Length RenderBox::overridingLogicalWidthLength() const
+{
+    ASSERT(hasOverridingLogicalWidthLength());
+    return gOverridingLogicalWidthLengthMap->get(this);
+}
+
+void RenderBox::setOverridingLogicalWidthLength(const Length& height)
+{
+    if (!gOverridingLogicalWidthLengthMap)
+        gOverridingLogicalWidthLengthMap = new OverridingLengthMap();
+    gOverridingLogicalWidthLengthMap->set(this, height);
+}
+
+bool RenderBox::hasOverridingLogicalWidthLength() const
+{
+    return gOverridingLogicalWidthLengthMap && gOverridingLogicalWidthLengthMap->contains(this);
+}
+
+void RenderBox::clearOverridingLogicalWidthLength()
+{
+    if (gOverridingLogicalWidthLengthMap)
+        gOverridingLogicalWidthLengthMap->remove(this);
+}
+
 LayoutUnit RenderBox::adjustBorderBoxLogicalWidthForBoxSizing(const Length& logicalWidth) const
 {
     auto width = LayoutUnit { logicalWidth.value() };
@@ -2625,7 +2677,11 @@
     treatAsReplaced = treatAsReplaced && (!isGridItem() || !hasStretchedLogicalWidth());
 
     const RenderStyle& styleToUse = style();
-    Length logicalWidthLength = treatAsReplaced ? Length(computeReplacedLogicalWidth(), LengthType::Fixed) : styleToUse.logicalWidth();
+    Length logicalWidthLength;
+    if (hasOverridingLogicalWidthLength())
+        logicalWidthLength = overridingLogicalWidthLength();
+    else
+        logicalWidthLength = treatAsReplaced ? Length(computeReplacedLogicalWidth(), LengthType::Fixed) : styleToUse.logicalWidth();
 
     RenderBlock& cb = *containingBlock();
     LayoutUnit containerLogicalWidth = std::max<LayoutUnit>(0, containingBlockLogicalWidthForContentInFragment(fragment));
@@ -2650,7 +2706,7 @@
     } else if (shouldComputeLogicalWidthFromAspectRatio() && style().logicalWidth().isAuto()) {
         computedValues.m_extent = computeLogicalWidthFromAspectRatio(fragment);
     } else {
-        LayoutUnit preferredWidth = computeLogicalWidthInFragmentUsing(MainOrPreferredSize, styleToUse.logicalWidth(), containerWidthInInlineDirection, cb, fragment);
+        LayoutUnit preferredWidth = computeLogicalWidthInFragmentUsing(MainOrPreferredSize, hasOverridingLogicalWidthLength() ? logicalWidthLength : styleToUse.logicalWidth(), containerWidthInInlineDirection, cb, fragment);
         computedValues.m_extent = constrainLogicalWidthInFragmentByMinMax(preferredWidth, containerWidthInInlineDirection, cb, fragment);
     }
 
@@ -3054,6 +3110,7 @@
         bool stretching = parent()->style().boxAlign() == BoxAlignment::Stretch;
         bool treatAsReplaced = shouldComputeSizeAsReplaced() && (!inHorizontalBox || !stretching);
         bool checkMinMaxHeight = false;
+        auto& logicalHeightInUse = hasOverridingLogicalHeightLength() ? overridingLogicalHeightLength() : style().logicalHeight();
 
         // The parent box is flexing us, so it has increased or decreased our height.  We have to
         // grab our cached flexible height.
@@ -3064,7 +3121,7 @@
         } else if (treatAsReplaced)
             h = Length(computeReplacedLogicalHeight() + borderAndPaddingLogicalHeight(), LengthType::Fixed);
         else {
-            h = style().logicalHeight();
+            h = logicalHeightInUse;
             checkMinMaxHeight = true;
         }
 
@@ -3091,7 +3148,7 @@
             } else {
                 if (intrinsicHeight)
                     *intrinsicHeight -= borderAndPaddingLogicalHeight();
-                heightResult = computeLogicalHeightUsing(MainOrPreferredSize, style().logicalHeight(), intrinsicHeight).value_or(computedValues.m_extent);
+                heightResult = computeLogicalHeightUsing(MainOrPreferredSize, logicalHeightInUse, intrinsicHeight).value_or(computedValues.m_extent);
             }
             heightResult = constrainLogicalHeightByMinMax(heightResult, intrinsicHeight);
         } else {

Modified: trunk/Source/WebCore/rendering/RenderBox.h (285622 => 285623)


--- trunk/Source/WebCore/rendering/RenderBox.h	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2021-11-11 09:42:13 UTC (rev 285623)
@@ -344,6 +344,18 @@
     void clearOverridingContainingBlockContentSize();
     void clearOverridingContainingBlockContentLogicalHeight();
 
+    // These are currently only used by Flexbox code. In some cases we must layout flex items with a different main size
+    // (the size in the main direction) than the one specified by the item in order to compute the value of flex basis, i.e.,
+    // the initial main size of the flex item before the free space is distributed.
+    Length overridingLogicalHeightLength() const;
+    Length overridingLogicalWidthLength() const;
+    void setOverridingLogicalHeightLength(const Length&);
+    void setOverridingLogicalWidthLength(const Length&);
+    bool hasOverridingLogicalHeightLength() const;
+    bool hasOverridingLogicalWidthLength() const;
+    void clearOverridingLogicalHeightLength();
+    void clearOverridingLogicalWidthLength();
+
     LayoutSize offsetFromContainer(RenderElement&, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override;
     
     LayoutUnit adjustBorderBoxLogicalWidthForBoxSizing(const Length& logicalWidth) const;

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (285622 => 285623)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-11-11 09:42:13 UTC (rev 285623)
@@ -1000,18 +1000,53 @@
     m_intrinsicSizeAlongMainAxis.remove(&child);
 }
 
-LayoutUnit RenderFlexibleBox::computeInnerFlexBaseSizeForChild(RenderBox& child, LayoutUnit mainAxisBorderAndPadding)
+// This is a RAII class that is used to temporarily set the flex basis as the child size in the main axis.
+class ScopedFlexBasisAsChildMainSize {
+public:
+    ScopedFlexBasisAsChildMainSize(RenderBox& child, Length flexBasis, bool mainAxisIsInlineAxis)
+        : m_child(child)
+        , m_mainAxisIsInlineAxis(mainAxisIsInlineAxis)
+    {
+        if (m_mainAxisIsInlineAxis)
+            m_child.setOverridingLogicalWidthLength(flexBasis);
+        else
+            m_child.setOverridingLogicalHeightLength(flexBasis);
+    }
+    ~ScopedFlexBasisAsChildMainSize()
+    {
+        if (m_mainAxisIsInlineAxis)
+            m_child.clearOverridingLogicalWidthLength();
+        else
+            m_child.clearOverridingLogicalHeightLength();
+    }
+
+private:
+    RenderBox& m_child;
+    bool m_mainAxisIsInlineAxis;
+};
+
+// https://drafts.csswg.org/css-flexbox/#algo-main-item
+LayoutUnit RenderFlexibleBox::computeFlexBaseSizeForChild(RenderBox& child, LayoutUnit mainAxisBorderAndPadding, bool relayoutChildren)
 {
     Length flexBasis = flexBasisForChild(child);
+    ScopedFlexBasisAsChildMainSize scoped(child, flexBasisForChild(child), mainAxisIsChildInlineAxis(child));
+
+    maybeCacheChildMainIntrinsicSize(child, relayoutChildren);
+
+    // 9.2.3 A.
     if (childMainSizeIsDefinite(child, flexBasis))
         return std::max(0_lu, computeMainAxisExtentForChild(child, MainOrPreferredSize, flexBasis).value());
 
+    // 9.2.3 B.
     if (childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(child)) {
         const Length& crossSizeLength = crossSizeLengthForChild(MainOrPreferredSize, child);
         return adjustChildSizeForAspectRatioCrossAxisMinAndMax(child, computeMainSizeFromAspectRatioUsing(child, crossSizeLength));
     }
 
-    // The flex basis is indefinite (=auto), so we need to compute the actual width of the child.
+    // FIXME: 9.2.3 C.
+    // FIXME: 9.2.3 D.
+
+    // 9.2.3 E.
     LayoutUnit mainAxisExtent;
     if (!mainAxisIsChildInlineAxis(child)) {
         ASSERT(!child.needsLayout());
@@ -1363,34 +1398,38 @@
     return childSize;
 }
 
+void RenderFlexibleBox::maybeCacheChildMainIntrinsicSize(RenderBox& child, bool relayoutChildren)
+{
+    if (!childHasIntrinsicMainAxisSize(child))
+        return;
+
+    // If this condition is true, then computeMainAxisExtentForChild will call
+    // child.intrinsicContentLogicalHeight() and child.scrollbarLogicalHeight(),
+    // so if the child has intrinsic min/max/preferred size, run layout on it now to make sure
+    // its logical height and scroll bars are up to date.
+    updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child);
+    // Don't resolve percentages in children. This is especially important for the min-height calculation,
+    // where we want percentages to be treated as auto. For flex-basis itself, this is not a problem because
+    // by definition we have an indefinite flex basis here and thus percentages should not resolve.
+    if (child.needsLayout() || !m_intrinsicSizeAlongMainAxis.contains(&child)) {
+        if (isHorizontalWritingMode() == child.isHorizontalWritingMode())
+            child.setOverridingContainingBlockContentLogicalHeight(std::nullopt);
+        else
+            child.setOverridingContainingBlockContentLogicalWidth(std::nullopt);
+        child.setChildNeedsLayout(MarkOnlyThis);
+        child.layoutIfNeeded();
+        cacheChildMainSize(child);
+        child.clearOverridingContainingBlockContentSize();
+    }
+}
+
 FlexItem RenderFlexibleBox::constructFlexItem(RenderBox& child, bool relayoutChildren)
 {
     auto childHadLayout = child.everHadLayout();
     child.clearOverridingContentSize();
-    if (childHasIntrinsicMainAxisSize(child)) {
-        // If this condition is true, then computeMainAxisExtentForChild will call
-        // child.intrinsicContentLogicalHeight() and child.scrollbarLogicalHeight(),
-        // so if the child has intrinsic min/max/preferred size, run layout on it now to make sure
-        // its logical height and scroll bars are up to date.
-        updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child);
-        // Don't resolve percentages in children. This is especially important for the min-height calculation,
-        // where we want percentages to be treated as auto. For flex-basis itself, this is not a problem because
-        // by definition we have an indefinite flex basis here and thus percentages should not resolve.
-        if (child.needsLayout() || !m_intrinsicSizeAlongMainAxis.contains(&child)) {
-            if (isHorizontalWritingMode() == child.isHorizontalWritingMode())
-                child.setOverridingContainingBlockContentLogicalHeight(std::nullopt);
-            else
-                child.setOverridingContainingBlockContentLogicalWidth(std::nullopt);
-            child.clearOverridingContentSize();
-            child.setChildNeedsLayout(MarkOnlyThis);
-            child.layoutIfNeeded();
-            cacheChildMainSize(child);
-            child.clearOverridingContainingBlockContentSize();
-        }
-    }
     
     LayoutUnit borderAndPadding = isHorizontalFlow() ? child.horizontalBorderAndPaddingExtent() : child.verticalBorderAndPaddingExtent();
-    LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(child, borderAndPadding);
+    LayoutUnit childInnerFlexBaseSize = computeFlexBaseSizeForChild(child, borderAndPadding, relayoutChildren);
     LayoutUnit margin = isHorizontalFlow() ? child.horizontalMarginExtent() : child.verticalMarginExtent();
     return FlexItem(child, childInnerFlexBaseSize, borderAndPadding, margin, computeFlexItemMinMaxSizes(child), childHadLayout);
 }

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (285622 => 285623)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-11-11 08:21:51 UTC (rev 285622)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-11-11 09:42:13 UTC (rev 285623)
@@ -150,7 +150,8 @@
     void computeChildIntrinsicLogicalWidths(RenderObject&, LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
     LayoutUnit computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const;
     void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
-    LayoutUnit computeInnerFlexBaseSizeForChild(RenderBox& child, LayoutUnit mainAxisBorderAndPadding);
+    LayoutUnit computeFlexBaseSizeForChild(RenderBox& child, LayoutUnit mainAxisBorderAndPadding, bool relayoutChildren);
+    void maybeCacheChildMainIntrinsicSize(RenderBox& child, bool relayoutChildren);
     void adjustAlignmentForChild(RenderBox& child, LayoutUnit);
     ItemPosition alignmentForChild(const RenderBox& child) const;
     bool canComputePercentageFlexBasis(const RenderBox& child, const Length& flexBasis, UpdatePercentageHeightDescendants);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to