Modified: trunk/Source/WebCore/ChangeLog (208972 => 208973)
--- trunk/Source/WebCore/ChangeLog 2016-11-24 13:35:34 UTC (rev 208972)
+++ trunk/Source/WebCore/ChangeLog 2016-11-24 15:08:11 UTC (rev 208973)
@@ -1,3 +1,38 @@
+2016-11-23 Sergio Villar Senin <[email protected]>
+
+ [css-grid] Convert grid representation into a class
+ https://bugs.webkit.org/show_bug.cgi?id=165042
+
+ Reviewed by Manuel Rego Casasnovas.
+
+ So far grids are represented as Vectors of Vectors. There are a couple of issues associated
+ to that decision. First or all, the source code in RenderGrid assumes the existence of that
+ data structure, meaning that we cannot eventually change it without changing a lot of
+ code. Apart from the coupling there is another issue, RenderGrid is full of methods to
+ access and manipulate that data structure.
+
+ Instead, it'd be much better to have a Grid class encapsulating both the data structures and
+ the methods required to access/manipulate it. Note that follow-up patches will move even
+ more data and procedures into this new class from the RenderGrid code.
+
+ No new tests required as this is a refactoring.
+
+ * rendering/RenderGrid.cpp:
+ (WebCore::RenderGrid::Grid::ensureGridSize): Moved from RenderGrid.
+ (WebCore::RenderGrid::Grid::insert): Ditto.
+ (WebCore::RenderGrid::Grid::clear): Ditto.
+ (WebCore::RenderGrid::GridIterator::GridIterator):
+ (WebCore::RenderGrid::gridColumnCount): Use Grid's methods.
+ (WebCore::RenderGrid::gridRowCount): Ditto.
+ (WebCore::RenderGrid::placeItemsOnGrid): Use Grid's methods to insert children.
+ (WebCore::RenderGrid::populateExplicitGridAndOrderIterator): Ditto.
+ (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid): Ditto.
+ (WebCore::RenderGrid::placeAutoMajorAxisItemOnGrid): Ditto.
+ (WebCore::RenderGrid::numTracks): Use Grid's methods.
+ (WebCore::RenderGrid::ensureGridSize): Deleted. Moved to Grid class.
+ (WebCore::RenderGrid::insertItemIntoGrid): Deleted. Moved to Grid class.
+ * rendering/RenderGrid.h:
+
2016-11-24 Antti Koivisto <[email protected]>
Remove unused bool return from Element::willRecalcStyle
Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (208972 => 208973)
--- trunk/Source/WebCore/rendering/RenderGrid.cpp 2016-11-24 13:35:34 UTC (rev 208972)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp 2016-11-24 15:08:11 UTC (rev 208973)
@@ -46,6 +46,38 @@
ForbidInfinity,
};
+void RenderGrid::Grid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize)
+{
+ const size_t oldColumnSize = numColumns();
+ const size_t oldRowSize = numRows();
+ if (maximumRowSize > oldRowSize) {
+ m_grid.grow(maximumRowSize);
+ for (size_t row = oldRowSize; row < maximumRowSize; ++row)
+ m_grid[row].grow(oldColumnSize);
+ }
+
+ if (maximumColumnSize > oldColumnSize) {
+ for (size_t row = 0; row < numRows(); ++row)
+ m_grid[row].grow(maximumColumnSize);
+ }
+}
+
+void RenderGrid::Grid::insert(RenderBox& child, const GridArea& area)
+{
+ ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
+ ensureGridSize(area.rows.endLine(), area.columns.endLine());
+
+ for (const auto& row : area.rows) {
+ for (const auto& column : area.columns)
+ m_grid[row][column].append(&child);
+ }
+}
+
+void RenderGrid::Grid::clear()
+{
+ m_grid.resize(0);
+}
+
class GridTrack {
public:
GridTrack() {}
@@ -149,8 +181,8 @@
public:
// |direction| is the direction that is fixed to |fixedTrackIndex| so e.g
// GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd column.
- GridIterator(const Vector<Vector<Vector<RenderBox*, 1>>>& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0)
- : m_grid(grid)
+ GridIterator(const Grid& grid, GridTrackSizingDirection direction, unsigned fixedTrackIndex, unsigned varyingTrackIndex = 0)
+ : m_grid(grid.m_grid)
, m_direction(direction)
, m_rowIndex((direction == ForColumns) ? varyingTrackIndex : fixedTrackIndex)
, m_columnIndex((direction == ForColumns) ? fixedTrackIndex : varyingTrackIndex)
@@ -227,7 +259,7 @@
}
private:
- const Vector<Vector<Vector<RenderBox*, 1>>>& m_grid;
+ const GridAsMatrix& m_grid;
GridTrackSizingDirection m_direction;
unsigned m_rowIndex;
unsigned m_columnIndex;
@@ -387,13 +419,13 @@
unsigned RenderGrid::gridColumnCount() const
{
ASSERT(!m_gridIsDirty);
- return m_grid.size() ? m_grid[0].size() : 0;
+ return m_grid.numColumns();
}
unsigned RenderGrid::gridRowCount() const
{
ASSERT(!m_gridIsDirty);
- return m_grid.size();
+ return m_grid.numRows();
}
LayoutUnit RenderGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizingData) const
@@ -1510,32 +1542,6 @@
}
#endif
-void RenderGrid::ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize)
-{
- const unsigned oldRowCount = gridRowCount();
- if (maximumRowSize > oldRowCount) {
- m_grid.grow(maximumRowSize);
- for (unsigned row = oldRowCount; row < gridRowCount(); ++row)
- m_grid[row].grow(gridColumnCount());
- }
-
- if (maximumColumnSize > gridColumnCount()) {
- for (unsigned row = 0; row < gridRowCount(); ++row)
- m_grid[row].grow(maximumColumnSize);
- }
-}
-
-void RenderGrid::insertItemIntoGrid(RenderBox& child, const GridArea& area)
-{
- ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefinite());
- ensureGridSize(area.rows.endLine(), area.columns.endLine());
-
- for (auto row : area.rows) {
- for (auto column : area.columns)
- m_grid[row][column].append(&child);
- }
-}
-
unsigned RenderGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection direction, SizingOperation sizingOperation) const
{
bool isRowAxis = direction == ForColumns;
@@ -1679,7 +1685,7 @@
specifiedMajorAxisAutoGridItems.append(child);
continue;
}
- insertItemIntoGrid(*child, GridArea(area.rows, area.columns));
+ m_grid.insert(*child, { area.rows, area.columns });
}
#if ENABLE(ASSERT)
@@ -1743,9 +1749,7 @@
m_gridItemArea.set(child, GridArea(rowPositions, columnPositions));
}
- m_grid.grow(maximumRowIndex + std::abs(m_smallestRowStart));
- for (auto& column : m_grid)
- column.grow(maximumColumnIndex + std::abs(m_smallestColumnStart));
+ m_grid.ensureGridSize(maximumRowIndex + std::abs(m_smallestRowStart), maximumColumnIndex + std::abs(m_smallestColumnStart));
}
std::unique_ptr<GridArea> RenderGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(const RenderBox& gridItem, GridTrackSizingDirection specifiedDirection, const GridSpan& specifiedPositions) const
@@ -1780,7 +1784,7 @@
emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions);
m_gridItemArea.set(autoGridItem, *emptyGridArea);
- insertItemIntoGrid(*autoGridItem, *emptyGridArea);
+ m_grid.insert(*autoGridItem, *emptyGridArea);
if (!isGridAutoFlowDense)
minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyGridArea->rows.startLine() : emptyGridArea->columns.startLine());
@@ -1853,7 +1857,7 @@
}
m_gridItemArea.set(&gridItem, *emptyGridArea);
- insertItemIntoGrid(gridItem, *emptyGridArea);
+ m_grid.insert(gridItem, *emptyGridArea);
autoPlacementCursor.first = emptyGridArea->rows.startLine();
autoPlacementCursor.second = emptyGridArea->columns.startLine();
}
@@ -2718,9 +2722,9 @@
// because not having rows implies that there are no "normal" children (out-of-flow children are
// not stored in m_grid).
if (direction == ForRows)
- return m_grid.size();
+ return m_grid.numRows();
- return m_grid.size() ? m_grid[0].size() : GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns);
+ return m_grid.numRows() ? m_grid.numColumns() : GridPositionsResolver::explicitGridColumnCount(style(), m_autoRepeatColumns);
}
void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect)
Modified: trunk/Source/WebCore/rendering/RenderGrid.h (208972 => 208973)
--- trunk/Source/WebCore/rendering/RenderGrid.h 2016-11-24 13:35:34 UTC (rev 208972)
+++ trunk/Source/WebCore/rendering/RenderGrid.h 2016-11-24 15:08:11 UTC (rev 208973)
@@ -88,9 +88,6 @@
LayoutUnit computeUsedBreadthOfMaxLength(const GridTrackSize&, LayoutUnit usedBreadth, LayoutUnit maxSize) const;
void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, GridSizingData&) const;
- void ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize);
- void insertItemIntoGrid(RenderBox&, const GridArea&);
-
unsigned computeAutoRepeatTracksCount(GridTrackSizingDirection, SizingOperation) const;
typedef ListHashSet<size_t> OrderedTrackIndexSet;
@@ -200,7 +197,30 @@
bool isOrthogonalChild(const RenderBox&) const;
GridTrackSizingDirection flowAwareDirectionForChild(const RenderBox&, GridTrackSizingDirection) const;
- Vector<Vector<Vector<RenderBox*, 1>>> m_grid;
+ typedef Vector<RenderBox*, 1> GridCell;
+ typedef Vector<Vector<GridCell>> GridAsMatrix;
+ class Grid final {
+ public:
+ Grid() { }
+
+ unsigned numColumns() const { return m_grid.size() ? m_grid[0].size() : 0; }
+ unsigned numRows() const { return m_grid.size(); }
+
+ void ensureGridSize(unsigned maximumRowSize, unsigned maximumColumnSize);
+ void insert(RenderBox&, const GridArea&);
+
+ const GridCell& cell(unsigned row, unsigned column) const { return m_grid[row][column]; }
+
+ void shrinkToFit() { m_grid.shrinkToFit(); }
+
+ void clear();
+
+ private:
+ friend class GridIterator;
+ GridAsMatrix m_grid;
+ };
+ Grid m_grid;
+
Vector<LayoutUnit> m_columnPositions;
Vector<LayoutUnit> m_rowPositions;
LayoutUnit m_offsetBetweenColumns;