Changeset 208973 in webkit
- Timestamp:
- Nov 24, 2016 7:08:11 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r208971 r208973 1 2016-11-23 Sergio Villar Senin <svillar@igalia.com> 2 3 [css-grid] Convert grid representation into a class 4 https://bugs.webkit.org/show_bug.cgi?id=165042 5 6 Reviewed by Manuel Rego Casasnovas. 7 8 So far grids are represented as Vectors of Vectors. There are a couple of issues associated 9 to that decision. First or all, the source code in RenderGrid assumes the existence of that 10 data structure, meaning that we cannot eventually change it without changing a lot of 11 code. Apart from the coupling there is another issue, RenderGrid is full of methods to 12 access and manipulate that data structure. 13 14 Instead, it'd be much better to have a Grid class encapsulating both the data structures and 15 the methods required to access/manipulate it. Note that follow-up patches will move even 16 more data and procedures into this new class from the RenderGrid code. 17 18 No new tests required as this is a refactoring. 19 20 * rendering/RenderGrid.cpp: 21 (WebCore::RenderGrid::Grid::ensureGridSize): Moved from RenderGrid. 22 (WebCore::RenderGrid::Grid::insert): Ditto. 23 (WebCore::RenderGrid::Grid::clear): Ditto. 24 (WebCore::RenderGrid::GridIterator::GridIterator): 25 (WebCore::RenderGrid::gridColumnCount): Use Grid's methods. 26 (WebCore::RenderGrid::gridRowCount): Ditto. 27 (WebCore::RenderGrid::placeItemsOnGrid): Use Grid's methods to insert children. 28 (WebCore::RenderGrid::populateExplicitGridAndOrderIterator): Ditto. 29 (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid): Ditto. 30 (WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid): Ditto. 31 (WebCore::RenderGrid::numTracks): Use Grid's methods. 32 (WebCore::RenderGrid::ensureGridSize): Deleted. Moved to Grid class. 33 (WebCore::RenderGrid::insertItemIntoGrid): Deleted. Moved to Grid class. 34 * rendering/RenderGrid.h: 35 1 36 2016-11-24 Antti Koivisto <antti@apple.com> 2 37 -
trunk/Source/WebCore/rendering/RenderGrid.cpp
r208962 r208973 47 47 }; 48 48 49 void RenderGrid::Grid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize) 50 { 51 const size_t oldColumnSize = numColumns(); 52 const size_t oldRowSize = numRows(); 53 if (maximumRowSize > oldRowSize) { 54 m_grid.grow(maximumRowSize); 55 for (size_t row = oldRowSize; row < maximumRowSize; ++row) 56 m_grid[row].grow(oldColumnSize); 57 } 58 59 if (maximumColumnSize > oldColumnSize) { 60 for (size_t row = 0; row < numRows(); ++row) 61 m_grid[row].grow(maximumColumnSize); 62 } 63 } 64 65 void RenderGrid::Grid::insert(RenderBox& child, const GridArea& area) 66 { 67 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite()); 68 ensureGridSize(area.rows.endLine(), area.columns.endLine()); 69 70 for (const auto& row : area.rows) { 71 for (const auto& column : area.columns) 72 m_grid[row][column].append(&child); 73 } 74 } 75 76 void RenderGrid::Grid::clear() 77 { 78 m_grid.resize(0); 79 } 80 49 81 class GridTrack { 50 82 public: … … 150 182 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g 151 183 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd column. 152 GridIterator(const Vector<Vector<Vector<RenderBox*, 1>>>& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0)153 : m_grid(grid )184 GridIterator(const Grid& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0) 185 : m_grid(grid.m_grid) 154 186 , m_direction(direction) 155 187 , m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackIndex) … … 228 260 229 261 private: 230 const Vector<Vector<Vector<RenderBox*, 1>>>& m_grid;262 const GridAsMatrix& m_grid; 231 263 GridTrackSizingDirection m_direction; 232 264 unsigned m_rowIndex; … … 388 420 { 389 421 ASSERT(!m_gridIsDirty); 390 return m_grid. size() ? m_grid[0].size() : 0;422 return m_grid.numColumns(); 391 423 } 392 424 … … 394 426 { 395 427 ASSERT(!m_gridIsDirty); 396 return m_grid. size();428 return m_grid.numRows(); 397 429 } 398 430 … … 1511 1543 #endif 1512 1544 1513 void RenderGrid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize)1514 {1515 const unsigned oldRowCount = gridRowCount();1516 if (maximumRowSize > oldRowCount) {1517 m_grid.grow(maximumRowSize);1518 for (unsigned row = oldRowCount; row < gridRowCount(); ++row)1519 m_grid[row].grow(gridColumnCount());1520 }1521 1522 if (maximumColumnSize > gridColumnCount()) {1523 for (unsigned row = 0; row < gridRowCount(); ++row)1524 m_grid[row].grow(maximumColumnSize);1525 }1526 }1527 1528 void RenderGrid::insertItemIntoGrid(RenderBox& child, const GridArea& area)1529 {1530 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());1531 ensureGridSize(area.rows.endLine(), area.columns.endLine());1532 1533 for (auto row : area.rows) {1534 for (auto column : area.columns)1535 m_grid[row][column].append(&child);1536 }1537 }1538 1539 1545 unsigned RenderGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection direction, SizingOperation sizingOperation) const 1540 1546 { … … 1680 1686 continue; 1681 1687 } 1682 insertItemIntoGrid(*child, GridArea(area.rows, area.columns));1688 m_grid.insert(*child, { area.rows, area.columns }); 1683 1689 } 1684 1690 … … 1744 1750 } 1745 1751 1746 m_grid.grow(maximumRowIndex + std::abs(m_smallestRowStart)); 1747 for (auto& column : m_grid) 1748 column.grow(maximumColumnIndex + std::abs(m_smallestColumnStart)); 1752 m_grid.ensureGridSize(maximumRowIndex + std::abs(m_smallestRowStart), maximumColumnIndex + std::abs(m_smallestColumnStart)); 1749 1753 } 1750 1754 … … 1781 1785 1782 1786 m_gridItemArea.set(autoGridItem, *emptyGridArea); 1783 insertItemIntoGrid(*autoGridItem, *emptyGridArea);1787 m_grid.insert(*autoGridItem, *emptyGridArea); 1784 1788 1785 1789 if (!isGridAutoFlowDense) … … 1854 1858 1855 1859 m_gridItemArea.set(&gridItem, *emptyGridArea); 1856 insertItemIntoGrid(gridItem, *emptyGridArea);1860 m_grid.insert(gridItem, *emptyGridArea); 1857 1861 autoPlacementCursor.first = emptyGridArea->rows.startLine(); 1858 1862 autoPlacementCursor.second = emptyGridArea->columns.startLine(); … … 2719 2723 // not stored in m_grid). 2720 2724 if (direction == ForRows) 2721 return m_grid. size();2722 2723 return m_grid. size() ? m_grid[0].size() : GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns);2725 return m_grid.numRows(); 2726 2727 return m_grid.numRows() ? m_grid.numColumns() : GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns); 2724 2728 } 2725 2729 -
trunk/Source/WebCore/rendering/RenderGrid.h
r208962 r208973 89 89 void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, GridSizingData&) const; 90 90 91 void ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize);92 void insertItemIntoGrid(RenderBox&, const GridArea&);93 94 91 unsigned computeAutoRepeatTracksCount(GridTrackSizingDirection, SizingOperation) const; 95 92 … … 201 198 GridTrackSizingDirection flowAwareDirectionForChild(const RenderBox&, GridTrackSizingDirection) const; 202 199 203 Vector<Vector<Vector<RenderBox*, 1>>> m_grid; 200 typedef Vector<RenderBox*, 1> GridCell; 201 typedef Vector<Vector<GridCell>> GridAsMatrix; 202 class Grid final { 203 public: 204 Grid() { } 205 206 unsigned numColumns() const { return m_grid.size() ? m_grid[0].size() : 0; } 207 unsigned numRows() const { return m_grid.size(); } 208 209 void ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize); 210 void insert(RenderBox&, const GridArea&); 211 212 const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; } 213 214 void shrinkToFit() { m_grid.shrinkToFit(); } 215 216 void clear(); 217 218 private: 219 friend class GridIterator; 220 GridAsMatrix m_grid; 221 }; 222 Grid m_grid; 223 204 224 Vector<LayoutUnit> m_columnPositions; 205 225 Vector<LayoutUnit> m_rowPositions;
Note: See TracChangeset
for help on using the changeset viewer.