Title: [274708] trunk/Source/WebCore
Revision
274708
Author
[email protected]
Date
2021-03-19 02:14:52 -0700 (Fri, 19 Mar 2021)

Log Message

[css-flex] Make {main|cross}SizeForPercentageResolution() return booleans instead of actual sizes
https://bugs.webkit.org/show_bug.cgi?id=223377

Reviewed by Manuel Rego Casasnovas.

These two methods were only called by childLogicalHeightForPercentageResolution() and they either returned
WTF::nullopt or the overridingContentLogicalHeight(). We could simplify a bit the code by returning a boolean
which means whether the overriding content logical height should be used to resolve a percentage or not. Apart
from changing the return value we're also improving the naming so it becomes obvious that we are dealing with
flex items and not the flex container.

We're also removing some comments in those methods that were not really accurate.

No new tests as there is no change in functionality.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::availableLogicalHeightForPercentageComputation const):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::computeReplacedLogicalHeightUsing const):
(WebCore::RenderBox::availableLogicalHeightUsing const):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::hasAutoHeightOrContainingBlockWithAutoHeight const):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::useChildOverridingCrossSizeForPercentageResolution): Renamed from crossSizeForPercentageResolution.
(WebCore::RenderFlexibleBox::useChildOverridingMainSizeForPercentageResolution): Renamed from mainSizeForPercentageResolution.
(WebCore::RenderFlexibleBox::useChildOverridingLogicalHeightForPercentageResolution): Renamed from childLogicalHeightForPercentageResolution.
(WebCore::RenderFlexibleBox::crossSizeForPercentageResolution): Deleted.
(WebCore::RenderFlexibleBox::mainSizeForPercentageResolution): Deleted.
(WebCore::RenderFlexibleBox::childLogicalHeightForPercentageResolution): Deleted.
* rendering/RenderFlexibleBox.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274707 => 274708)


--- trunk/Source/WebCore/ChangeLog	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/ChangeLog	2021-03-19 09:14:52 UTC (rev 274708)
@@ -1,3 +1,36 @@
+2021-03-17  Sergio Villar Senin  <[email protected]>
+
+        [css-flex] Make {main|cross}SizeForPercentageResolution() return booleans instead of actual sizes
+        https://bugs.webkit.org/show_bug.cgi?id=223377
+
+        Reviewed by Manuel Rego Casasnovas.
+
+        These two methods were only called by childLogicalHeightForPercentageResolution() and they either returned
+        WTF::nullopt or the overridingContentLogicalHeight(). We could simplify a bit the code by returning a boolean
+        which means whether the overriding content logical height should be used to resolve a percentage or not. Apart
+        from changing the return value we're also improving the naming so it becomes obvious that we are dealing with
+        flex items and not the flex container.
+
+        We're also removing some comments in those methods that were not really accurate.
+
+        No new tests as there is no change in functionality.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::availableLogicalHeightForPercentageComputation const):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::computeReplacedLogicalHeightUsing const):
+        (WebCore::RenderBox::availableLogicalHeightUsing const):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::hasAutoHeightOrContainingBlockWithAutoHeight const):
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::useChildOverridingCrossSizeForPercentageResolution): Renamed from crossSizeForPercentageResolution.
+        (WebCore::RenderFlexibleBox::useChildOverridingMainSizeForPercentageResolution): Renamed from mainSizeForPercentageResolution.
+        (WebCore::RenderFlexibleBox::useChildOverridingLogicalHeightForPercentageResolution): Renamed from childLogicalHeightForPercentageResolution.
+        (WebCore::RenderFlexibleBox::crossSizeForPercentageResolution): Deleted.
+        (WebCore::RenderFlexibleBox::mainSizeForPercentageResolution): Deleted.
+        (WebCore::RenderFlexibleBox::childLogicalHeightForPercentageResolution): Deleted.
+        * rendering/RenderFlexibleBox.h:
+
 2021-03-19  Diego Pino Garcia  <[email protected]>
 
         Unreviewed, fix WPE debug build after r274695

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (274707 => 274708)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2021-03-19 09:14:52 UTC (rev 274708)
@@ -3207,12 +3207,8 @@
     // that can be used for any percentage computations.
     bool isOutOfFlowPositionedWithSpecifiedHeight = isOutOfFlowPositioned() && (!styleToUse.logicalHeight().isAuto() || (!styleToUse.logicalTop().isAuto() && !styleToUse.logicalBottom().isAuto()));
     
