⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280631 in webkit


Ignore:
Timestamp:
Aug 4, 2021, 3:57:08 AM (5 years ago)
Author:
cathiechen
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:

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r280630 r280631  
     12021-08-04  Cathie Chen  <cathiechen@igalia.com>
     2
     3        REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
     4        https://bugs.webkit.org/show_bug.cgi?id=228076
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * TestExpectations:
     9
    1102021-08-04  Tim Horton  <timothy_horton@apple.com>
    211
  • trunk/LayoutTests/TestExpectations

    r280592 r280631  
    47124712webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-025.html [ ImageOnlyFailure ]
    47134713webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-026.html [ ImageOnlyFailure ]
    4714 webkit.org/b/228076 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-027.html [ ImageOnlyFailure ]
    4715 webkit.org/b/228076 imported/w3c/web-platform-tests/css/css-sizing/aspect-ratio/flex-aspect-ratio-028.html [ ImageOnlyFailure ]
    47164714webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-001.html [ ImageOnlyFailure ]
    47174715webkit.org/b/214463 imported/w3c/web-platform-tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-002.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r280630 r280631  
     12021-08-04  Cathie Chen  <cathiechen@igalia.com>
     2
     3        REGRESSION (r277997) Images get stretched with aspect-ratio and max-width: x%
     4        https://bugs.webkit.org/show_bug.cgi?id=228076
     5
     6        Reviewed by Antti Koivisto.
     7
     8        The image get stretched because constrainLogicalWidthInFragmentByMinMax returns the intrinsic width while computing MinSize.
     9        According to [1], the box's minimum width is its min-content size not the MinIntrinsic width which is used because of
     10        the recursion. To break the recursion, computeIntrinsicLogicalWidthUsing calls computeLogicalWidthFromAspectRatioInternal instead,
     11        then checks children's width.
     12
     13        [1] https://www.w3.org/TR/css-sizing-4/#aspect-ratio-minimum
     14
     15        * rendering/RenderBox.cpp:
     16        (WebCore::RenderBox::constrainLogicalWidthInFragmentByMinMax const): If shouldComputeLogicalWidthFromAspectRatio,
     17        the length should be treated as MinContent not MinIntrinsic.
     18        (WebCore::RenderBox::computeIntrinsicLogicalWidthUsing const): To break the loop, call computeLogicalWidthFromAspectRatioInternal instead
     19        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.
     20        (WebCore::RenderBox::computeLogicalWidthFromAspectRatioInternal const):
     21        (WebCore::RenderBox::computeLogicalWidthFromAspectRatio const):
     22        * rendering/RenderBox.h:
     23
    1242021-08-04  Tim Horton  <timothy_horton@apple.com>
    225
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r280509 r280631  
    665665        // Make sure we actually used the aspect ratio.
    666666        if (shouldComputeLogicalWidthFromAspectRatio())
    667             minLength = Length(LengthType::MinIntrinsic);
     667            minLength = Length(LengthType::MinContent);
    668668    }
    669669    return std::max(logicalWidth, computeLogicalWidthInFragmentUsing(MinSize, minLength, availableWidth, cb, fragment));
     
    26972697    LayoutUnit minLogicalWidth;
    26982698    LayoutUnit maxLogicalWidth;
    2699     if (!logicalWidthLength.isMinIntrinsic() && shouldComputeLogicalWidthFromAspectRatio())
    2700         minLogicalWidth = maxLogicalWidth = computeLogicalWidthFromAspectRatio();
    2701     else
     2699    if (!logicalWidthLength.isMinIntrinsic() && shouldComputeLogicalWidthFromAspectRatio()) {
     2700        minLogicalWidth = maxLogicalWidth = computeLogicalWidthFromAspectRatioInternal() - borderAndPadding;
     2701        if (firstChild()) {
     2702            LayoutUnit minChildrenLogicalWidth;
     2703            LayoutUnit maxChildrenLogicalWidth;
     2704            computeIntrinsicKeywordLogicalWidths(minChildrenLogicalWidth, maxChildrenLogicalWidth);
     2705            minLogicalWidth = std::max(minLogicalWidth, minChildrenLogicalWidth);
     2706            maxLogicalWidth = std::max(maxLogicalWidth, maxChildrenLogicalWidth);
     2707        }
     2708    } else
    27022709        computeIntrinsicKeywordLogicalWidths(minLogicalWidth, maxLogicalWidth);
    27032710
     
    53035310}
    53045311
    5305 LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
     5312LayoutUnit RenderBox::computeLogicalWidthFromAspectRatioInternal() const
    53065313{
    53075314    ASSERT(shouldComputeLogicalWidthFromAspectRatio());
     
    53095316    LayoutUnit logicalHeightforAspectRatio = computedValues.m_extent;
    53105317
    5311     auto logicalWidth = inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), LayoutUnit(style().logicalAspectRatio()), style().boxSizingForAspectRatio(), logicalHeightforAspectRatio);
    5312 
     5318    return inlineSizeFromAspectRatio(horizontalBorderAndPaddingExtent(), verticalBorderAndPaddingExtent(), LayoutUnit(style().logicalAspectRatio()), style().boxSizingForAspectRatio(), logicalHeightforAspectRatio);
     5319}
     5320
     5321LayoutUnit RenderBox::computeLogicalWidthFromAspectRatio(RenderFragmentContainer* fragment) const
     5322{
     5323    auto logicalWidth = computeLogicalWidthFromAspectRatioInternal();
    53135324    LayoutUnit containerWidthInInlineDirection = std::max<LayoutUnit>(0, containingBlockLogicalWidthForContentInFragment(fragment));
    53145325    return constrainLogicalWidthInFragmentByMinMax(logicalWidth, containerWidthInInlineDirection, *containingBlock(), fragment, AllowIntrinsic::No);
  • trunk/Source/WebCore/rendering/RenderBox.h

    r280075 r280631  
    710710    bool shouldIgnoreAspectRatio() const;
    711711    bool shouldComputeLogicalWidthFromAspectRatio() const;
     712    LayoutUnit computeLogicalWidthFromAspectRatioInternal() const;
    712713    LayoutUnit computeLogicalWidthFromAspectRatio(RenderFragmentContainer* = nullptr) const;
    713714    std::pair<LayoutUnit, LayoutUnit> computeMinMaxLogicalWidthFromAspectRatio() const;
Note: See TracChangeset for help on using the changeset viewer.