Changeset 290096 in webkit


Ignore:
Timestamp:
Feb 17, 2022 4:54:41 PM (5 months ago)
Author:
commit-queue@webkit.org
Message:

Account for subgrid MBP when sizing
https://bugs.webkit.org/show_bug.cgi?id=236338

Patch by Matt Woodrow <Matt Woodrow> on 2022-02-17
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html:
  • web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html:
  • web-platform-tests/css/css-grid/subgrid/line-names-008.html:
  • web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html:
  • web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html:

Source/WebCore:

Adds extra margin to subgrid items participating in the sizing of an outer
grid's tracks to account for the margin/border/padding of the intermediate
subgrid item itself.
Also contributes the subgrid's m/b/p to the edge tracks it cover, even
if no inner items occupy that track.

  • rendering/GridLayoutFunctions.cpp:

(WebCore::GridLayoutFunctions::directionFromSide):
(WebCore::GridLayoutFunctions::hasRelativeOrIntrinsicSizeForChild):
(WebCore::GridLayoutFunctions::extraMarginForSubgridChild):
(WebCore::GridLayoutFunctions::gapDifferenceForSubgridChild):
(WebCore::GridLayoutFunctions::marginLogicalSizeForChild):

  • rendering/GridTrackSizingAlgorithm.cpp:

(WebCore::setOverridingContainingBlockContentSizeForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild const):
(WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
(WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):
(WebCore::DefiniteSizeStrategy::minContentForChild const):
(WebCore::addSubgridMarginBorderPadding):
(WebCore::GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack):

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::isSubgrid const):
(WebCore::RenderGrid::mayBeSubgridExcludingAbsPos const):
(WebCore::RenderGrid::gridSpanCoversRealTracks const):
(WebCore::RenderGrid::gridAreaBreadthForOutOfFlowChild):
(WebCore::RenderGrid::computeContentPositionAndDistributionOffset):
(WebCore::RenderGrid::gridSpanForChild const):

  • rendering/RenderGrid.h:
  • rendering/style/GridPositionsResolver.cpp:

(WebCore::adjustGridPositionsFromStyle):

LayoutTests:

Account for subgrid MBP when sizing

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r290087 r290096  
     12022-02-17  Matt Woodrow  <mattwoodrow@apple.com>
     2
     3        Account for subgrid MBP when sizing
     4        https://bugs.webkit.org/show_bug.cgi?id=236338
     5
     6        Reviewed by Dean Jackson.
     7
     8        Account for subgrid MBP when sizing
     9
     10        * TestExpectations:
     11
    1122022-02-17  Matt Woodrow  <mattwoodrow@apple.com>
    213
  • trunk/LayoutTests/TestExpectations

    r290077 r290096  
    13961396
    13971397imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-001.html [ ImageOnlyFailure ]
    1398 imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002.html [ ImageOnlyFailure ]
    1399 imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003.html [ ImageOnlyFailure ]
    1400 imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-004.html [ ImageOnlyFailure ]
    14011398imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-001.html [ ImageOnlyFailure ]
    1402 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-001.html [ ImageOnlyFailure ]
    1403 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-002.html [ ImageOnlyFailure ]
    14041399imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-003.html [ ImageOnlyFailure ]
    1405 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-004.html [ ImageOnlyFailure ]
    14061400imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-007.html [ ImageOnlyFailure ]
    1407 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-larger-001.html [ ImageOnlyFailure ]
    1408 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-larger-002.html [ ImageOnlyFailure ]
    1409 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-smaller-001.html [ ImageOnlyFailure ]
    1410 imported/w3c/web-platform-tests/css/css-grid/subgrid/item-percentage-height-001.html [ ImageOnlyFailure ]
    14111401imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-007.html [ ImageOnlyFailure ]
    1412 imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html [ ImageOnlyFailure ]
    1413 imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-001.html [ ImageOnlyFailure ]
    14141402imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-002.html [ ImageOnlyFailure ]
    14151403imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-003.html [ ImageOnlyFailure ]
    14161404imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-004.html [ ImageOnlyFailure ]
    1417 imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html [ ImageOnlyFailure ]
    1418 imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html [ ImageOnlyFailure ]
    14191405imported/w3c/web-platform-tests/css/css-grid/subgrid/repeat-auto-fill-003.html [ ImageOnlyFailure ]
    1420 imported/w3c/web-platform-tests/css/css-grid/subgrid/repeat-auto-fill-004.html [ ImageOnlyFailure ]
    14211406imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-mbp-overflow-001.html [ ImageOnlyFailure ]
    14221407imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-mbp-overflow-002.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r290080 r290096  
     12022-02-17  Matt Woodrow  <mattwoodrow@apple.com>
     2
     3        Account for subgrid MBP when sizing
     4        https://bugs.webkit.org/show_bug.cgi?id=236338
     5
     6        Reviewed by Dean Jackson.
     7
     8        * web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html:
     9        * web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html:
     10        * web-platform-tests/css/css-grid/subgrid/line-names-008.html:
     11        * web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html:
     12        * web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html:
     13
    1142022-02-17  Noam Rosenthal  <noam@webkit.org>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html

    r262056 r290096  
    6262<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
    6363<div class="subgrid">
    64   <x style="grid-column:3; right:27px">x</x>
     64  <x style="grid-column:3; right:33px">x</x>
    6565</div>
    6666</div>
     
    118118<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
    119119<div class="subgrid hr">
    120   <x style="grid-column:auto/1; left:-27px">x</x>
     120  <x style="grid-column:auto/1; left:-33px">x</x>
    121121</div>
    122122</div>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html

    r262056 r290096  
    3939  inset: 0;
    4040  background: purple;
    41 }
    42 
    43 .a > .t1 > x {
    44   margin: -10px 0 0 -10px;
    45 }
    46 .a > .t2 > x,
    47 .c > .t2 > x,
    48 .c > .t1 > x {
    49   margin: 0 0 0 -10px;
    5041}
    5142
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html

    r262056 r290096  
    147147</div>
    148148
    149 <div class="grid" style="grid-template-columns: repeat(3,30px) [a] 30px repeat(7,30px)">
     149<div class="grid" style="grid-template-columns: 30px [a] repeat(2,30px) [a] 30px repeat(7,30px)">
    150150<n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n>
    151151  <div class="hr" style="grid-template-columns: subgrid [] [] [] [] [a]; grid-column:2/span 6">
     
    154154</div>
    155155
    156 <div class="grid" style="grid-template-columns: repeat(3,30px) [a] 30px repeat(7,30px)">
     156<div class="grid" style="grid-template-columns: 30px [a] repeat(2,30px) [a] 30px repeat(7,30px)">
    157157<n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n>
    158158  <div class="hr" style="grid-template-columns: subgrid [] [] [] [] [a]; grid-column:2/span 6">
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html

    r262056 r290096  
    436436<script>
    437437  const expectedResults = [
    438     "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z]",
    439     "[x y] 0px [z] 1px [z] 1px [z] 1px [z]",
     438    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z] 46px",
     439    "[x y] 0px [z] 1px [z] 1px [z] 1px [z] 23.5px 23.5px",
    440440    "[x] 1px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
    441441    "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z] 1px [z]",
     
    455455    "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px",
    456456    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
    457     "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
    458     "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z]",
     457    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
     458    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 18px",
    459459    "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px",
    460     "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
    461     "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
    462     "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px",
    463     "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
    464     "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
    465     "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
     460    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
     461    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
     462    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px 18px",
     463    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
     464    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
     465    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
    466466  ];
    467467  [...document.querySelectorAll('.grid')].forEach(function(grid, i) {
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html

    r262056 r290096  
    440440<script>
    441441  const expectedResults = [
    442     "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z]",
    443     "[x y] 0px [z] 1px [z] 1px [z] 1px [z]",
     442    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z] 46px",
     443    "[x y] 0px [z] 1px [z] 1px [z] 1px [z] 23.5px 23.5px",
    444444    "[x] 1px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
    445445    "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z] 1px [z]",
     
    459459    "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px",
    460460    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
    461     "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
    462     "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z]",
     461    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
     462    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 18px",
    463463    "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px",
    464     "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
    465     "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
    466     "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px",
    467     "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
    468     "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
    469     "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
     464    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
     465    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
     466    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px 18px",
     467    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
     468    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
     469    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
    470470  ];
    471471  [...document.querySelectorAll('.grid')].forEach(function(grid, i) {
  • trunk/Source/WebCore/ChangeLog

    r290089 r290096  
     12022-02-17  Matt Woodrow  <mattwoodrow@apple.com>
     2
     3        Account for subgrid MBP when sizing
     4        https://bugs.webkit.org/show_bug.cgi?id=236338
     5
     6        Reviewed by Dean Jackson.
     7
     8        Adds extra margin to subgrid items participating in the sizing of an outer
     9        grid's tracks to account for the margin/border/padding of the intermediate
     10        subgrid item itself.
     11        Also contributes the subgrid's m/b/p to the edge tracks it cover, even
     12        if no inner items occupy that track.
     13
     14        * rendering/GridLayoutFunctions.cpp:
     15        (WebCore::GridLayoutFunctions::directionFromSide):
     16        (WebCore::GridLayoutFunctions::hasRelativeOrIntrinsicSizeForChild):
     17        (WebCore::GridLayoutFunctions::extraMarginForSubgridChild):
     18        (WebCore::GridLayoutFunctions::gapDifferenceForSubgridChild):
     19        (WebCore::GridLayoutFunctions::marginLogicalSizeForChild):
     20        * rendering/GridTrackSizingAlgorithm.cpp:
     21        (WebCore::setOverridingContainingBlockContentSizeForChild):
     22        (WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild const):
     23        (WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
     24        (WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):
     25        (WebCore::DefiniteSizeStrategy::minContentForChild const):
     26        (WebCore::addSubgridMarginBorderPadding):
     27        (WebCore::GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack):
     28        * rendering/RenderGrid.cpp:
     29        (WebCore::RenderGrid::isSubgrid const):
     30        (WebCore::RenderGrid::mayBeSubgridExcludingAbsPos const):
     31        (WebCore::RenderGrid::gridSpanCoversRealTracks const):
     32        (WebCore::RenderGrid::gridAreaBreadthForOutOfFlowChild):
     33        (WebCore::RenderGrid::computeContentPositionAndDistributionOffset):
     34        (WebCore::RenderGrid::gridSpanForChild const):
     35        * rendering/RenderGrid.h:
     36        * rendering/style/GridPositionsResolver.cpp:
     37        (WebCore::adjustGridPositionsFromStyle):
     38
    1392022-02-17  J Pascoe  <j_pascoe@apple.com>
    240
  • trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp

    r290007 r290096  
    6767}
    6868
     69static inline GridTrackSizingDirection directionFromSide(GridPositionSide side)
     70{
     71    return side == ColumnStartSide || side == ColumnEndSide ? ForColumns : ForRows;
     72}
     73
     74static bool hasRelativeOrIntrinsicSizeForChild(const RenderBox& child, GridTrackSizingDirection direction)
     75{
     76    if (direction == ForColumns)
     77        return child.hasRelativeLogicalWidth() || child.style().logicalWidth().isIntrinsicOrAuto();
     78    return child.hasRelativeLogicalHeight() || child.style().logicalHeight().isIntrinsicOrAuto();
     79}
     80
     81static LayoutUnit extraMarginForSubgrid(const RenderGrid& parent, unsigned startLine, unsigned endLine, GridTrackSizingDirection direction)
     82{
     83    unsigned numTracks = parent.numTracks(direction);
     84    if (!numTracks || !parent.isSubgrid(direction))
     85        return 0_lu;
     86
     87    std::optional<LayoutUnit> availableSpace;
     88    if (!hasRelativeOrIntrinsicSizeForChild(parent, direction))
     89        availableSpace = parent.availableSpaceForGutters(direction);
     90
     91    RenderGrid& grandParent = downcast<RenderGrid>(*parent.parent());
     92    LayoutUnit mbp;
     93    if (!startLine)
     94        mbp += (direction == ForColumns) ? parent.marginAndBorderAndPaddingStart() : parent.marginAndBorderAndPaddingBefore();
     95    else
     96        mbp += (parent.gridGap(direction, availableSpace) - grandParent.gridGap(direction)) / 2;
     97
     98    if (endLine == numTracks)
     99        mbp += (direction == ForColumns) ? parent.marginAndBorderAndPaddingEnd() : parent.marginAndBorderAndPaddingAfter();
     100    else
     101        mbp += (parent.gridGap(direction, availableSpace) - grandParent.gridGap(direction)) / 2;
     102
     103    return mbp;
     104}
     105
     106static LayoutUnit extraMarginForSubgridAncestors(GridTrackSizingDirection direction, const RenderBox& child)
     107{
     108    const RenderGrid* grid = downcast<RenderGrid>(child.parent());
     109    LayoutUnit mbp;
     110
     111    while (grid->isSubgrid(direction)) {
     112        GridSpan span = grid->gridSpanForChild(child, direction);
     113
     114        mbp += extraMarginForSubgrid(*grid, span.startLine(), span.endLine(), direction);
     115
     116        const RenderElement* parent = grid->parent();
     117        if (!parent || !is<RenderGrid>(parent))
     118            break;
     119
     120        const RenderGrid* parentGrid = downcast<RenderGrid>(parent);
     121        direction = flowAwareDirectionForParent(*grid, *parentGrid, direction);
     122
     123        grid = parentGrid;
     124    }
     125
     126    return mbp;
     127}
     128
    69129LayoutUnit marginLogicalSizeForChild(const RenderGrid& grid, GridTrackSizingDirection direction, const RenderBox& child)
    70130{
     131    LayoutUnit margin;
    71132    if (child.needsLayout())
    72         return computeMarginLogicalSizeForChild(grid, direction, child);
    73     GridTrackSizingDirection flowAwareDirection = flowAwareDirectionForChild(grid, child, direction);
    74     bool isRowAxis = flowAwareDirection == ForColumns;
    75     LayoutUnit marginStart = marginStartIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginStart() : child.marginBefore();
    76     LayoutUnit marginEnd = marginEndIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginEnd() : child.marginAfter();
    77     return marginStart + marginEnd;
     133        margin = computeMarginLogicalSizeForChild(grid, direction, child);
     134    else {
     135        GridTrackSizingDirection flowAwareDirection = flowAwareDirectionForChild(grid, child, direction);
     136        bool isRowAxis = flowAwareDirection == ForColumns;
     137        LayoutUnit marginStart = marginStartIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginStart() : child.marginBefore();
     138        LayoutUnit marginEnd = marginEndIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginEnd() : child.marginAfter();
     139        margin = marginStart + marginEnd;
     140    }
     141
     142    if (&grid != child.parent())
     143        margin += extraMarginForSubgridAncestors(direction, child);
     144
     145    return margin;
    78146}
    79147
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp

    r290077 r290096  
    126126}
    127127
    128 static void setOverridingContainingBlockContentSizeForChild(RenderBox& child, GridTrackSizingDirection direction, std::optional<LayoutUnit> size)
    129 {
     128static void setOverridingContainingBlockContentSizeForChild(const RenderGrid& grid, RenderBox& child, GridTrackSizingDirection direction, std::optional<LayoutUnit> size)
     129{
     130    // This function sets the dimension based on the writing mode of the containing block.
     131    // For subgrids, this might not be the outermost grid, but could be a subgrid. If the
     132    // writing mode of the CB and the grid for which we're doing sizing don't match, swap
     133    // the directions.
     134    direction = GridLayoutFunctions::flowAwareDirectionForChild(grid, *child.containingBlock(), direction);
    130135    if (direction == ForColumns)
    131136        child.setOverridingContainingBlockContentLogicalWidth(size);
     
    795800    // what we are interested in here. Thus we need to set the block-axis override size to nullopt (no possible resolution).
    796801    if (shouldClearOverridingContainingBlockContentSizeForChild(child, ForRows)) {
    797         setOverridingContainingBlockContentSizeForChild(child, childBlockDirection, std::nullopt);
     802        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, childBlockDirection, std::nullopt);
    798803        child.setNeedsLayout(MarkOnlyThis);
    799804    }
     
    960965    if (!overrideSize)
    961966        overrideSize = m_algorithm.gridAreaBreadthForChild(child, direction);
     967
    962968    if (GridLayoutFunctions::hasOverridingContainingBlockContentSizeForChild(child, direction) && GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, direction) == overrideSize)
    963969        return false;
    964970
    965     setOverridingContainingBlockContentSizeForChild(child, direction, overrideSize);
     971    setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, direction, overrideSize);
    966972    return true;
    967973}
     
    11231129    if (hasRelativeMarginOrPaddingForChild(child, flowAwareDirection) || (direction() != childInlineDirection && hasRelativeOrIntrinsicSizeForChild(child, flowAwareDirection))) {
    11241130        auto indefiniteSize = direction() == childInlineDirection ? std::make_optional(0_lu) : std::nullopt;
    1125         setOverridingContainingBlockContentSizeForChild(child, direction(), indefiniteSize);
     1131        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, direction(), indefiniteSize);
    11261132    }
    11271133    return GridTrackSizingAlgorithmStrategy::minLogicalSizeForChild(child, childMinSize, availableSize);
     
    11681174    GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
    11691175    if (direction() == childInlineDirection && child.needsLayout() && shouldClearOverridingContainingBlockContentSizeForChild(child, ForColumns))
    1170         setOverridingContainingBlockContentSizeForChild(child, childInlineDirection, LayoutUnit());
     1176        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, childInlineDirection, LayoutUnit());
    11711177    return GridTrackSizingAlgorithmStrategy::minContentForChild(child);
    11721178}
     
    12231229}
    12241230
     1231static LayoutUnit marginAndBorderAndPaddingForEdge(const RenderGrid& grid, GridTrackSizingDirection direction, bool startEdge)
     1232{
     1233    if (direction == ForColumns)
     1234        return startEdge ? grid.marginAndBorderAndPaddingStart() : grid.marginAndBorderAndPaddingEnd();
     1235    return startEdge ? grid.marginAndBorderAndPaddingBefore() : grid.marginAndBorderAndPaddingAfter();
     1236}
     1237
     1238// https://drafts.csswg.org/css-grid-2/#subgrid-edge-placeholders
     1239// FIXME: This is a simplification of the specified behaviour, where we add the hypothetical
     1240// items directly to the edge tracks as if they had a span of 1. This matches the current Gecko
     1241// behavior.
     1242static void addSubgridMarginBorderPadding(const RenderGrid* outermost, GridTrackSizingDirection outermostDirection, Vector<GridTrack>& allTracks, GridSpan& span, RenderGrid* subgrid)
     1243{
     1244    // Convert the direction into the coordinate space of subgrid (which may not be a direct child
     1245    // of the outermost grid for which we're running the track sizing algorithm).
     1246    GridTrackSizingDirection direction = GridLayoutFunctions::flowAwareDirectionForChild(*outermost, *subgrid, outermostDirection);
     1247    bool reversed = GridLayoutFunctions::isSubgridReversedDirection(*outermost, outermostDirection, *subgrid);
     1248
     1249    if (allTracks[span.startLine()].cachedTrackSize().hasIntrinsicMinTrackBreadth()) {
     1250        // If the subgrid has a reversed flow direction relative to the outermost grid, then
     1251        // we want the MBP from the end edge in its local coordinate space.
     1252        LayoutUnit mbpStart = marginAndBorderAndPaddingForEdge(*subgrid, direction, !reversed);
     1253        allTracks[span.startLine()].setBaseSize(std::max(allTracks[span.startLine()].baseSize(), mbpStart));
     1254    }
     1255    if (allTracks[span.endLine() - 1].cachedTrackSize().hasIntrinsicMinTrackBreadth()) {
     1256        LayoutUnit mbpEnd = marginAndBorderAndPaddingForEdge(*subgrid, direction, reversed);
     1257        allTracks[span.endLine() - 1].setBaseSize(std::max(allTracks[span.endLine() - 1].baseSize(), mbpEnd));
     1258    }
     1259}
     1260
    12251261void GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack(GridTrack& track, GridIterator& iterator, Vector<GridItemWithSpan>& itemsSortedByIncreasingSpan, Vector<GridItemWithSpan>& itemsCrossingFlexibleTracks, HashSet<RenderBox*>& itemsSet)
    12261262{
     1263    Vector<GridTrack>& allTracks = tracks(m_direction);
     1264
    12271265    while (auto* gridItem = iterator.nextGridItem()) {
    12281266        bool isNewEntry = itemsSet.add(gridItem).isNewEntry;
    12291267        if (is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem)->isSubgridInParentDirection(iterator.direction())) {
     1268            // Contribute the mbp of wrapper to the first and last tracks that we span.
    12301269            RenderGrid* inner = downcast<RenderGrid>(gridItem);
     1270            if (isNewEntry) {
     1271                GridSpan span = m_renderGrid->gridSpanForChild(*gridItem, m_direction);
     1272                addSubgridMarginBorderPadding(m_renderGrid, m_direction, allTracks, span, inner);
     1273            }
    12311274
    12321275            GridIterator childIterator = GridIterator::createForSubgrid(*inner, iterator);
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r290077 r290096  
    16541654bool RenderGrid::isSubgrid(GridTrackSizingDirection direction) const
    16551655{
    1656     if (isOutOfFlowPositioned() || isExcludedFromNormalLayout())
     1656    if (!mayBeSubgridExcludingAbsPos(direction))
    16571657        return false;
    1658     if ((direction == ForColumns) ? !style().gridSubgridColumns() : !style().gridSubgridRows())
    1659         return false;
    1660     return is<RenderGrid>(parent());
     1658    return downcast<RenderGrid>(parent())->gridSpanCoversRealTracks(*this, direction);
    16611659}
    16621660
     
    16671665    GridTrackSizingDirection direction = GridLayoutFunctions::flowAwareDirectionForChild(*downcast<RenderGrid>(parent()), *this, parentDirection);
    16681666    return isSubgrid(direction);
     1667}
     1668
     1669bool RenderGrid::mayBeSubgridExcludingAbsPos(GridTrackSizingDirection direction) const
     1670{
     1671    // Should exclude cases where we establish an IFC, like contain layout.
     1672    if (isExcludedFromNormalLayout())
     1673        return false;
     1674    if (direction == ForColumns ? !style().gridSubgridColumns() : !style().gridSubgridRows())
     1675        return false;
     1676    if (!is<RenderGrid>(parent()))
     1677        return false;
     1678    return true;
    16691679}
    16701680
     
    18531863    auto& offset =
    18541864        isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows;
     1865    if (isRowAxis ? isSubgridColumns() : isSubgridRows()) {
     1866        offset.positionOffset = 0_lu;
     1867        offset.distributionOffset = 0_lu;
     1868        return;
     1869    }
    18551870    auto contentAlignmentData = contentAlignment(direction);
    18561871    auto position = contentAlignmentData.position();
     
    20962111}
    20972112
     2113bool RenderGrid::gridSpanCoversRealTracks(const RenderBox& child, GridTrackSizingDirection direction) const
     2114{
     2115    // Only out of flow positioned items can span to the special line that covers
     2116    // the padding area.
     2117    if (!child.isOutOfFlowPositioned())
     2118        return true;
     2119
     2120    int lastLine = numTracks(direction, m_grid);
     2121    int startLine, endLine;
     2122    bool startIsAuto, endIsAuto;
     2123    if (!computeGridPositionsForOutOfFlowChild(child, direction, startLine, startIsAuto, endLine, endIsAuto))
     2124        return lastLine > 0;
     2125
     2126    // If the resulting span covers only the padding area, then it's not a real
     2127    // track that could be used for a subgrid.
     2128    if (startIsAuto && !endLine)
     2129        return false;
     2130    if (endIsAuto && startLine == lastLine)
     2131        return false;
     2132    return true;
     2133}
     2134
    20982135} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r290077 r290096  
    9797    }
    9898    bool isSubgridInParentDirection(GridTrackSizingDirection parentDirection) const;
     99    bool mayBeSubgridExcludingAbsPos(GridTrackSizingDirection) const;
    99100
    100101    const Grid& currentGrid() const
     
    109110
    110111    void placeItems();
     112
     113    std::optional<LayoutUnit> availableSpaceForGutters(GridTrackSizingDirection) const;
     114    LayoutUnit gridGap(GridTrackSizingDirection) const;
     115    LayoutUnit gridGap(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
    111116
    112117private:
     
    125130    bool selfAlignmentChangedToStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
    126131    bool selfAlignmentChangedFromStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
    127 
    128     std::optional<LayoutUnit> availableSpaceForGutters(GridTrackSizingDirection) const;
    129132
    130133    bool explicitGridDidResize(const RenderStyle&) const;
     
    207210    LayoutUnit rowAxisBaselineOffsetForChild(const RenderBox&) const;
    208211
    209     LayoutUnit gridGap(GridTrackSizingDirection) const;
    210     LayoutUnit gridGap(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
    211 
    212212    unsigned nonCollapsedTracks(GridTrackSizingDirection) const;
    213213    unsigned numTracks(GridTrackSizingDirection, const Grid&) const;
     
    223223
    224224    GridSpan gridSpanForOutOfFlowChild(const RenderBox&, GridTrackSizingDirection) const;
     225
    225226    bool computeGridPositionsForOutOfFlowChild(const RenderBox&, GridTrackSizingDirection, int&, bool&, int&, bool&) const;
     227    bool gridSpanCoversRealTracks(const RenderBox&, GridTrackSizingDirection) const;
    226228
    227229    Grid m_grid;
  • trunk/Source/WebCore/rendering/style/GridPositionsResolver.cpp

    r289998 r290096  
    381381        initialPosition.setSpanPosition(1, String());
    382382
    383     if (isIndefiniteSpan(initialPosition, finalPosition) && is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem).isSubgrid(direction)) {
     383    // Absolutely positioned items specifying subgrid might not actually be a subgrid if their grid
     384    // span doesn't cover any tracks and only the padding area. We don't know if that is the case until
     385    // we've figured out their grid position though, which is what we're trying to do now.
     386    if (isIndefiniteSpan(initialPosition, finalPosition) && is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem).mayBeSubgridExcludingAbsPos(direction)) {
    384387        // Indefinite span for an item that is subgridded in this axis.
    385388        int lineCount = (isForColumns ? gridItem.style().orderedNamedGridColumnLines() : gridItem.style().orderedNamedGridRowLines()).size();
Note: See TracChangeset for help on using the changeset viewer.