-    Optional<LayoutUnit> stretchedFlexHeight;
-    if (isFlexItem())
-        stretchedFlexHeight = downcast<RenderFlexibleBox>(parent())->childLogicalHeightForPercentageResolution(*this);
-    
-    if (stretchedFlexHeight)
-        availableHeight = stretchedFlexHeight;
+    if (isFlexItem() && downcast<RenderFlexibleBox>(parent())->useChildOverridingLogicalHeightForPercentageResolution(*this))
+        availableHeight = overridingContentLogicalHeight();
     else if (isGridItem() && hasOverridingLogicalHeight())
         availableHeight = overridingContentLogicalHeight();
     else if (styleToUse.logicalHeight().isFixed()) {

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (274707 => 274708)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2021-03-19 09:14:52 UTC (rev 274708)
@@ -3311,8 +3311,8 @@
         if (is<RenderBlock>(container)) {
             auto* block = downcast<RenderBlock>(container);
             block->addPercentHeightDescendant(*const_cast<RenderBox*>(this));
-            if (block->isFlexItem())
-                stretchedHeight = downcast<RenderFlexibleBox>(block->parent())->childLogicalHeightForPercentageResolution(*block);
+            if (block->isFlexItem() && downcast<RenderFlexibleBox>(block->parent())->useChildOverridingLogicalHeightForPercentageResolution(*block))
+                stretchedHeight = block->overridingContentLogicalHeight();
             else if (block->isGridItem() && block->hasOverridingLogicalHeight() && !hasPerpendicularContainingBlock)
                 stretchedHeight = block->overridingContentLogicalHeight();
         }
@@ -3384,12 +3384,8 @@
         return logicalHeight() - borderAndPaddingLogicalHeight();
     }
 
-    if (isFlexItem()) {
-        auto& flexBox = downcast<RenderFlexibleBox>(*parent());
-        auto stretchedHeight = flexBox.childLogicalHeightForPercentageResolution(*this);
-        if (stretchedHeight)
-            return stretchedHeight.value();
-    }
+    if (isFlexItem() && downcast<RenderFlexibleBox>(*parent()).useChildOverridingLogicalHeightForPercentageResolution(*this))
+        return overridingContentLogicalHeight();
 
     if (shouldComputeLogicalHeightFromAspectRatio())
         return blockSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), LayoutUnit(style().logicalAspectRatio()), style().boxSizingForAspectRatio(), logicalWidth());

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (274707 => 274708)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2021-03-19 09:14:52 UTC (rev 274708)
@@ -275,11 +275,8 @@
     if (logicalHeightLength.isPercentOrCalculated() && cb && isBox())
         cb->addPercentHeightDescendant(*const_cast<RenderBox*>(downcast<RenderBox>(this)));
 
-    if (thisBox && thisBox->isFlexItem()) {
-        auto& flexBox = downcast<RenderFlexibleBox>(*parent());
-        if (flexBox.childLogicalHeightForPercentageResolution(*thisBox))
-            return false;
-    }
+    if (thisBox && thisBox->isFlexItem() && downcast<RenderFlexibleBox>(*parent()).useChildOverridingLogicalHeightForPercentageResolution(*thisBox))
+        return false;
     
     if (thisBox && thisBox->isGridItem() && thisBox->hasOverridingContainingBlockContentLogicalHeight())
         return thisBox->overridingContainingBlockContentLogicalHeight() == WTF::nullopt;

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (274707 => 274708)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-03-19 09:14:52 UTC (rev 274708)
@@ -1234,26 +1234,16 @@
     return std::max(0_lu, childSize);
 }
     
