Changeset 285497 in webkit


Ignore:
Timestamp:
Nov 9, 2021 6:48:01 AM (8 months ago)
Author:
Ziran Sun
Message:

[css-grid] update the content-sized grid width before laying out a grid item with block constraints and aspect-ratio
https://bugs.webkit.org/show_bug.cgi?id=231802

Reviewed by Javier Fernandez.
Source/WebCore:

For a grid item with an aspect-ratio, if it has block-constraints such as the relative logical height
case we consider in this CL, it should try and resolve it if possible and transfer this size into
the inline direction for the min/max content size. For the case that the grid width is content sized,
we need to update the width before laying out the grid items. Since the min-content contribution of
the grid item has changed based on the row sizes calculated in step 2 of sizing algorithm, we also
need to repeat the sizing algorithm steps to update the width of the track sizes.

  • rendering/GridLayoutFunctions.cpp:

(WebCore::GridLayoutFunctions::isAspectRatioBlockSizeDependentChild):

  • rendering/GridLayoutFunctions.h:
  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::updateGridAreaForAspectRatioItems):

  • rendering/RenderGrid.h:

LayoutTests:

Unskip the tests that are now passing and add a new test to check track size updates.

  • imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-005-expected.html: Added.
  • imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-005.html: Added.
  • TestExpectations:
  • platform/ios-wk2/TestExpectations:
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r285495 r285497  
     12021-11-09  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] update the content-sized grid width before laying out a grid item with block constraints and aspect-ratio
     4        https://bugs.webkit.org/show_bug.cgi?id=231802
     5
     6        Reviewed by Javier Fernandez.
     7       
     8        Unskip the tests that are now passing and add a new test to check track size updates.
     9
     10        * imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-005-expected.html: Added.
     11        * imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-005.html: Added.
     12        * TestExpectations:
     13        * platform/ios-wk2/TestExpectations:
     14
    1152021-11-09  Alan Bujtas  <zalan@apple.com>
    216
  • trunk/LayoutTests/TestExpectations

    r285493 r285497  
    14001400imported/w3c/web-platform-tests/css/css-grid/grid-model/grid-areas-overflowing-grid-container-009.html [ ImageOnlyFailure ]
    14011401imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/flex-sizing-rows-indefinite-height.html [ ImageOnlyFailure ]
    1402 webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/grid-intrinsic-size-dynamic-block-size.html [ ImageOnlyFailure ]
    14031402webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/grid-template-flexible-rerun-track-sizing.html [ ImageOnlyFailure ]
    14041403imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-align-content-001.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r285394 r285497  
    19941994webkit.org/b/209461 imported/w3c/web-platform-tests/css/css-grid/grid-items/grid-item-dynamic-min-contribution-001.html [ Failure ]
    19951995
    1996 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-001.html [ ImageOnlyFailure ]
    1997 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-002.html [ ImageOnlyFailure ]
    1998 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/aspect-ratio-003.html [ ImageOnlyFailure ]
    19991996webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/grid-item-inline-contribution-001.html [ ImageOnlyFailure ]
    20001997webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/grid-item-inline-contribution-002.html [ ImageOnlyFailure ]
    2001 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/replaced-element-011.html [ ImageOnlyFailure ]
    2002 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/replaced-element-012.html [ ImageOnlyFailure ]
    2003 webkit.org/b/227283 imported/w3c/web-platform-tests/css/css-grid/grid-items/replaced-element-013.html [ ImageOnlyFailure ]
    20041998
    20051999webkit.org/b/215929 compositing/video/poster.html [ Pass Timeout ]
  • trunk/Source/WebCore/ChangeLog

    r285495 r285497  
     12021-11-09  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] update the content-sized grid width before laying out a grid item with block constraints and aspect-ratio
     4        https://bugs.webkit.org/show_bug.cgi?id=231802
     5
     6        Reviewed by Javier Fernandez.
     7
     8        For a grid item with an aspect-ratio, if it has block-constraints such as the relative logical height
     9        case we consider in this CL, it should try and resolve it if possible and transfer this size into
     10        the inline direction for the min/max content size. For the case that the grid width is content sized,
     11        we need to update the width before laying out the grid items. Since the min-content contribution of
     12        the grid item has changed based on the row sizes calculated in step 2 of sizing algorithm, we also
     13        need to repeat the sizing algorithm steps to update the width of the track sizes.
     14
     15        * rendering/GridLayoutFunctions.cpp:
     16        (WebCore::GridLayoutFunctions::isAspectRatioBlockSizeDependentChild):
     17        * rendering/GridLayoutFunctions.h:
     18        * rendering/RenderGrid.cpp:
     19        (WebCore::RenderGrid::layoutBlock):
     20        (WebCore::RenderGrid::updateGridAreaForAspectRatioItems):
     21        * rendering/RenderGrid.h:
     22
    1232021-11-09  Alan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp

    r278253 r285497  
    8383}
    8484
     85bool isAspectRatioBlockSizeDependentChild(const RenderBox& child)
     86{
     87    return (child.style().hasAspectRatio() || child.hasIntrinsicAspectRatio()) && child.hasRelativeLogicalHeight();
     88}
     89
    8590GridTrackSizingDirection flowAwareDirectionForChild(const RenderGrid& grid, const RenderBox& child, GridTrackSizingDirection direction)
    8691{
  • trunk/Source/WebCore/rendering/GridLayoutFunctions.h

    r278253 r285497  
    4141LayoutUnit marginLogicalSizeForChild(const RenderGrid&, GridTrackSizingDirection, const RenderBox&);
    4242bool isOrthogonalChild(const RenderGrid&, const RenderBox&);
     43bool isAspectRatioBlockSizeDependentChild(const RenderBox&);
    4344GridTrackSizingDirection flowAwareDirectionForChild(const RenderGrid&, const RenderBox&, GridTrackSizingDirection);
    4445bool hasOverridingContainingBlockContentSizeForChild(const RenderBox&, GridTrackSizingDirection);
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r283321 r285497  
    162162    // cases with orthogonal flows require this extra cycle; we need a more specific
    163163    // condition to detect whether child's min-content contribution has changed or not.
    164     if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight()) {
     164    if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight() || m_hasAspectRatioBlockSizeDependentItem) {
    165165        computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
    166166        computeContentPositionAndDistributionOffset(ForColumns, m_trackSizingAlgorithm.freeSpace(ForColumns).value(), nonCollapsedTracks(ForColumns));
     
    200200        bool hasDefiniteLogicalHeight = RenderBlock::hasDefiniteLogicalHeight() || hasOverridingLogicalHeight() || computeContentLogicalHeight(MainOrPreferredSize, style().logicalHeight(), std::nullopt);
    201201        m_hasAnyOrthogonalItem = false;
     202        m_hasAspectRatioBlockSizeDependentItem = false;
     203        Vector<RenderBox*> aspectRatioBlockSizeDependentGridItems;
    202204        for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
    203205            if (child->isOutOfFlowPositioned())
     
    211213            if (GridLayoutFunctions::isOrthogonalChild(*this, *child))
    212214                m_hasAnyOrthogonalItem = true;
    213 
     215           
     216            // For a grid item that has an aspect-ratio and block-constraints such as the relative logical height,
     217            // when the grid width is auto, we may need get the real grid width before laying out the item.
     218            if (GridLayoutFunctions::isAspectRatioBlockSizeDependentChild(*child) && (style().logicalWidth().isAuto() || style().logicalWidth().isMinContent() || style().logicalWidth().isMaxContent())) {
     219                aspectRatioBlockSizeDependentGridItems.append(child);
     220                m_hasAspectRatioBlockSizeDependentItem = true;
     221            }
    214222            // We keep a cache of items with baseline as alignment values so
    215223            // that we only compute the baseline shims for such items. This
     
    274282        computeContentPositionAndDistributionOffset(ForRows, m_trackSizingAlgorithm.freeSpace(ForRows).value(), nonCollapsedTracks(ForRows));
    275283
     284        if (!aspectRatioBlockSizeDependentGridItems.isEmpty()) {
     285            updateGridAreaForAspectRatioItems(aspectRatioBlockSizeDependentGridItems);
     286            updateLogicalWidth();
     287        }
     288
    276289        // 3- If the min-content contribution of any grid items have changed based on the row
    277290        // sizes calculated in step 2, steps 1 and 2 are repeated with the new min-content
     
    941954    child.setOverridingContainingBlockContentLogicalWidth(width);
    942955    child.setOverridingContainingBlockContentLogicalHeight(height);
     956}
     957
     958void RenderGrid::updateGridAreaForAspectRatioItems(const Vector<RenderBox*>& autoGridItems)
     959{
     960    populateGridPositionsForDirection(ForColumns);
     961    populateGridPositionsForDirection(ForRows);
     962
     963    for (auto& autoGridItem : autoGridItems)
     964        updateGridAreaLogicalSize(*autoGridItem, gridAreaBreadthForChildIncludingAlignmentOffsets(*autoGridItem, ForColumns), gridAreaBreadthForChildIncludingAlignmentOffsets(*autoGridItem, ForRows));
    943965}
    944966
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r280075 r285497  
    131131    void repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows);
    132132
     133    void updateGridAreaForAspectRatioItems(const Vector<RenderBox*>&);
    133134    void layoutGridItems();
    134135    void populateGridPositionsForDirection(GridTrackSizingDirection);
     
    205206
    206207    bool m_hasAnyOrthogonalItem {false};
     208    bool m_hasAspectRatioBlockSizeDependentItem { false };
    207209    bool m_baselineItemsCached {false};
    208210};
Note: See TracChangeset for help on using the changeset viewer.