Title: [280631] trunk
Revision
280631
Author
[email protected]
Date
2021-08-04 03:57:08 -0700 (Wed, 04 Aug 2021)

Log Message

REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
https://bugs.webkit.org/show_bug.cgi?id=228076

Reviewed by Antti Koivisto.

Source/WebCore:

The image get stretched because constrainLogicalWidthInFragmentByMinMax returns the intrinsic width while computing MinSize.
According to [1], the box's minimum width is its min-content size not the MinIntrinsic width which is used because of
the recursion. To break the recursion, computeIntrinsicLogicalWidthUsing calls computeLogicalWidthFromAspectRatioInternal instead,
then checks children's width.

[1] https://www.w3.org/TR/css-sizing-4/#aspect-ratio-minimum

* rendering/RenderBox.cpp:
(WebCore::RenderBox::constrainLogicalWidthInFragmentByMinMax const): If shouldComputeLogicalWidthFromAspectRatio,
the length should be treated as MinContent not MinIntrinsic.
(WebCore::RenderBox::computeIntrinsicLogicalWidthUsing const): To break the loop, call computeLogicalWidthFromAspectRatioInternal instead
to get the width from aspect-ratio and if there is child, make sure the min/max logical width not less than content's width.
(WebCore::RenderBox::computeLogicalWidthFromAspectRatioInternal const):
(WebCore::RenderBox::computeLogicalWidthFromAspectRatio const):
* rendering/RenderBox.h:

LayoutTests:

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (280630 => 280631)


--- trunk/LayoutTests/ChangeLog	2021-08-04 09:40:46 UTC (rev 280630)
+++ trunk/LayoutTests/ChangeLog	2021-08-04 10:57:08 UTC (rev 280631)
@@ -1,3 +1,12 @@
+2021-08-04  Cathie Chen  <[email protected]>
+
+        REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
+        https://bugs.webkit.org/show_bug.cgi?id=228076
+
+        Reviewed by Antti Koivisto.
+
+        * TestExpectations:
+
 2021-08-04  Tim Horton  <[email protected]>
 
         fast/canvas/canvas-crash.html doesn't test what it intends to on iOS

Modified: trunk/LayoutTests/TestExpectations (280630 => 280631)


--- trunk/LayoutTests/TestExpectations	2021-08-04 09:40:46 UTC (rev 280630)
+++ trunk/LayoutTests/TestExpectations	2021-08-04 10:57:08 UTC (rev 280631)
@@ -4711,8 +4711,6 @@
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-022.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-025.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-026.html [ ImageOnlyFailure ]
-webkit.org/b/228076 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-027.html [ ImageOnlyFailure ]
-webkit.org/b/228076 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-028.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-001.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-002.html [ ImageOnlyFailure ]
 webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-003.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (280630 => 280631)


--- trunk/Source/WebCore/ChangeLog	2021-08-04 09:40:46 UTC (rev 280630)
+++ trunk/Source/WebCore/ChangeLog	2021-08-04 10:57:08 UTC (rev 280631)
@@ -1,3 +1,26 @@
+2021-08-04  Cathie Chen  <[email protected]>
+
+        REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
+        https://bugs.webkit.org/show_bug.cgi?id=228076
+
+        Reviewed by Antti Koivisto.
+
+        The image get stretched because constrainLogicalWidthInFragmentByMinMax returns the intrinsic width while computing MinSize.
+        According to [1], the box's minimum width is its min-content size not the MinIntrinsic width which is used because of
+        the recursion. To break the recursion, computeIntrinsicLogicalWidthUsing calls computeLogicalWidthFromAspectRatioInternal instead,
+        then checks children's width.
+
+        [1] https://www.w3.org/TR/css-sizing-4/#aspect-ratio-minimum
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::constrainLogicalWidthInFragmentByMinMax const): If shouldComputeLogicalWidthFromAspectRatio,
+        the length should be treated as MinContent not MinIntrinsic.
+        (WebCore::RenderBox::computeIntrinsicLogicalWidthUsing const): To break the loop, call computeLogicalWidthFromAspectRatioInternal instead
+        to get the width from aspect-ratio and if there is child, make sure the min/max logical width not less than content's width.
+        (WebCore::RenderBox::computeLogicalWidthFromAspectRatioInternal const):
+        (WebCore::RenderBox::computeLogicalWidthFromAspectRatio const):
+        * rendering/RenderBox.h:
+
 2021-08-04  Tim Horton  <[email protected]>
 
         fast/canvas/canvas-crash.html doesn't test what it intends to on iOS

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (280630 => 280631)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2021-08-04 09:40:46 UTC (rev 280630)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2021-08-04 10:57:08 UTC (rev 280631)
@@ -664,7 +664,7 @@
     if (styleToUse.hasAspectRatio() && minLength.isAuto() && (styleToUse.logicalWidth().isAuto() || styleToUse.logicalWidth().isMinContent() || styleToUse.logicalWidth().isMaxContent()) && styleToUse.overflowInlineDirection() == Overflow::Visible) {
         // Make sure we actually used the aspect ratio.
         if (shouldComputeLogicalWidthFromAspectRatio())
-            minLength = Length(LengthType::MinIntrinsic);
+            minLength = Length(LengthType::MinContent);
     }
     return std::max(logicalWidth, computeLogicalWidthInFragmentUsing(MinSize, minLength, availableWidth, cb, fragment));
 }