-Optional<LayoutUnit> RenderFlexibleBox::crossSizeForPercentageResolution(const RenderBox& child)
+bool RenderFlexibleBox::useChildOverridingCrossSizeForPercentageResolution(const RenderBox& child)
 {
     ASSERT(mainAxisIsChildInlineAxis(child));
     if (alignmentForChild(child) != ItemPosition::Stretch)
-        return WTF::nullopt;
+        return false;
 
-    // Here we implement https://drafts.csswg.org/css-flexbox/#algo-stretch
-    if (child.hasOverridingLogicalHeight())
-        return child.overridingContentLogicalHeight();
-
-    // We don't currently implement the optimization from
-    // https://drafts.csswg.org/css-flexbox/#definite-sizes case 1. While that
-    // could speed up a specialized case, it requires determining if we have a
-    // definite size, which itself is not cheap. We can consider implementing it
-    // at a later time. (The correctness is ensured by redoing layout in
-    // applyStretchAlignmentToChild)
-    return WTF::nullopt;
+    return child.hasOverridingLogicalHeight();
 }
 
-Optional<LayoutUnit> RenderFlexibleBox::mainSizeForPercentageResolution(const RenderBox& child)
+bool RenderFlexibleBox::useChildOverridingMainSizeForPercentageResolution(const RenderBox& child)
 {
     ASSERT(!mainAxisIsChildInlineAxis(child));
     // This function implements section 9.8. Definite and Indefinite Sizes, case 2) of the flexbox spec.
@@ -1260,16 +1250,16 @@
     // If the flex container has a definite main size the flex item post-flexing main size is also treated
     // as definite. We make up a percentage to check whether we have a definite size.
     if (!childMainSizeIsDefinite(child, Length(0, LengthType::Percent)))
-        return WTF::nullopt;
+        return false;
 
-    return child.hasOverridingLogicalHeight() ? Optional<LayoutUnit>(child.overridingContentLogicalHeight()) : WTF::nullopt;
+    return child.hasOverridingLogicalHeight();
 }
 
-Optional<LayoutUnit> RenderFlexibleBox::childLogicalHeightForPercentageResolution(const RenderBox& child)
+bool RenderFlexibleBox::useChildOverridingLogicalHeightForPercentageResolution(const RenderBox& child)
 {
     if (mainAxisIsChildInlineAxis(child))
-        return crossSizeForPercentageResolution(child);
-    return mainSizeForPercentageResolution(child);
+        return useChildOverridingCrossSizeForPercentageResolution(child);
+    return useChildOverridingMainSizeForPercentageResolution(child);
 }
 
 LayoutUnit RenderFlexibleBox::adjustChildSizeForAspectRatioCrossAxisMinAndMax(const RenderBox& child, LayoutUnit childSize)

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (274707 => 274708)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-03-19 09:06:52 UTC (rev 274707)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-03-19 09:14:52 UTC (rev 274708)
@@ -69,7 +69,7 @@
 
     virtual bool isFlexibleBoxImpl() const { return false; };
     
-    Optional<LayoutUnit> childLogicalHeightForPercentageResolution(const RenderBox&);
+    bool useChildOverridingLogicalHeightForPercentageResolution(const RenderBox&);
     
     void clearCachedMainSizeForChild(const RenderBox& child);
     
@@ -156,8 +156,8 @@
     Overflow mainAxisOverflowForChild(const RenderBox& child) const;
     Overflow crossAxisOverflowForChild(const RenderBox& child) const;
     void cacheChildMainSize(const RenderBox& child);
-    Optional<LayoutUnit> crossSizeForPercentageResolution(const RenderBox&);
-    Optional<LayoutUnit> mainSizeForPercentageResolution(const RenderBox&);
+    bool useChildOverridingCrossSizeForPercentageResolution(const RenderBox&);
+    bool useChildOverridingMainSizeForPercentageResolution(const RenderBox&);
 
     void layoutFlexItems(bool relayoutChildren);
     LayoutUnit autoMarginOffsetInMainAxis(const Vector<FlexItem>&, LayoutUnit& availableFreeSpace);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to