Changeset 286100 in webkit


Ignore:
Timestamp:
Nov 21, 2021 10:22:01 AM (8 months ago)
Author:
Ziran Sun
Message:

[css-grid] svg image as grid items should use the overriding logical width/height when defined to compute the logical height/width
https://bugs.webkit.org/show_bug.cgi?id=228105

Reviewed by Javier Fernandez.

Source/WebCore:

This is a reland of r280290. It's got reverted because another patch r280078 caused crash and had been
reverted. r280290 is a dependent patch for r280078.

As discussed at https://github.com/w3c/csswg-drafts/issues/6286#issuecomment-866986544, degenerate
aspect ratios derived from SVG width/height attributes fall back to viewbox aspect ratio
(whether due to negative values or zero values).

When computing the logical height/width using an intrinsic aspect ratio, RenderReplaced uses the
overridingLogicalWidth/overridingLogicalHeight whenever defined as long as the flex or
grid item has an intrinsic size. For an SVG graphic though, it's common to have an intrinsic aspect
ratio but not to have an intrinsic width or height. For this special case, we still should use
overridingLogicalWidth/overridingLogicalHeight for logical height/width calculations.

  • rendering/RenderReplaced.cpp:

(WebCore::hasIntrinsicSize):
(WebCore::RenderReplaced::computeReplacedLogicalWidth const):
(WebCore::RenderReplaced::computeReplacedLogicalHeight const):

LayoutTests:

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r286094 r286100  
     12021-11-21  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] svg image as grid items should use the overriding logical width/height when defined to compute the logical height/width
     4        https://bugs.webkit.org/show_bug.cgi?id=228105
     5
     6        Reviewed by Javier Fernandez.
     7
     8        * TestExpectations: unskip two tests that are now passing.
     9
    1102021-11-20  Carlos Garcia Campos  <cgarcia@igalia.com>
    211
  • trunk/LayoutTests/TestExpectations

    r286094 r286100  
    43234323webkit.org/b/209460 imported/w3c/web-platform-tests/css/css-grid/abspos/descendant-static-position-003.html [ ImageOnlyFailure ]
    43244324webkit.org/b/212201 imported/w3c/web-platform-tests/css/css-grid/grid-definition/grid-limits-001.html [ Skip ]
    4325 webkit.org/b/227900 imported/w3c/web-platform-tests/css/css-grid/alignment/grid-item-aspect-ratio-stretch-1.html [ ImageOnlyFailure ]
    4326 webkit.org/b/227900 imported/w3c/web-platform-tests/css/css-grid/alignment/grid-item-aspect-ratio-stretch-2.html [ ImageOnlyFailure ]
    43274325webkit.org/b/212246 imported/w3c/web-platform-tests/css/css-grid/alignment/grid-baseline-align-cycles-001.html [ ImageOnlyFailure ]
    43284326webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/alignment/grid-inline-baseline.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r286099 r286100  
     12021-11-21  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] svg image as grid items should use the overriding logical width/height when defined to compute the logical height/width
     4        https://bugs.webkit.org/show_bug.cgi?id=228105
     5
     6        Reviewed by Javier Fernandez.
     7
     8        This is a reland of r280290. It's got reverted because another patch r280078 caused crash and had been
     9        reverted. r280290 is a dependent patch for r280078.
     10
     11        As discussed at https://github.com/w3c/csswg-drafts/issues/6286#issuecomment-866986544, degenerate
     12        aspect ratios derived from SVG width/height attributes fall back to viewbox aspect ratio
     13        (whether due to negative values or zero values).
     14
     15        When computing the logical height/width using an intrinsic aspect ratio, RenderReplaced uses the
     16        overridingLogicalWidth/overridingLogicalHeight whenever defined as long as the flex or
     17        grid item has an intrinsic size. For an SVG graphic though, it's common to have an intrinsic aspect
     18        ratio but not to have an intrinsic width or height. For this special case, we still should use
     19        overridingLogicalWidth/overridingLogicalHeight for logical height/width calculations.       
     20
     21        * rendering/RenderReplaced.cpp:
     22        (WebCore::hasIntrinsicSize):
     23        (WebCore::RenderReplaced::computeReplacedLogicalWidth const):
     24        (WebCore::RenderReplaced::computeReplacedLogicalHeight const):
     25
    1262021-11-21  Alan Bujtas  <zalan@apple.com>
    227
  • trunk/Source/WebCore/rendering/RenderReplaced.cpp

    r285998 r286100  
    532532}
    533533
     534static inline bool hasIntrinsicSize(RenderBox*contentRenderer, bool hasIntrinsicWidth, bool hasIntrinsicHeight )
     535{
     536    if (hasIntrinsicWidth && hasIntrinsicHeight)
     537        return true;
     538    if (hasIntrinsicWidth || hasIntrinsicHeight)
     539        return contentRenderer && contentRenderer->isSVGRoot();
     540    return false;
     541}
     542
    534543LayoutUnit RenderReplaced::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
    535544{
     
    554563        // grid item has an intrinsic size. It is possible (indeed, common) for an SVG graphic to have an intrinsic aspect ratio but not to have an intrinsic
    555564        // width or height. There are also elements with intrinsic sizes but without intrinsic ratio (like an iframe).
    556         if (intrinsicRatio && (isFlexItem() || isGridItem()) && hasOverridingLogicalHeight() && hasIntrinsicWidth && hasIntrinsicHeight)
     565        if (intrinsicRatio && (isFlexItem() || isGridItem()) && hasOverridingLogicalHeight() && hasIntrinsicSize(contentRenderer, hasIntrinsicWidth, hasIntrinsicHeight))
    557566            return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(round(overridingContentLogicalHeight() * intrinsicRatio)), shouldComputePreferred);
    558567
     
    624633
    625634    // See computeReplacedLogicalHeight() for a similar check for heights.
    626     if (intrinsicRatio && (isFlexItem() || isGridItem()) && hasOverridingLogicalWidth() && hasIntrinsicHeight && hasIntrinsicWidth)
     635    if (intrinsicRatio && (isFlexItem() || isGridItem()) && hasOverridingLogicalWidth() && hasIntrinsicSize(contentRenderer, hasIntrinsicWidth, hasIntrinsicHeight))
    627636        return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(round(overridingContentLogicalWidth() / intrinsicRatio)));
    628637
Note: See TracChangeset for help on using the changeset viewer.