Changeset 238114 in webkit


Ignore:
Timestamp:
Nov 12, 2018 4:31:51 PM (5 years ago)
Author:
jfernandez@igalia.com
Message:

[css-grid] Refactoring to make more explicit the orthogonal items' pre-layout logic
https://bugs.webkit.org/show_bug.cgi?id=191358

Reviewed by Manuel Rego Casasnovas.

These changes are just a refactoring to ease the integration of the new Baseline Alignment
logic in a follow up patch.

We need to properly estimate the grid area size of orthogonal items so that we can perform
an accurate pre-layout. This is important because orthogonal items will synthesize their baseline
if they participate in any baseline alignment context.

No new tests, since no behavior change has been introduced in this patch.

  • rendering/Grid.cpp:

(WebCore::Grid::setNeedsItemsPlacement):

  • rendering/Grid.h:
  • rendering/GridTrackSizingAlgorithm.cpp:

(WebCore::GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild const):
(WebCore::GridTrackSizingAlgorithm::gridAreaBreadthForChild const):
(WebCore::GridTrackSizingAlgorithm::isRelativeGridLengthAsAuto const):
(WebCore::GridTrackSizingAlgorithm::isRelativeSizedTrackAsAuto const):
(WebCore::GridTrackSizingAlgorithm::gridTrackSize const):
(WebCore::IndefiniteSizeStrategy::findUsedFlexFraction const):
(WebCore::GridTrackSizingAlgorithm::run):
(WebCore::GridTrackSizingAlgorithm::reset):

  • rendering/GridTrackSizingAlgorithm.h:

(WebCore::GridTrackSizingAlgorithmStrategy::gridTrackSize const):

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::repeatTracksSizingIfNeeded):
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeIntrinsicLogicalWidths const):
(WebCore::RenderGrid::computeTrackSizesForIndefiniteSize const):
(WebCore::RenderGrid::placeItemsOnGrid const):
(WebCore::RenderGrid::performGridItemsPreLayout const):
(WebCore::overrideSizeChanged):
(WebCore::hasRelativeBlockAxisSize):
(WebCore::RenderGrid::updateGridAreaLogicalSize const):
(WebCore::RenderGrid::layoutGridItems):

  • rendering/RenderGrid.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r238112 r238114  
     12018-11-12  Javier Fernandez  <jfernandez@igalia.com>
     2
     3        [css-grid] Refactoring to make more explicit the orthogonal items' pre-layout logic
     4        https://bugs.webkit.org/show_bug.cgi?id=191358
     5
     6        Reviewed by Manuel Rego Casasnovas.
     7
     8        These changes are just a refactoring to ease the integration of the new Baseline Alignment
     9        logic in a follow up patch.
     10
     11        We need to properly estimate the grid area size of orthogonal items so that we can perform
     12        an accurate pre-layout. This is important because orthogonal items will synthesize their baseline
     13        if they participate in any baseline alignment context.
     14
     15        No new tests, since no behavior change has been introduced in this patch.
     16
     17        * rendering/Grid.cpp:
     18        (WebCore::Grid::setNeedsItemsPlacement):
     19        * rendering/Grid.h:
     20        * rendering/GridTrackSizingAlgorithm.cpp:
     21        (WebCore::GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild const):
     22        (WebCore::GridTrackSizingAlgorithm::gridAreaBreadthForChild const):
     23        (WebCore::GridTrackSizingAlgorithm::isRelativeGridLengthAsAuto const):
     24        (WebCore::GridTrackSizingAlgorithm::isRelativeSizedTrackAsAuto const):
     25        (WebCore::GridTrackSizingAlgorithm::gridTrackSize const):
     26        (WebCore::IndefiniteSizeStrategy::findUsedFlexFraction const):
     27        (WebCore::GridTrackSizingAlgorithm::run):
     28        (WebCore::GridTrackSizingAlgorithm::reset):
     29        * rendering/GridTrackSizingAlgorithm.h:
     30        (WebCore::GridTrackSizingAlgorithmStrategy::gridTrackSize const):
     31        * rendering/RenderGrid.cpp:
     32        (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
     33        (WebCore::RenderGrid::layoutBlock):
     34        (WebCore::RenderGrid::computeIntrinsicLogicalWidths const):
     35        (WebCore::RenderGrid::computeTrackSizesForIndefiniteSize const):
     36        (WebCore::RenderGrid::placeItemsOnGrid const):
     37        (WebCore::RenderGrid::performGridItemsPreLayout const):
     38        (WebCore::overrideSizeChanged):
     39        (WebCore::hasRelativeBlockAxisSize):
     40        (WebCore::RenderGrid::updateGridAreaLogicalSize const):
     41        (WebCore::RenderGrid::layoutGridItems):
     42        * rendering/RenderGrid.h:
     43
    1442018-11-12  Sihui Liu  <sihui_liu@apple.com>
    245
  • trunk/Source/WebCore/rendering/Grid.cpp

    r231245 r238114  
    158158    m_grid.shrink(0);
    159159    m_gridItemArea.clear();
    160     m_hasAnyOrthogonalGridItem = false;
    161160    m_smallestRowStart = 0;
    162161    m_smallestColumnStart = 0;
  • trunk/Source/WebCore/rendering/Grid.h

    r231245 r238114  
    5454    bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
    5555
    56     // FIXME: move this to SizingData once placeItemsOnGrid() takes it as argument.
    57     bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
    58     void setHasAnyOrthogonalGridItem(bool hasAnyOrthogonalGridItem) { m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; }
    59 
    6056    GridArea gridItemArea(const RenderBox& item) const;
    6157    void setGridItemArea(const RenderBox& item, GridArea);
     
    9692    unsigned m_autoRepeatRows { 0 };
    9793
    98     bool m_hasAnyOrthogonalGridItem { false };
    9994    bool m_needsItemsPlacement { true };
    10095
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp

    r237884 r238114  
    534534}
    535535
    536 LayoutUnit GridTrackSizingAlgorithm::assumedRowsSizeForOrthogonalChild(const RenderBox& child) const
    537 {
    538     ASSERT(GridLayoutFunctions::isOrthogonalChild(*m_renderGrid, child));
    539     const GridSpan& span = m_grid.gridItemSpan(child, ForRows);
     536LayoutSize GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child) const
     537{
     538    return {estimatedGridAreaBreadthForChild(child, ForColumns), estimatedGridAreaBreadthForChild(child, ForRows)};
     539}
     540
     541LayoutUnit GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction) const
     542{
     543    const GridSpan& span = m_grid.gridItemSpan(child, direction);
    540544    LayoutUnit gridAreaSize;
    541545    bool gridAreaIsIndefinite = false;
    542     LayoutUnit containingBlockAvailableSize = m_renderGrid->containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding);
     546    std::optional<LayoutUnit> availableSize = availableSpace(direction);
    543547    for (auto trackPosition : span) {
    544         GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition).maxTrackBreadth();
    545         if (maxTrackSize.isContentSized() || maxTrackSize.isFlex())
     548        // We may need to estimate the grid area size before running the track
     549        // sizing algorithm in order to perform the pre-layout of orthogonal
     550        // items.
     551        GridTrackSize trackSize = wasSetup() ? gridTrackSize(direction, trackPosition) : rawGridTrackSize(direction, trackPosition);
     552        GridLength maxTrackSize = trackSize.maxTrackBreadth();
     553        if (maxTrackSize.isContentSized() || maxTrackSize.isFlex() || isRelativeGridLengthAsAuto(maxTrackSize, direction))
    546554            gridAreaIsIndefinite = true;
    547555        else
    548             gridAreaSize += valueForLength(maxTrackSize.length(), containingBlockAvailableSize);
    549     }
    550 
    551     gridAreaSize += m_renderGrid->guttersSize(m_grid, ForRows, span.startLine(), span.integerSpan(), availableSpace(ForRows));
    552 
    553     return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : gridAreaSize;
     556            gridAreaSize += valueForLength(maxTrackSize.length(), availableSize.value_or(LayoutUnit()));
     557    }
     558
     559    gridAreaSize += m_renderGrid->guttersSize(m_grid, direction, span.startLine(), span.integerSpan(), availableSize);
     560
     561    GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*m_renderGrid, child, ForColumns);
     562    if (gridAreaIsIndefinite)
     563        return direction == childInlineDirection ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : LayoutUnit(-1);
     564    return gridAreaSize;
    554565}
    555566
     
    566577        // https://github.com/w3c/csswg-drafts/issues/2697
    567578        if (m_sizingState == ColumnSizingFirstIteration)
    568             return assumedRowsSizeForOrthogonalChild(child);
     579            return estimatedGridAreaBreadthForChild(child, ForRows);
    569580        addContentAlignmentOffset = true;
    570581    }
     
    584595}
    585596
     597bool GridTrackSizingAlgorithm::isRelativeGridLengthAsAuto(const GridLength& length, GridTrackSizingDirection direction) const
     598{
     599    return length.isPercentage() && !availableSpace(direction);
     600}
     601
    586602GridTrackSize GridTrackSizingAlgorithm::gridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex) const
    587603{
     604    ASSERT(wasSetup());
    588605    // Collapse empty auto repeat tracks if auto-fit.
    589606    if (m_grid.hasAutoRepeatEmptyTracks(direction) && m_grid.isEmptyAutoRepeatTrack(direction, translatedIndex))
     
    596613    GridLength minTrackBreadth = trackSize.minTrackBreadth();
    597614    GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
    598 
    599     // FIXME: Ensure this condition for determining whether a size is indefinite or not is working
    600     // correctly for orthogonal flows.
    601     if (!availableSpace(direction) && (minTrackBreadth.isPercentage() || maxTrackBreadth.isPercentage())) {
    602         if (minTrackBreadth.isPercentage())
    603             minTrackBreadth = Length(Auto);
    604         if (maxTrackBreadth.isPercentage())
    605             maxTrackBreadth = Length(Auto);
    606     }
     615    // If the logical width/height of the grid container is indefinite, percentage
     616    // values are treated as <auto>.
     617    if (isRelativeGridLengthAsAuto(trackSize.minTrackBreadth(), direction))
     618        minTrackBreadth = Length(Auto);
     619    if (isRelativeGridLengthAsAuto(trackSize.maxTrackBreadth(), direction))
     620        maxTrackBreadth = Length(Auto);
    607621
    608622    // Flex sizes are invalid as a min sizing function. However we still can have a flexible |minTrackBreadth|
     
    842856        // FIXME: we pass TrackSizing to gridTrackSize() because it does not really matter
    843857        // as we know the track is a flex sized track. It'd be nice not to have to do that.
    844         flexFraction = std::max(flexFraction, normalizedFlexFraction(allTracks[trackIndex], m_algorithm.gridTrackSize(direction, trackIndex).maxTrackBreadth().flex()));
     858        flexFraction = std::max(flexFraction, normalizedFlexFraction(allTracks[trackIndex], gridTrackSize(direction, trackIndex).maxTrackBreadth().flex()));
    845859    }
    846860
     
    11651179void GridTrackSizingAlgorithm::run()
    11661180{
     1181    ASSERT(wasSetup());
    11671182    StateMachine stateMachine(*this);
    11681183
     
    11981213void GridTrackSizingAlgorithm::reset()
    11991214{
     1215    ASSERT(wasSetup());
    12001216    m_sizingState = ColumnSizingFirstIteration;
    12011217    m_columns.shrink(0);
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h

    r234687 r238114  
    103103    // Required by RenderGrid. Try to minimize the exposed surface.
    104104    const Grid& grid() const { return m_grid; }
    105     GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
     105    // FIXME (jfernandez): We should remove any public getter for this attribute
     106    // and encapsulate any access in the algorithm class.
     107    Grid& mutableGrid() const { return m_grid; }
    106108
    107109    LayoutUnit minContentSize() const { return m_minContentSize; };
    108110    LayoutUnit maxContentSize() const { return m_maxContentSize; };
     111
     112    LayoutSize estimatedGridAreaBreadthForChild(const RenderBox&) const;
    109113
    110114    Vector<GridTrack>& tracks(GridTrackSizingDirection direction) { return direction == ForColumns ? m_columns : m_rows; }
     
    127131private:
    128132    std::optional<LayoutUnit> availableSpace() const { return availableSpace(m_direction); }
     133    bool isRelativeGridLengthAsAuto(const GridLength&, GridTrackSizingDirection) const;
     134    GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
    129135    const GridTrackSize& rawGridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
    130     LayoutUnit assumedRowsSizeForOrthogonalChild(const RenderBox&) const;
    131136
    132137    // Helper methods for step 1. initializeTrackSizes().
     
    141146    LayoutUnit itemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, RenderBox&) const;
    142147    template <TrackSizeComputationPhase phase> void distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<GridTrack*>* growBeyondGrowthLimitsTracks, LayoutUnit& availableLogicalSpace) const;
     148    LayoutUnit estimatedGridAreaBreadthForChild(const RenderBox&, GridTrackSizingDirection) const;
    143149    LayoutUnit gridAreaBreadthForChild(const RenderBox&, GridTrackSizingDirection) const;
    144150
     
    163169    bool isValidTransition() const;
    164170
     171    // Data.
     172    bool wasSetup() const { return !!m_strategy; }
    165173    bool m_needsSetup { true };
    166174    bool m_hasPercentSizedRowsIndefiniteHeight { false };
     
    240248    bool updateOverrideContainingBlockContentSizeForChild(RenderBox&, GridTrackSizingDirection, std::optional<LayoutUnit> = std::nullopt) const;
    241249
     250    GridTrackSize gridTrackSize(GridTrackSizingDirection direction, size_t translatedIndex) const { return m_algorithm.gridTrackSize(direction, translatedIndex); }
     251
    242252    // GridTrackSizingAlgorithm accessors for subclasses.
    243253    LayoutUnit computeTrackBasedSize() const { return m_algorithm.computeTrackBasedSize(); }
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r237884 r238114  
    159159    // cases with orthogonal flows require this extra cycle; we need a more specific
    160160    // condition to detect whether child's min-content contribution has changed or not.
    161     if (m_grid.hasAnyOrthogonalGridItem() || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight()) {
     161    if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight()) {
    162162        computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
    163163        computeContentPositionAndDistributionOffset(ForColumns, m_trackSizingAlgorithm.freeSpace(ForColumns).value(), nonCollapsedTracks(ForColumns));
     
    195195        bool hasDefiniteLogicalHeight = hasOverrideContentLogicalHeight() || computeContentLogicalHeight(MainOrPreferredSize, style().logicalHeight(), std::nullopt);
    196196
    197         // We need to clear both own and containingBlock override sizes of orthogonal items to ensure we get the
    198         // same result when grid's intrinsic size is computed again in the updateLogicalWidth call bellow.
    199         if (sizesLogicalWidthToFitContent(MaxSize) || style().logicalWidth().isIntrinsicOrAuto()) {
    200             for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
    201                 if (child->isOutOfFlowPositioned() || !GridLayoutFunctions::isOrthogonalChild(*this, *child))
    202                     continue;
    203                 child->clearOverrideContentSize();
    204                 child->clearOverrideContainingBlockContentSize();
    205                 child->setNeedsLayout();
    206                 child->layoutIfNeeded();
    207             }
     197        m_hasAnyOrthogonalItem = false;
     198        for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     199            if (child->isOutOfFlowPositioned())
     200                continue;
     201            // Grid's layout logic controls the grid item's override height, hence we need to
     202            // clear any override height set previously, so it doesn't interfere in current layout
     203            // execution. Grid never uses the override width, that's why we don't need to clear  it.
     204            child->clearOverrideContentLogicalHeight();
     205
     206            // We may need to repeat the track sizing in case of any grid item was orthogonal.
     207            if (GridLayoutFunctions::isOrthogonalChild(*this, *child))
     208                m_hasAnyOrthogonalItem = true;
    208209        }
    209210
     
    217218
    218219        LayoutUnit availableSpaceForColumns = availableLogicalWidth();
    219         placeItemsOnGrid(m_grid, availableSpaceForColumns);
     220        placeItemsOnGrid(m_trackSizingAlgorithm, availableSpaceForColumns);
     221
     222        performGridItemsPreLayout(m_trackSizingAlgorithm);
    220223
    221224        // 1- First, the track sizing algorithm is used to resolve the sizes of the
     
    236239            m_minContentHeight = LayoutUnit();
    237240            m_maxContentHeight = LayoutUnit();
    238             computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows, m_grid, *m_minContentHeight, *m_maxContentHeight);
     241            computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows, *m_minContentHeight, *m_maxContentHeight);
    239242            // FIXME: This should be really added to the intrinsic height in RenderBox::computeContentAndScrollbarLogicalHeightUsing().
    240243            // Remove this when that is fixed.
     
    385388
    386389    Grid grid(const_cast<RenderGrid&>(*this));
    387     placeItemsOnGrid(grid, std::nullopt);
    388 
    389390    GridTrackSizingAlgorithm algorithm(this, grid);
    390     computeTrackSizesForIndefiniteSize(algorithm, ForColumns, grid, minLogicalWidth, maxLogicalWidth);
     391    placeItemsOnGrid(algorithm, std::nullopt);
     392
     393    performGridItemsPreLayout(algorithm);
     394
     395    computeTrackSizesForIndefiniteSize(algorithm, ForColumns, minLogicalWidth, maxLogicalWidth);
    391396
    392397    if (hadExcludedChildren) {
     
    400405}
    401406
    402 void RenderGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm& algorithm, GridTrackSizingDirection direction, Grid& grid, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const
    403 {
     407void RenderGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm& algorithm, GridTrackSizingDirection direction, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const
     408{
     409    const Grid& grid = algorithm.grid();
    404410    algorithm.setup(direction, numTracks(direction, grid), IntrinsicSizeComputation, std::nullopt, std::nullopt);
    405411    algorithm.run();
     
    558564}
    559565
    560 // FIXME): We shouldn't have to pass the available logical width as argument. The problem is that
     566// FIXME: We shouldn't have to pass the available logical width as argument. The problem is that
    561567// availableLogicalWidth() does always return a value even if we cannot resolve it like when
    562568// computing the intrinsic size (preferred widths). That's why we pass the responsibility to the
    563569// caller who does know whether the available logical width is indefinite or not.
    564 void RenderGrid::placeItemsOnGrid(Grid& grid, std::optional<LayoutUnit> availableSpace) const
    565 {
    566     unsigned autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, availableSpace);
     570void RenderGrid::placeItemsOnGrid(GridTrackSizingAlgorithm& algorithm, std::optional<LayoutUnit> availableLogicalWidth) const
     571{
     572    Grid& grid = algorithm.mutableGrid();
     573    unsigned autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, availableLogicalWidth);
    567574    unsigned autoRepeatRows = computeAutoRepeatTracksCount(ForRows, availableLogicalHeightForPercentageComputation());
    568575
     
    583590    Vector<RenderBox*> autoMajorAxisAutoGridItems;
    584591    Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
    585     bool hasAnyOrthogonalGridItem = false;
    586592    for (auto* child = grid.orderIterator().first(); child; child = grid.orderIterator().next()) {
    587593        if (grid.orderIterator().shouldSkipChild(*child))
    588594            continue;
    589 
    590         hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem || GridLayoutFunctions::isOrthogonalChild(*this, *child);
    591595
    592596        GridArea area = grid.gridItemArea(*child);
     
    608612        grid.insert(*child, { area.rows, area.columns });
    609613    }
    610     grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem);
    611614
    612615#if !ASSERT_DISABLED
     
    635638    }
    636639#endif
     640}
     641
     642void RenderGrid::performGridItemsPreLayout(const GridTrackSizingAlgorithm& algorithm) const
     643{
     644    ASSERT(!algorithm.grid().needsItemsPlacement());
     645    // FIXME: We need a way when we are calling this during intrinsic size compuation before performing
     646    // the layout. Maybe using the PreLayout phase ?
     647    for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     648        if (child->isOutOfFlowPositioned())
     649            continue;
     650        // Orthogonal items should be laid out in order to properly compute content-sized tracks that may depend on item's intrinsic size.
     651        // We also need to properly estimate its grid area size, since it may affect to the baseline shims if such item particiaptes in baseline alignment.
     652        if (GridLayoutFunctions::isOrthogonalChild(*this, *child)) {
     653            updateGridAreaLogicalSize(*child, algorithm.estimatedGridAreaBreadthForChild(*child));
     654            child->layoutIfNeeded();
     655        }
     656    }
    637657}
    638658
     
    850870}
    851871
     872static bool overrideSizeChanged(const RenderBox& child, GridTrackSizingDirection direction, LayoutSize size)
     873{
     874    if (direction == ForColumns)
     875        return !child.hasOverrideContainingBlockContentLogicalWidth() || child.overrideContainingBlockContentLogicalWidth() != size.width();
     876    return !child.hasOverrideContainingBlockContentLogicalHeight() || child.overrideContainingBlockContentLogicalHeight() != size.height();
     877}
     878
     879static bool hasRelativeBlockAxisSize(const RenderGrid& grid, const RenderBox& child)
     880{
     881    return GridLayoutFunctions::isOrthogonalChild(grid, child) ? child.hasRelativeLogicalWidth() || child.style().logicalWidth().isAuto() : child.hasRelativeLogicalHeight();
     882}
     883
     884void RenderGrid::updateGridAreaLogicalSize(RenderBox& child, LayoutSize gridAreaLogicalSize) const
     885{
     886    // Because the grid area cannot be styled, we don't need to adjust
     887    // the grid breadth to account for 'box-sizing'.
     888    bool gridAreaWidthChanged = overrideSizeChanged(child, ForColumns, gridAreaLogicalSize);
     889    bool gridAreaHeightChanged = overrideSizeChanged(child, ForRows, gridAreaLogicalSize);
     890    if (gridAreaWidthChanged || (gridAreaHeightChanged && hasRelativeBlockAxisSize(*this, child)))
     891        child.setNeedsLayout(MarkOnlyThis);
     892
     893    child.setOverrideContainingBlockContentLogicalWidth(gridAreaLogicalSize.width());
     894    child.setOverrideContainingBlockContentLogicalHeight(gridAreaLogicalSize.height());
     895}
     896
    852897void RenderGrid::layoutGridItems()
    853898{
     
    863908        }
    864909
    865         // Because the grid area cannot be styled, we don't need to adjust
    866         // the grid breadth to account for 'box-sizing'.
    867         std::optional<LayoutUnit> oldOverrideContainingBlockContentLogicalWidth = child->hasOverrideContainingBlockContentLogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit();
    868         std::optional<LayoutUnit> oldOverrideContainingBlockContentLogicalHeight = child->hasOverrideContainingBlockContentLogicalHeight() ? child->overrideContainingBlockContentLogicalHeight() : LayoutUnit();
    869 
    870         LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns);
    871         LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows);
    872         if (!oldOverrideContainingBlockContentLogicalWidth || oldOverrideContainingBlockContentLogicalWidth.value() != overrideContainingBlockContentLogicalWidth
    873             || ((!oldOverrideContainingBlockContentLogicalHeight || oldOverrideContainingBlockContentLogicalHeight.value() != overrideContainingBlockContentLogicalHeight)
    874                 && child->hasRelativeLogicalHeight()))
    875             child->setNeedsLayout(MarkOnlyThis);
    876 
    877         child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth);
    878         child->setOverrideContainingBlockContentLogicalHeight(overrideContainingBlockContentLogicalHeight);
     910        // Setting the definite grid area's sizes. It may imply that the
     911        // item must perform a layout if its area differs from the one
     912        // used during the track sizing algorithm.
     913        updateGridAreaLogicalSize(*child, LayoutSize(gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns), gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows)));
    879914
    880915        LayoutRect oldChildRect = child->frameRect();
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r237884 r238114  
    7575    LayoutUnit gridItemOffset(GridTrackSizingDirection) const;
    7676
     77    void updateGridAreaLogicalSize(RenderBox&, LayoutSize) const;
     78
    7779    StyleContentAlignmentData contentAlignment(GridTrackSizingDirection) const;
    7880
     
    106108    std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat(Grid&, GridTrackSizingDirection) const;
    107109
    108     void placeItemsOnGrid(Grid&, std::optional<LayoutUnit> availableSpaceForColumns) const;
     110    void performGridItemsPreLayout(const GridTrackSizingAlgorithm&) const;
     111
     112    void placeItemsOnGrid(GridTrackSizingAlgorithm&, std::optional<LayoutUnit> availableLogicalWidth) const;
    109113    void populateExplicitGridAndOrderIterator(Grid&) const;
    110114    std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(Grid&, const RenderBox&, GridTrackSizingDirection, const GridSpan&) const;
     
    122126
    123127    void computeTrackSizesForDefiniteSize(GridTrackSizingDirection, LayoutUnit availableSpace);
    124     void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&, GridTrackSizingDirection, Grid&, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const;
     128    void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&, GridTrackSizingDirection, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const;
    125129    LayoutUnit computeTrackBasedLogicalHeight() const;
    126130
     
    194198    std::optional<LayoutUnit> m_minContentHeight;
    195199    std::optional<LayoutUnit> m_maxContentHeight;
     200
     201    bool m_hasAnyOrthogonalItem {false};
    196202};
    197203
Note: See TracChangeset for help on using the changeset viewer.