Changeset 221931 in webkit


Ignore:
Timestamp:
Sep 12, 2017 12:19:45 PM (7 years ago)
Author:
Manuel Rego Casasnovas
Message:

[css-grid] Stretching auto tracks should be done as part of the track sizing algorithm
https://bugs.webkit.org/show_bug.cgi?id=176783

Reviewed by Sergio Villar Senin.

LayoutTests/imported/w3c:

Import changes on the test related to the new behavior.

  • web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html:

Source/WebCore:

CSS WG has agreed to modify the track sizing algorithm to include
a new step: https://drafts.csswg.org/css-grid/#algo-stretch
We used to do the stretch of the "auto" tracks at the end of
the track sizing algorithm, however this change integrates it
into the algorithm itself as the last step.
See: https://github.com/w3c/csswg-drafts/issues/1150

The patch moves the method
RenderGrid::applyStretchAlignmentToTracksIfNeeded() to
GridTrackSizingAlgorithm::stretchAutoTracks().
And then modifies the grid track sizing algorithm to execute
the new step.

This patch uses the WPT test updated to check the new behavior.

  • rendering/GridTrackSizingAlgorithm.cpp:

(WebCore::GridTrackSizingAlgorithm::initializeTrackSizes): Initialize
the list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks): Add
early return if there are not flexible tracks.
(WebCore::GridTrackSizingAlgorithm::stretchAutoTracks): Code moved from
RenderGrid::applyStretchAlignmentToTracksIfNeeded().
(WebCore::GridTrackSizingAlgorithm::setup): Reset list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::run): Add new step
stretchAutoTracks().
(WebCore::GridTrackSizingAlgorithm::reset): Reset auto tracks.

  • rendering/GridTrackSizingAlgorithm.h: Add m_autoSizedTracksIndex.
  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::layoutBlock): Avoid applying stretch here.
(WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Make public.
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded): Moved to
GridTrackSizingAlgorithm::stretchAutoTracks().

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

