Changeset 291464 in webkit


Ignore:
Timestamp:
Mar 17, 2022 7:33:37 PM (4 months ago)
Author:
Matt Woodrow
Message:

Subgrid items should always be stretched.
https://bugs.webkit.org/show_bug.cgi?id=237628

Reviewed by Alan Bujtas.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-grid/subgrid/subgrid-stretch-expected.html: Added.
  • web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html: Added.

Added new WPT test covering various width/height and alignement contraints that should be
ignored since subgrids are always stretched.

Source/WebCore:

Fixes https://drafts.csswg.org/css-grid-2/#subgrid-box-alignment

Test: imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computeLogicalWidthInFragment const):
(WebCore::RenderBox::hasStretchedLogicalHeight const):
(WebCore::RenderBox::hasStretchedLogicalWidth const):

  • rendering/RenderBox.h:

Makes computeLogicalWidthInFragment use the override logical width for grid items
if it's been set, as we already do for height. We don't early return, so that margins
still get computed relative to this width.

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::layoutGridItems):
(WebCore::RenderGrid::availableAlignmentSpaceForChildBeforeStretching const):
(WebCore::RenderGrid::alignSelfForChild const):
(WebCore::RenderGrid::justifySelfForChild const):
(WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded):
(WebCore::RenderGrid::applySubgridStretchAlignmentToChildIfNeeded):

  • rendering/RenderGrid.h:

Sets the required override width/height size on subgrid items so that they get
stretched.

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291420 r291464  
     12022-03-17  Matt Woodrow  <mattwoodrow@apple.com>
     2
     3        Subgrid items should always be stretched.
     4        https://bugs.webkit.org/show_bug.cgi?id=237628
     5
     6        Reviewed by Alan Bujtas.
     7
     8        * web-platform-tests/css/css-grid/subgrid/subgrid-stretch-expected.html: Added.
     9        * web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html: Added.
     10
     11        Added new WPT test covering various width/height and alignement contraints that should be
     12        ignored since subgrids are always stretched.
     13
    1142022-03-17  Antoine Quint  <graouts@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r291463 r291464  
     12022-03-17  Matt Woodrow  <mattwoodrow@apple.com>
     2
     3        Subgrid items should always be stretched.
     4        https://bugs.webkit.org/show_bug.cgi?id=237628
     5
     6        Reviewed by Alan Bujtas.
     7
     8        Fixes https://drafts.csswg.org/css-grid-2/#subgrid-box-alignment
     9
     10        Test: imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-stretch.html
     11
     12        * rendering/RenderBox.cpp:
     13        (WebCore::RenderBox::computeLogicalWidthInFragment const):
     14        (WebCore::RenderBox::hasStretchedLogicalHeight const):
     15        (WebCore::RenderBox::hasStretchedLogicalWidth const):
     16        * rendering/RenderBox.h:
     17
     18        Makes computeLogicalWidthInFragment use the override logical width for grid items
     19        if it's been set, as we already do for height. We don't early return, so that margins
     20        still get computed relative to this width.
     21
     22        * rendering/RenderGrid.cpp:
     23        (WebCore::RenderGrid::layoutGridItems):
     24        (WebCore::RenderGrid::availableAlignmentSpaceForChildBeforeStretching const):
     25        (WebCore::RenderGrid::alignSelfForChild const):
     26        (WebCore::RenderGrid::justifySelfForChild const):
     27        (WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded):
     28        (WebCore::RenderGrid::applySubgridStretchAlignmentToChildIfNeeded):
     29        * rendering/RenderGrid.h:
     30
     31        Sets the required override width/height size on subgrid items so that they get
     32        stretched.
     33
    1342022-03-17  Alan Bujtas  <zalan@apple.com>
    235
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r290634 r291464  
    27272727
    27282728    // Width calculations
    2729     if (treatAsReplaced) {
     2729    if (isGridItem() && hasOverridingLogicalWidth()) {
     2730        computedValues.m_extent = overridingLogicalWidth();
     2731    } else if (treatAsReplaced) {
    27302732        computedValues.m_extent = logicalWidthLength.value() + borderAndPaddingLogicalWidth();
    27312733    } else if (shouldComputeLogicalWidthFromAspectRatio() && style().logicalWidth().isAuto()) {
     
    28792881        return false;
    28802882    }
    2881     if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode())
     2883    if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) {
     2884        if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForColumns))
     2885            return true;
    28822886        return style.resolvedJustifySelf(&containingBlock->style(), containingBlock->selfAlignmentNormalBehavior(this)).position() == ItemPosition::Stretch;
     2887    }
     2888    if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForRows))
     2889        return true;
    28832890    return style.resolvedAlignSelf(&containingBlock->style(), containingBlock->selfAlignmentNormalBehavior(this)).position() == ItemPosition::Stretch;
    28842891}
     
    28972904    }
    28982905    auto normalItemPosition = stretchingMode == StretchingMode::Any ? containingBlock->selfAlignmentNormalBehavior(this) : ItemPosition::Normal;
    2899     if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode())
     2906    if (containingBlock->isHorizontalWritingMode() != isHorizontalWritingMode()) {
     2907        if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForRows))
     2908            return true;
    29002909        return style.resolvedAlignSelf(&containingBlock->style(), normalItemPosition).position() == ItemPosition::Stretch;
     2910    }
     2911    if (is<RenderGrid>(this) && downcast<RenderGrid>(this)->isSubgridInParentDirection(ForColumns))
     2912        return true;
    29012913    return style.resolvedJustifySelf(&containingBlock->style(), normalItemPosition).position() == ItemPosition::Stretch;
    29022914}
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r290879 r291464  
    10561056        // determine the available space before stretching, are not set yet.
    10571057        applyStretchAlignmentToChildIfNeeded(*child);
     1058        applySubgridStretchAlignmentToChildIfNeeded(*child);
    10581059
    10591060        child->layoutIfNeeded();
     
    12001201}
    12011202
    1202 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& child) const
     1203LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox& child, GridTrackSizingDirection direction) const
    12031204{
    12041205    // Because we want to avoid multiple layouts, stretching logic might be performed before
    12051206    // children are laid out, so we can't use the child cached values. Hence, we need to
    12061207    // compute margins in order to determine the available height before stretching.
    1207     GridTrackSizingDirection childBlockFlowDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForRows);
    1208     return std::max(0_lu, gridAreaBreadthForChild - GridLayoutFunctions::marginLogicalSizeForChild(*this, childBlockFlowDirection, child));
     1208    auto childFlowDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, direction);
     1209    return std::max(0_lu, gridAreaBreadthForChild - GridLayoutFunctions::marginLogicalSizeForChild(*this, childFlowDirection, child));
    12091210}
    12101211
    12111212StyleSelfAlignmentData RenderGrid::alignSelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const
    12121213{
     1214    if (isSubgridInParentDirection(ForRows))
     1215        return { ItemPosition::Stretch, OverflowAlignment::Default };
    12131216    if (!gridStyle)
    12141217        gridStyle = &style();
     
    12191222StyleSelfAlignmentData RenderGrid::justifySelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const
    12201223{
     1224    if (isSubgridInParentDirection(ForColumns))
     1225        return { ItemPosition::Stretch, OverflowAlignment::Default };
    12211226    if (!gridStyle)
    12221227        gridStyle = &style();
     
    12521257    bool allowedToStretchChildBlockSize = blockFlowIsColumnAxis ? allowedToStretchChildAlongColumnAxis(child) : allowedToStretchChildAlongRowAxis(child);
    12531258    if (allowedToStretchChildBlockSize && !aspectRatioPrefersInline(child, blockFlowIsColumnAxis)) {
    1254         LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child);
     1259        LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child, ForRows);
    12551260        LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, std::nullopt);
    12561261        child.setOverridingLogicalHeight(desiredLogicalHeight);
     
    12651270        }
    12661271    } else if (!allowedToStretchChildBlockSize && allowedToStretchChildAlongRowAxis(child)) {
    1267         LayoutUnit stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child);
     1272        LayoutUnit stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child, ForColumns);
    12681273        LayoutUnit desiredLogicalWidth = child.constrainLogicalWidthInFragmentByMinMax(stretchedLogicalWidth, contentWidth(), *this, nullptr);
    12691274        child.setOverridingLogicalWidth(desiredLogicalWidth);
    12701275        if (desiredLogicalWidth != child.logicalWidth())
    12711276            child.setNeedsLayout(MarkOnlyThis);
    1272     }
     1277    }
     1278}
     1279
     1280void RenderGrid::applySubgridStretchAlignmentToChildIfNeeded(RenderBox& child)
     1281{
     1282    if (!is<RenderGrid>(child))
     1283        return;
     1284
     1285    if (downcast<RenderGrid>(child).isSubgrid(ForRows)) {
     1286        auto childBlockDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForRows);
     1287        auto stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childBlockDirection).value(), child, ForRows);
     1288        child.setOverridingLogicalHeight(stretchedLogicalHeight);
     1289    }
     1290
     1291    if (downcast<RenderGrid>(child).isSubgrid(ForColumns)) {
     1292        auto childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*this, child, ForColumns);
     1293        auto stretchedLogicalWidth = availableAlignmentSpaceForChildBeforeStretching(GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, childInlineDirection).value(), child, ForColumns);
     1294        child.setOverridingLogicalWidth(stretchedLogicalWidth);
     1295    }
    12731296}
    12741297
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r290879 r291464  
    192192
    193193    void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) override;
    194     LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox&) const;
     194    LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox&, GridTrackSizingDirection) const;
    195195    StyleSelfAlignmentData justifySelfForChild(const RenderBox&, StretchingMode = StretchingMode::Any, const RenderStyle* = nullptr) const;
    196196    StyleSelfAlignmentData alignSelfForChild(const RenderBox&, StretchingMode = StretchingMode::Any, const RenderStyle* = nullptr) const;
    197197    void applyStretchAlignmentToChildIfNeeded(RenderBox&);
     198    void applySubgridStretchAlignmentToChildIfNeeded(RenderBox&);
    198199    bool hasAutoSizeInColumnAxis(const RenderBox& child) const;
    199200    bool hasAutoSizeInRowAxis(const RenderBox& child) const;
Note: See TracChangeset for help on using the changeset viewer.