Changeset 208995 in webkit


Ignore:
Timestamp:
Nov 28, 2016 3:28:41 AM (7 years ago)
Author:
svillar@igalia.com
Message:

[css-grid] Move attributes from RenderGrid to the new Grid class
https://bugs.webkit.org/show_bug.cgi?id=165065

Reviewed by Darin Adler.

A new class called Grid was added in 208973. This is the first of a couple of patches moving
private attributes from RenderGrid to Grid.

Apart from that this is adding a couple of new helper functions that will decouple the
existence of in-flow items from the actual data structures storing that information.

Last but not least, the Grid::insert() method does not only insert the item in the m_grid
data structure, but also stores the GridArea associated to that item, so there is no need to
do it in two different calls.

No new tests required as this is a refactoring.

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::Grid::insert): Added a new parameter.
(WebCore::RenderGrid::Grid::setSmallestTracksStart):
(WebCore::RenderGrid::Grid::smallestTrackStart):
(WebCore::RenderGrid::Grid::gridItemArea):
(WebCore::RenderGrid::Grid::setGridItemArea):
(WebCore::RenderGrid::Grid::clear): Clear the newly added attributes.
(WebCore::RenderGrid::repeatTracksSizingIfNeeded):
(WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
(WebCore::RenderGrid::rawGridTrackSize):
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
(WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
(WebCore::RenderGrid::placeItemsOnGrid):
(WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
(WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
(WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
(WebCore::RenderGrid::clearGrid):
(WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
(WebCore::RenderGrid::cachedGridSpan):
(WebCore::RenderGrid::cachedGridArea): Deleted.

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208993 r208995  
     12016-11-24  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-grid] Move attributes from RenderGrid to the new Grid class
     4        https://bugs.webkit.org/show_bug.cgi?id=165065
     5
     6        Reviewed by Darin Adler.
     7
     8        A new class called Grid was added in 208973. This is the first of a couple of patches moving
     9        private attributes from RenderGrid to Grid.
     10
     11        Apart from that this is adding a couple of new helper functions that will decouple the
     12        existence of in-flow items from the actual data structures storing that information.
     13
     14        Last but not least, the Grid::insert() method does not only insert the item in the m_grid
     15        data structure, but also stores the GridArea associated to that item, so there is no need to
     16        do it in two different calls.
     17
     18        No new tests required as this is a refactoring.
     19
     20        * rendering/RenderGrid.cpp:
     21        (WebCore::RenderGrid::Grid::insert): Added a new parameter.
     22        (WebCore::RenderGrid::Grid::setSmallestTracksStart):
     23        (WebCore::RenderGrid::Grid::smallestTrackStart):
     24        (WebCore::RenderGrid::Grid::gridItemArea):
     25        (WebCore::RenderGrid::Grid::setGridItemArea):
     26        (WebCore::RenderGrid::Grid::clear): Clear the newly added attributes.
     27        (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
     28        (WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
     29        (WebCore::RenderGrid::rawGridTrackSize):
     30        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions):
     31        (WebCore::RenderGrid::computeEmptyTracksForAutoRepeat):
     32        (WebCore::RenderGrid::placeItemsOnGrid):
     33        (WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
     34        (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
     35        (WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid):
     36        (WebCore::RenderGrid::clearGrid):
     37        (WebCore::RenderGrid::offsetAndBreadthForPositionedChild):
     38        (WebCore::RenderGrid::cachedGridSpan):
     39        (WebCore::RenderGrid::cachedGridArea): Deleted.
     40        * rendering/RenderGrid.h:
     41
    1422016-11-27  Sam Weinig  <sam@webkit.org>
    243
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r208985 r208995  
    7272            m_grid[row][column].append(&child);
    7373    }
     74
     75    setGridItemArea(child, area);
     76}
     77
     78void RenderGrid::Grid::setSmallestTracksStart(int rowStart, int columnStart)
     79{
     80    m_smallestRowStart = rowStart;
     81    m_smallestColumnStart = columnStart;
     82}
     83
     84int RenderGrid::Grid::smallestTrackStart(GridTrackSizingDirection direction) const
     85{
     86    return direction == ForRows ? m_smallestRowStart : m_smallestColumnStart;
     87}
     88
     89GridArea RenderGrid::Grid::gridItemArea(const RenderBox& item) const
     90{
     91    ASSERT(m_gridItemArea.contains(&item));
     92    return m_gridItemArea.get(&item);
     93}
     94
     95void RenderGrid::Grid::setGridItemArea(const RenderBox& item, GridArea area)
     96{
     97    m_gridItemArea.set(&item, area);
    7498}
    7599
     
    77101{
    78102    m_grid.resize(0);
     103    m_gridItemArea.clear();
     104    m_hasAnyOrthogonalGridItem = false;
     105    m_smallestRowStart = 0;
     106    m_smallestColumnStart = 0;
    79107}
    80108
     
    468496    // cases with orthogonal flows require this extra cycle; we need a more specific
    469497    // condition to detect whether child's min-content contribution has changed or not.
    470     if (m_hasAnyOrthogonalChild) {
     498    if (m_grid.hasAnyOrthogonalGridItem()) {
    471499        computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForColumns);
    472500        computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows);
     
    822850            flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[trackIndex], gridTrackSize(direction, trackIndex, sizingData.sizingOperation).maxTrackBreadth().flex()));
    823851
    824         if (!m_gridItemArea.isEmpty()) {
     852        if (m_grid.hasGridItems()) {
    825853            for (unsigned i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
    826854                GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]);
     
    10081036    unsigned explicitTracksCount = trackStyles.size() + autoRepeatTracksCount;
    10091037
    1010     int untranslatedIndexAsInt = translatedIndex + (isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
     1038    int untranslatedIndexAsInt = translatedIndex + m_grid.smallestTrackStart(direction);
    10111039    unsigned autoTrackStylesSize = autoTrackStyles.size();
    10121040    if (untranslatedIndexAsInt < 0) {
     
    12211249    sizingData.itemsSortedByIncreasingSpan.shrink(0);
    12221250    HashSet<RenderBox*> itemsSet;
    1223     if (!m_gridItemArea.isEmpty()) {
     1251    if (m_grid.hasGridItems()) {
    12241252        for (auto trackIndex : sizingData.contentSizedTracksIndex) {
    12251253            GridIterator iterator(m_grid, direction, trackIndex);
     
    16301658    std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes;
    16311659    unsigned insertionPoint = isRowAxis ? style().gridAutoRepeatColumnsInsertionPoint() : style().gridAutoRepeatRowsInsertionPoint();
    1632     unsigned firstAutoRepeatTrack = insertionPoint + std::abs(isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
     1660    unsigned firstAutoRepeatTrack = insertionPoint + std::abs(m_grid.smallestTrackStart(direction));
    16331661    unsigned lastAutoRepeatTrack = firstAutoRepeatTrack + autoRepeatCountForDirection(direction);
    16341662
    1635     if (m_gridItemArea.isEmpty()) {
     1663    if (!m_grid.hasGridItems()) {
    16361664        emptyTrackIndexes = std::make_unique<OrderedTrackIndexSet>();
    16371665        for (unsigned trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepeatTrack; ++trackIndex)
     
    16531681{
    16541682    ASSERT(m_gridIsDirty);
    1655     ASSERT(m_gridItemArea.isEmpty());
     1683    ASSERT(!m_grid.hasGridItems());
    16561684
    16571685    m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizingOperation);
     
    16601688    populateExplicitGridAndOrderIterator();
    16611689    m_gridIsDirty = false;
     1690    bool hasAnyOrthogonalGridItem = false;
    16621691
    16631692    Vector<RenderBox*> autoMajorAxisAutoGridItems;
    16641693    Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
    1665     m_hasAnyOrthogonalChild = false;
    16661694    for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) {
    16671695        if (child->isOutOfFlowPositioned())
    16681696            continue;
    16691697
    1670         m_hasAnyOrthogonalChild = m_hasAnyOrthogonalChild || isOrthogonalChild(*child);
    1671 
    1672         GridArea area = cachedGridArea(*child);
     1698        hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem || isOrthogonalChild(*child);
     1699
     1700        GridArea area = m_grid.gridItemArea(*child);
    16731701        if (!area.rows.isIndefinite())
    1674             area.rows.translate(std::abs(m_smallestRowStart));
     1702            area.rows.translate(std::abs(m_grid.smallestTrackStart(ForRows)));
    16751703        if (!area.columns.isIndefinite())
    1676             area.columns.translate(std::abs(m_smallestColumnStart));
    1677         m_gridItemArea.set(child, area);
     1704            area.columns.translate(std::abs(m_grid.smallestTrackStart(ForColumns)));
    16781705
    16791706        if (area.rows.isIndefinite() || area.columns.isIndefinite()) {
     1707            m_grid.setGridItemArea(*child, area);
    16801708            bool majorAxisDirectionIsForColumns = autoPlacementMajorAxisDirection() == ForColumns;
    16811709            if ((majorAxisDirectionIsForColumns && area.columns.isIndefinite())
     
    16881716        m_grid.insert(*child, { area.rows, area.columns });
    16891717    }
     1718    m_grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem);
    16901719
    16911720#if ENABLE(ASSERT)
    1692     if (!m_gridItemArea.isEmpty()) {
     1721    if (m_grid.hasGridItems()) {
    16931722        ASSERT(gridRowCount() >= GridPositionsResolver::explicitGridRowCount(style(), m_autoRepeatRows));
    16941723        ASSERT(gridColumnCount() >= GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns));
     
    17081737            continue;
    17091738
    1710         GridArea area = cachedGridArea(*child);
     1739        GridArea area = m_grid.gridItemArea(*child);
    17111740        ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
    17121741    }
     
    17171746{
    17181747    OrderIteratorPopulator populator(m_orderIterator);
    1719     m_smallestRowStart = m_smallestColumnStart = 0;
     1748    int smallestRowStart = 0;
     1749    int smallestColumnStart = 0;
    17201750    unsigned maximumRowIndex = GridPositionsResolver::explicitGridRowCount(style(), m_autoRepeatRows);
    17211751    unsigned maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns);
     
    17291759        GridSpan rowPositions = GridPositionsResolver::resolveGridPositionsFromStyle(style(), *child, ForRows, m_autoRepeatRows);
    17301760        if (!rowPositions.isIndefinite()) {
    1731             m_smallestRowStart = std::min(m_smallestRowStart, rowPositions.untranslatedStartLine());
     1761            smallestRowStart = std::min(smallestRowStart, rowPositions.untranslatedStartLine());
    17321762            maximumRowIndex = std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine());
    17331763        } else {
     
    17391769        GridSpan columnPositions = GridPositionsResolver::resolveGridPositionsFromStyle(style(), *child, ForColumns, m_autoRepeatColumns);
    17401770        if (!columnPositions.isIndefinite()) {
    1741             m_smallestColumnStart = std::min(m_smallestColumnStart, columnPositions.untranslatedStartLine());
     1771            smallestColumnStart = std::min(smallestColumnStart, columnPositions.untranslatedStartLine());
    17421772            maximumColumnIndex = std::max<int>(maximumColumnIndex, columnPositions.untranslatedEndLine());
    17431773        } else {
     
    17471777        }
    17481778
    1749         m_gridItemArea.set(child, GridArea(rowPositions, columnPositions));
    1750     }
    1751 
    1752     m_grid.ensureGridSize(maximumRowIndex + std::abs(m_smallestRowStart), maximumColumnIndex + std::abs(m_smallestColumnStart));
     1779        m_grid.setGridItemArea(*child, { rowPositions, columnPositions });
     1780    }
     1781
     1782    m_grid.setSmallestTracksStart(smallestRowStart, smallestColumnStart);
     1783    m_grid.ensureGridSize(maximumRowIndex + std::abs(smallestRowStart), maximumColumnIndex + std::abs(smallestColumnStart));
    17531784}
    17541785
     
    17841815            emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions);
    17851816
    1786         m_gridItemArea.set(autoGridItem, *emptyGridArea);
    17871817        m_grid.insert(*autoGridItem, *emptyGridArea);
    17881818
     
    18571887    }
    18581888
    1859     m_gridItemArea.set(&gridItem, *emptyGridArea);
    18601889    m_grid.insert(gridItem, *emptyGridArea);
    18611890    autoPlacementCursor.first = emptyGridArea->rows.startLine();
     
    18761905{
    18771906    m_grid.clear();
    1878     m_gridItemArea.clear();
    18791907    m_gridIsDirty = true;
    18801908}
     
    20552083
    20562084    // For positioned items we cannot use GridSpan::translate() because we could end up with negative values, as the positioned items do not create implicit tracks per spec.
    2057     int smallestStart = std::abs(isRowAxis ? m_smallestColumnStart : m_smallestRowStart);
     2085    int smallestStart = std::abs(m_grid.smallestTrackStart(direction));
    20582086    int startLine = positions.untranslatedStartLine() + smallestStart;
    20592087    int endLine = positions.untranslatedEndLine() + smallestStart;
     
    21202148}
    21212149
    2122 GridArea RenderGrid::cachedGridArea(const RenderBox& gridItem) const
    2123 {
    2124     ASSERT(m_gridItemArea.contains(&gridItem));
    2125     return m_gridItemArea.get(&gridItem);
    2126 }
    2127 
    21282150GridSpan RenderGrid::cachedGridSpan(const RenderBox& gridItem, GridTrackSizingDirection direction) const
    21292151{
    2130     GridArea area = cachedGridArea(gridItem);
     2152    GridArea area = m_grid.gridItemArea(gridItem);
    21312153    return direction == ForColumns ? area.columns : area.rows;
    21322154}
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r208985 r208995  
    210210        void insert(RenderBox&, const GridArea&);
    211211
     212        // Note that each in flow child of a grid container becomes a grid item. This means that
     213        // this method will return false for a grid container with only out of flow children.
     214        bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
     215
     216        // FIXME: move this to SizingData once placeItemsOnGrid() takes it as argument.
     217        bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
     218        void setHasAnyOrthogonalGridItem(bool hasAnyOrthogonalGridItem) { m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; }
     219
     220        GridArea gridItemArea(const RenderBox& item) const;
     221        void setGridItemArea(const RenderBox& item, GridArea);
     222
    212223        const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; }
    213224
     225        int smallestTrackStart(GridTrackSizingDirection) const;
     226        void setSmallestTracksStart(int rowStart, int columnStart);
    214227        void shrinkToFit() { m_grid.shrinkToFit(); }
    215228
     
    218231    private:
    219232        friend class GridIterator;
     233
     234        int m_smallestColumnStart { 0 };
     235        int m_smallestRowStart { 0 };
     236
     237        bool m_hasAnyOrthogonalGridItem { false };
     238
    220239        GridAsMatrix m_grid;
     240
     241        HashMap<const RenderBox*, GridArea> m_gridItemArea;
     242        HashMap<const RenderBox*, size_t> m_gridItemsIndexesMap;
    221243    };
    222244    Grid m_grid;
     
    226248    LayoutUnit m_offsetBetweenColumns;
    227249    LayoutUnit m_offsetBetweenRows;
    228     HashMap<const RenderBox*, GridArea> m_gridItemArea;
    229250    OrderIterator m_orderIterator;
    230251
     
    232253    std::optional<LayoutUnit> m_maxContentHeight;
    233254
    234     int m_smallestColumnStart;
    235     int m_smallestRowStart;
    236 
    237255    unsigned m_autoRepeatColumns { 0 };
    238256    unsigned m_autoRepeatRows { 0 };
    239 
    240     bool m_hasAnyOrthogonalChild;
    241257
    242258    bool m_gridIsDirty { true };
Note: See TracChangeset for help on using the changeset viewer.