Title: [279286] trunk
Revision
279286
Author
[email protected]
Date
2021-06-25 08:42:07 -0700 (Fri, 25 Jun 2021)

Log Message

[css-flexbox] Improve computation of intrinsic sizes of flex items with aspect ratio
https://bugs.webkit.org/show_bug.cgi?id=227395

Reviewed by Rob Buis.

Source/WebCore:

Before computing the intrinsic sizes of flex items we first clear the overriding sizes of the item
that might have been set before in order to get the proper intrinsic size. However there is one
situation in which having an overriding size is desirable and it's when the cross size should
be set to the flex container's definite cross size. That's one of the exceptions for definite/indefinite
sizes mentioned in the specs (see https://drafts.csswg.org/css-flexbox/#definite-sizes).

In the aforementioned case we should temporarily set that overriding size in the cross axis so that
the intrinsic size could be computed with that constrain.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::computeChildIntrinsicLogicalWidths const): Set the overriding size
in the cross axis to compute the intrinsic size.
(WebCore::RenderFlexibleBox::computeMainSizeFromAspectRatioUsing const):
(WebCore::RenderFlexibleBox::childCrossSizeShouldUseContainerCrossSize const): Added a missing check,
the cross size of the child must be auto, otherwise the rule does not apply.
(WebCore::RenderFlexibleBox::computeCrossSizeForChildUsingContainerCrossSize const): Refactored from
computeMainSizeFromAspectRatioUsing() as it's now used in two different places.
* rendering/RenderFlexibleBox.h:

LayoutTests:

* TestExpectations: Unskipped 3 tests that are now passing.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (279285 => 279286)


--- trunk/LayoutTests/ChangeLog	2021-06-25 15:39:12 UTC (rev 279285)
+++ trunk/LayoutTests/ChangeLog	2021-06-25 15:42:07 UTC (rev 279286)
@@ -1,3 +1,12 @@
+2021-06-25  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Improve computation of intrinsic sizes of flex items with aspect ratio
+        https://bugs.webkit.org/show_bug.cgi?id=227395
+
+        Reviewed by Rob Buis.
+
+        * TestExpectations: Unskipped 3 tests that are now passing.
+
 2021-06-17  Sergio Villar Senin  <[email protected]>
 
         Nullptr crash in StyledMarkupAccumulator::traverseNodesForSerialization

Modified: trunk/LayoutTests/TestExpectations (279285 => 279286)


--- trunk/LayoutTests/TestExpectations	2021-06-25 15:39:12 UTC (rev 279285)
+++ trunk/LayoutTests/TestExpectations	2021-06-25 15:42:07 UTC (rev 279286)
@@ -3952,12 +3952,9 @@
 
 webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-img-column-015.html [ ImageOnlyFailure ]
 webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-img-row-010.html [ ImageOnlyFailure ]
-webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-001.html [ ImageOnlyFailure ]
 webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-002.html [ ImageOnlyFailure ]
-webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-003.html [ ImageOnlyFailure ]
 webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-004.html [ ImageOnlyFailure ]
 webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-005.html [ ImageOnlyFailure ]
-webkit.org/b/219343 imported/w3c/web-platform-tests/css/css-flexbox/aspect-ratio-intrinsic-size-006.html [ ImageOnlyFailure ]
 
 webkit.org/b/145176 imported/w3c/web-platform-tests/css/css-flexbox/flexbox_align-items-stretch-3.html [ ImageOnlyFailure ]
 webkit.org/b/210093 imported/w3c/web-platform-tests/css/css-flexbox/select-element-zero-height-001.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (279285 => 279286)


--- trunk/Source/WebCore/ChangeLog	2021-06-25 15:39:12 UTC (rev 279285)
+++ trunk/Source/WebCore/ChangeLog	2021-06-25 15:42:07 UTC (rev 279286)
@@ -1,3 +1,29 @@
+2021-06-25  Sergio Villar Senin  <[email protected]>
+
+        [css-flexbox] Improve computation of intrinsic sizes of flex items with aspect ratio
+        https://bugs.webkit.org/show_bug.cgi?id=227395
+
+        Reviewed by Rob Buis.
+
+        Before computing the intrinsic sizes of flex items we first clear the overriding sizes of the item
+        that might have been set before in order to get the proper intrinsic size. However there is one
+        situation in which having an overriding size is desirable and it's when the cross size should
+        be set to the flex container's definite cross size. That's one of the exceptions for definite/indefinite
+        sizes mentioned in the specs (see https://drafts.csswg.org/css-flexbox/#definite-sizes).
+
+        In the aforementioned case we should temporarily set that overriding size in the cross axis so that
+        the intrinsic size could be computed with that constrain.
+
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::computeChildIntrinsicLogicalWidths const): Set the overriding size
+        in the cross axis to compute the intrinsic size.
+        (WebCore::RenderFlexibleBox::computeMainSizeFromAspectRatioUsing const):
+        (WebCore::RenderFlexibleBox::childCrossSizeShouldUseContainerCrossSize const): Added a missing check,
+        the cross size of the child must be auto, otherwise the rule does not apply.
+        (WebCore::RenderFlexibleBox::computeCrossSizeForChildUsingContainerCrossSize const): Refactored from
+        computeMainSizeFromAspectRatioUsing() as it's now used in two different places.
+        * rendering/RenderFlexibleBox.h:
+
 2021-06-25  Philippe Normand  <[email protected]>
 
         [GStreamer] TextCombiner has unlinked internal encoders

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (279285 => 279286)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-06-25 15:39:12 UTC (rev 279285)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2021-06-25 15:42:07 UTC (rev 279286)
@@ -212,6 +212,16 @@
     ASSERT(childObject.isBox());
     RenderBox& child = downcast<RenderBox>(childObject);
 