@@ -2696,9 +2696,16 @@
 
     LayoutUnit minLogicalWidth;
     LayoutUnit maxLogicalWidth;
-    if (!logicalWidthLength.isMinIntrinsic() && shouldComputeLogicalWidthFromAspectRatio())
-        minLogicalWidth = maxLogicalWidth = computeLogicalWidthFromAspectRatio();
-    else
+    if (!logicalWidthLength.isMinIntrinsic() && shouldComputeLogicalWidthFromAspectRatio()) {
+        minLogicalWidth = maxLogicalWidth = computeLogicalWidthFromAspectRatioInternal() - borderAndPadding;
+        if (firstChild()) {
+            LayoutUnit minChildrenLogicalWidth;
+            LayoutUnit maxChildrenLogicalWidth;
+            computeIntrinsicKeywordLogicalWidths(minChildrenLogicalWidth, maxChildrenLogicalWidth);
+            minLogicalWidth = std::max(minLogicalWidth, minChildrenLogicalWidth);
+            maxLogicalWidth = std::max(maxLogicalWidth, maxChildrenLogicalWidth);
+        }
+    } else
         computeIntrinsicKeywordLogicalWidths(minLogicalWidth, maxLogicalWidth);
 
     if (logicalWidthLength.isMinContent() || logicalWidthLength.isMinIntrinsic())
@@ -5302,14 +5309,18 @@
     return hasOverridingLogicalHeight() || shouldComputeLogicalWidthFromAspectRatioAndInsets(*this) || style().logicalHeight().isFixed() || isResolvablePercentageHeight();
 }
 
-LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
+LayoutUnit RenderBox::computeLogicalWidthFromAspectRatioInternal() const
 {
     ASSERT(shouldComputeLogicalWidthFromAspectRatio());
     auto computedValues = computeLogicalHeight(logicalHeight(), logicalTop());
     LayoutUnit logicalHeightforAspectRatio = computedValues.m_extent;
 
-    auto logicalWidth = inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), LayoutUnit(style().logicalAspectRatio()), style().boxSizingForAspectRatio(), logicalHeightforAspectRatio);
+    return inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), LayoutUnit(style().logicalAspectRatio()), style().boxSizingForAspectRatio(), logicalHeightforAspectRatio);
+}
 
+LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
+{
+    auto logicalWidth = computeLogicalWidthFromAspectRatioInternal();
     LayoutUnit containerWidthInInlineDirection = std::max<LayoutUnit>(0, containingBlockLogicalWidthForContentInFragment(fragment));
     return constrainLogicalWidthInFragmentByMinMax(logicalWidth, containerWidthInInlineDirection, *containingBlock(), fragment, AllowIntrinsic::No);
 }

Modified: trunk/Source/WebCore/rendering/RenderBox.h (280630 => 280631)


--- trunk/Source/WebCore/rendering/RenderBox.h	2021-08-04 09:40:46 UTC (rev 280630)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2021-08-04 10:57:08 UTC (rev 280631)
@@ -709,6 +709,7 @@
 
     bool shouldIgnoreAspectRatio() const;
     bool shouldComputeLogicalWidthFromAspectRatio() const;
+    LayoutUnit computeLogicalWidthFromAspectRatioInternal() const;
     LayoutUnit computeLogicalWidthFromAspectRatio(RenderFragmentContainer* = nullptr) const;
     std::pair<LayoutUnit, LayoutUnit> computeMinMaxLogicalWidthFromAspectRatio() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to