Legend:

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

    r221910 r221931  
     12017-09-12  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [css-grid] Stretching auto tracks should be done as part of the track sizing algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=176783
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Import changes on the test related to the new behavior.
     9
     10        * web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html:
     11
    1122017-09-12  Manuel Rego Casasnovas  <rego@igalia.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html

    r221910 r221931  
    6969    checkGridSizeTracksAndImageSize("grid-1", "img-1", "200px", "200px", "200px", "200px", "200px", "200px");
    7070    checkGridSizeTracksAndImageSize("grid-2", "img-2", "10px", "10px", "200px", "200px", "200px", "200px");
    71     checkGridSizeTracksAndImageSize("grid-3", "img-3", "200px", "50px", "200px", "50px", "200px", "200px");
    72     checkGridSizeTracksAndImageSize("grid-4", "img-4", "200px", "10px", "200px", "50px", "200px", "200px");
     71    checkGridSizeTracksAndImageSize("grid-3", "img-3", "200px", "200px", "200px", "200px", "200px", "200px");
     72    checkGridSizeTracksAndImageSize("grid-4", "img-4", "200px", "10px", "200px", "200px", "200px", "200px");
    7373    checkGridSizeTracksAndImageSize("grid-5", "img-5", "200px", "50px", "50px", "50px", "50px", "50px");
    7474    checkGridSizeTracksAndImageSize("grid-6", "img-6", "200px", "10px", "50px", "50px", "50px", "50px");
    7575    checkGridSizeTracksAndImageSize("grid-7", "img-7", "200px", "225px", "200px", "200px 25px", "200px", "200px");
    7676    checkGridSizeTracksAndImageSize("grid-8", "img-8", "10px", "10px", "200px", "200px 25px", "200px", "200px");
    77     checkGridSizeTracksAndImageSize("grid-9", "img-9", "200px", "125px", "200px", "100px 25px", "200px", "200px");
    78     checkGridSizeTracksAndImageSize("grid-10", "img-10", "200px", "10px", "200px", "100px 25px", "200px", "200px");
     77    checkGridSizeTracksAndImageSize("grid-9", "img-9", "200px", "225px", "200px", "200px 25px", "200px", "200px");
     78    checkGridSizeTracksAndImageSize("grid-10", "img-10", "200px", "10px", "200px", "200px 25px", "200px", "200px");
    7979    checkGridSizeTracksAndImageSize("grid-11", "img-11", "200px", "125px", "100px", "100px 25px", "100px", "100px");
    8080    checkGridSizeTracksAndImageSize("grid-12", "img-12", "200px", "10px", "100px", "100px 25px", "100px", "100px");
  • trunk/Source/WebCore/ChangeLog

    r221929 r221931  
     12017-09-12  Manuel Rego Casasnovas  <rego@igalia.com>
     2
     3        [css-grid] Stretching auto tracks should be done as part of the track sizing algorithm
     4        https://bugs.webkit.org/show_bug.cgi?id=176783
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        CSS WG has agreed to modify the track sizing algorithm to include
     9        a new step: https://drafts.csswg.org/css-grid/#algo-stretch
     10        We used to do the stretch of the "auto" tracks at the end of
     11        the track sizing algorithm, however this change integrates it
     12        into the algorithm itself as the last step.
     13        See: https://github.com/w3c/csswg-drafts/issues/1150
     14
     15        The patch moves the method
     16        RenderGrid::applyStretchAlignmentToTracksIfNeeded() to
     17        GridTrackSizingAlgorithm::stretchAutoTracks().
     18        And then modifies the grid track sizing algorithm to execute
     19        the new step.
     20
     21        This patch uses the WPT test updated to check the new behavior.
     22
     23        * rendering/GridTrackSizingAlgorithm.cpp:
     24        (WebCore::GridTrackSizingAlgorithm::initializeTrackSizes): Initialize
     25        the list of auto tracks.
     26        (WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks): Add
     27        early return if there are not flexible tracks.
     28        (WebCore::GridTrackSizingAlgorithm::stretchAutoTracks): Code moved from
     29        RenderGrid::applyStretchAlignmentToTracksIfNeeded().
     30        (WebCore::GridTrackSizingAlgorithm::setup): Reset list of auto tracks.
     31        (WebCore::GridTrackSizingAlgorithm::run): Add new step
     32        stretchAutoTracks().
     33        (WebCore::GridTrackSizingAlgorithm::reset): Reset auto tracks.
     34        * rendering/GridTrackSizingAlgorithm.h: Add m_autoSizedTracksIndex.
     35        * rendering/RenderGrid.cpp:
     36        (WebCore::RenderGrid::layoutBlock): Avoid applying stretch here.
     37        (WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Make public.
     38        (WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded): Moved to
     39        GridTrackSizingAlgorithm::stretchAutoTracks().
     40        * rendering/RenderGrid.h:
     41
    1422017-09-12  Eric Carlson  <eric.carlson@apple.com>
    243
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp

    r221910 r221931  
    971971    ASSERT(m_contentSizedTracksIndex.isEmpty());
    972972    ASSERT(m_flexibleSizedTracksIndex.isEmpty());
     973    ASSERT(m_autoSizedTracksIndex.isEmpty());
    973974
    974975    Vector<GridTrack>& allTracks = tracks(m_direction);
     
    993994        if (trackSize.maxTrackBreadth().isFlex())
    994995            m_flexibleSizedTracksIndex.append(i);
     996        if (trackSize.hasAutoMaxTrackBreadth())
     997            m_autoSizedTracksIndex.append(i);
    995998    }
    996999}
     
    10401043void GridTrackSizingAlgorithm::stretchFlexibleTracks(std::optional<LayoutUnit> freeSpace)
    10411044{
     1045    if (m_flexibleSizedTracksIndex.isEmpty())
     1046        return;
     1047
    10421048    double flexFraction = m_strategy->findUsedFlexFraction(m_flexibleSizedTracksIndex, m_direction, freeSpace);
    10431049
     
    10621068        setFreeSpace(m_direction, this->freeSpace(m_direction).value() - totalGrowth);
    10631069    m_maxContentSize += totalGrowth;
     1070}
     1071
     1072void GridTrackSizingAlgorithm::stretchAutoTracks()
     1073{
     1074    if (m_autoSizedTracksIndex.isEmpty())
     1075        return;
     1076
     1077    auto currentFreeSpace = freeSpace(m_direction);
     1078    if (!currentFreeSpace
     1079        || currentFreeSpace.value() <= 0
     1080        || (m_direction == ForColumns && m_renderGrid->style().resolvedJustifyContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
     1081        || (m_direction == ForRows && m_renderGrid->style().resolvedAlignContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch))
     1082        return;
     1083
     1084    Vector<GridTrack>& allTracks = tracks(m_direction);
     1085    unsigned numberOfAutoSizedTracks = m_autoSizedTracksIndex.size();
     1086    LayoutUnit sizeToIncrease = currentFreeSpace.value() / numberOfAutoSizedTracks;
     1087    for (const auto& trackIndex : m_autoSizedTracksIndex) {
     1088        auto& track = allTracks[trackIndex];
     1089        track.setBaseSize(track.baseSize() + sizeToIncrease);
     1090    }
     1091    setFreeSpace(m_direction, LayoutUnit());
    10641092}
    10651093
     
    11181146    m_contentSizedTracksIndex.shrink(0);
    11191147    m_flexibleSizedTracksIndex.shrink(0);
     1148    m_autoSizedTracksIndex.shrink(0);
    11201149
    11211150    setFreeSpace(direction, freeSpace);
     
    11511180    m_strategy->maximizeTracks(tracks(m_direction), m_direction == ForColumns ? m_freeSpaceColumns : m_freeSpaceRows);
    11521181
    1153     if (m_flexibleSizedTracksIndex.isEmpty())
    1154         return;
    1155 
    11561182    // Step 4.
    11571183    stretchFlexibleTracks(initialFreeSpace);
     1184
     1185    // Step 5.
     1186    stretchAutoTracks();
    11581187}
    11591188
     
    11651194    m_contentSizedTracksIndex.shrink(0);
    11661195    m_flexibleSizedTracksIndex.shrink(0);
     1196    m_autoSizedTracksIndex.shrink(0);
    11671197    setAvailableSpace(ForRows, std::nullopt);
    11681198    setAvailableSpace(ForColumns, std::nullopt);
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h

    r215800 r221931  
    154154    void resolveIntrinsicTrackSizes();
    155155    void stretchFlexibleTracks(std::optional<LayoutUnit> freeSpace);
     156    void stretchAutoTracks();
    156157
    157158    // State machine.
     
    172173    Vector<unsigned> m_contentSizedTracksIndex;
    173174    Vector<unsigned> m_flexibleSizedTracksIndex;
     175    Vector<unsigned> m_autoSizedTracksIndex;
    174176
    175177    GridTrackSizingDirection m_direction;
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r219315 r221931  
    306306    }
    307307
    308     applyStretchAlignmentToTracksIfNeeded(ForColumns);
    309     applyStretchAlignmentToTracksIfNeeded(ForRows);
    310 
    311308    layoutGridItems();
    312309    m_trackSizingAlgorithm.reset();
     
    881878}
    882879
    883 static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid()
     880const StyleContentAlignmentData& RenderGrid::contentAlignmentNormalBehaviorGrid()
    884881{
    885882    static const StyleContentAlignmentData normalBehavior = {ContentPositionNormal, ContentDistributionStretch};
    886883    return normalBehavior;
    887 }
    888 
    889 void RenderGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction)
    890 {
    891     std::optional<LayoutUnit> freeSpace = m_trackSizingAlgorithm.freeSpace(direction);
    892     if (!freeSpace
    893         || freeSpace.value() <= 0
    894         || (direction == ForColumns && style().resolvedJustifyContentDistribution(contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
    895         || (direction == ForRows && style().resolvedAlignContentDistribution(contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch))
    896         return;
    897 
    898     // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing function.
    899     Vector<GridTrack>& allTracks = m_trackSizingAlgorithm.tracks(direction);
    900     Vector<unsigned> autoSizedTracksIndex;
    901     for (unsigned i = 0; i < allTracks.size(); ++i) {
    902         const GridTrackSize& trackSize = m_trackSizingAlgorithm.gridTrackSize(direction, i);
    903         if (trackSize.hasAutoMaxTrackBreadth())
    904             autoSizedTracksIndex.append(i);
    905     }
    906 
    907     unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size();
    908     if (numberOfAutoSizedTracks < 1)
    909         return;
    910 
    911     LayoutUnit sizeToIncrease = freeSpace.value() / numberOfAutoSizedTracks;
    912     for (const auto& trackIndex : autoSizedTracksIndex) {
    913         auto& track = allTracks[trackIndex];
    914         track.setBaseSize(track.baseSize() + sizeToIncrease);
    915     }
    916     m_trackSizingAlgorithm.setFreeSpace(direction, LayoutUnit());
    917884}
    918885
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r219315 r221931  
    6565    bool isOrthogonalChild(const RenderBox&) const;
    6666    LayoutUnit guttersSize(const Grid&, GridTrackSizingDirection, unsigned startLine, unsigned span, std::optional<LayoutUnit> availableSize) const;
     67
     68    static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid();
    6769
    6870protected:
     
    133135    LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&, GridTrackSizingDirection) const;
    134136
    135     void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection);
    136 
    137137    void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) override;
    138138    LayoutUnit marginLogicalSizeForChild(GridTrackSizingDirection, const RenderBox&) const;
Note: See TracChangeset for help on using the changeset viewer.