+    // If the item cross size should use the definite container cross size then set the overriding size now so
+    // the intrinsic sizes are properly computed in the presence of aspect ratios. The only exception is when
+    // we are both a flex item&container, because our parent might have already set our overriding size.
+    if (childCrossSizeShouldUseContainerCrossSize(child) && !isFlexItem()) {
+        auto axis = mainAxisIsChildInlineAxis(child) ? OverridingSizesScope::Axis::Block : OverridingSizesScope::Axis::Inline;
+        OverridingSizesScope overridingSizeScope(child, axis, computeCrossSizeForChildUsingContainerCrossSize(child));
+        RenderBlock::computeChildIntrinsicLogicalWidths(childObject, minPreferredLogicalWidth, maxPreferredLogicalWidth);
+        return;
+    }
+
     OverridingSizesScope cleanOverridingSizesScope(child, OverridingSizesScope::Axis::Both);
     RenderBlock::computeChildIntrinsicLogicalWidths(childObject, minPreferredLogicalWidth, maxPreferredLogicalWidth);
 }
@@ -869,13 +879,9 @@
     std::optional<LayoutUnit> crossSize;
     if (crossSizeLength.isFixed())
         crossSize = adjustForBoxSizing(child, crossSizeLength);
-    else if (crossSizeLength.isAuto()) {
-        ASSERT(childCrossSizeShouldUseContainerCrossSize(child));
-        auto containerCrossSizeLength = isHorizontalFlow() ? style().height() : style().width();
-        // Keep this sync'ed with childCrossSizeShouldUseContainerCrossSize().
-        ASSERT(containerCrossSizeLength.isFixed());
-        crossSize = std::max(0_lu, valueForLength(containerCrossSizeLength, -1_lu) - crossAxisMarginExtentForChild(child));
-    } else {
+    else if (crossSizeLength.isAuto())
+        crossSize = computeCrossSizeForChildUsingContainerCrossSize(child);
+    else {
         ASSERT(crossSizeLength.isPercentOrCalculated());
         crossSize = mainAxisIsChildInlineAxis(child) ? child.computePercentageLogicalHeight(crossSizeLength) : adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(crossSizeLength, contentWidth()), crossSizeLength.type());
         if (!crossSize)
@@ -948,7 +954,7 @@
     // 1. If a single-line flex container has a definite cross size, the automatic preferred outer cross size of any
     // stretched flex items is the flex container's inner cross size (clamped to the flex item's min and max cross size)
     // and is considered definite.
-    if (!isMultiline() && alignmentForChild(child) == ItemPosition::Stretch && !hasAutoMarginsInCrossAxis(child)) {
+    if (!isMultiline() && alignmentForChild(child) == ItemPosition::Stretch && !hasAutoMarginsInCrossAxis(child) && crossSizeLengthForChild(MainOrPreferredSize, child).isAuto()) {
         // This must be kept in sync with computeMainSizeFromAspectRatioUsing().
         // FIXME: so far we're only considered fixed sizes but we should extend it to other definite sizes.
         auto& crossSize = isHorizontalFlow() ? style().height() : style().width();
@@ -1667,6 +1673,15 @@
     return positionChanged;
 }
 
+// This refers to https://drafts.csswg.org/css-flexbox-1/#definite-sizes, section 1).
+LayoutUnit RenderFlexibleBox::computeCrossSizeForChildUsingContainerCrossSize(const RenderBox& child) const
+{
+    auto containerCrossSizeLength = isHorizontalFlow() ? style().height() : style().width();
+    // Keep this sync'ed with childCrossSizeShouldUseContainerCrossSize().
+    ASSERT(containerCrossSizeLength.isFixed());
+    return std::max(0_lu, valueForLength(containerCrossSizeLength, -1_lu) - crossAxisMarginExtentForChild(child));
+}
+
 void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox& child)
 {
     ASSERT(child.isOutOfFlowPositioned());

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (279285 => 279286)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-06-25 15:39:12 UTC (rev 279285)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2021-06-25 15:42:07 UTC (rev 279286)
@@ -145,6 +145,7 @@
     bool childHasComputableAspectRatio(const RenderBox&) const;
     bool childHasComputableAspectRatioAndCrossSizeIsConsideredDefinite(const RenderBox&);
     bool childCrossSizeShouldUseContainerCrossSize(const RenderBox& child) const;
+    LayoutUnit computeCrossSizeForChildUsingContainerCrossSize(const RenderBox& child) const;
     void computeChildIntrinsicLogicalWidths(RenderObject&, LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
     LayoutUnit computeMainSizeFromAspectRatioUsing(const RenderBox& child, Length crossSizeLength) const;
     void setFlowAwareLocationForChild(RenderBox& child, const LayoutPoint&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to