Chromium Code Reviews| Index: Source/core/rendering/RenderGrid.cpp |
| diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp |
| index 351881084b582f24de06651ade28f7fd5595239d..f37c4c1b58cf3a883d13040b6b679cd14c0ae530 100644 |
| --- a/Source/core/rendering/RenderGrid.cpp |
| +++ b/Source/core/rendering/RenderGrid.cpp |
| @@ -191,20 +191,28 @@ void RenderGrid::addChild(RenderObject* newChild, RenderObject* beforeChild) |
| return; |
| } |
| + if (style()->gridAutoFlow() != AutoFlowNone) { |
| + // The grid needs to be recomputed as it might contain auto-placed items that will change their position. |
| + dirtyGrid(); |
| + return; |
| + } |
| + |
| RenderBox* newChildBox = toRenderBox(newChild); |
| OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, ForRows); |
| OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox, ForColumns); |
| if (!rowPositions || !columnPositions) { |
| // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully. |
| dirtyGrid(); |
| - } else { |
| - if (gridRowCount() <= rowPositions->finalPositionIndex || gridColumnCount() <= columnPositions->finalPositionIndex) { |
| - // FIXME: We could just insert the new child provided we had a primitive to arbitrarily grow the grid. |
| - dirtyGrid(); |
| - } else { |
| - insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *columnPositions)); |
| - } |
| + return; |
| } |
| + |
| + // Grow grid if required. |
|
Julien - ping for review
2014/03/21 18:27:19
Maybe we could turn that into a better comment:
/
|
| + if (gridRowCount() <= rowPositions->finalPositionIndex) |
| + growGrid(ForRows, rowPositions->finalPositionIndex - gridRowCount() + 1); |
| + if (gridColumnCount() <= columnPositions->finalPositionIndex) |
| + growGrid(ForColumns, columnPositions->finalPositionIndex - gridColumnCount() + 1); |
| + |
| + insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *columnPositions)); |
| } |
| void RenderGrid::removeChild(RenderObject* child) |
| @@ -709,16 +717,19 @@ bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire |
| } |
| #endif |
| -void RenderGrid::growGrid(GridTrackSizingDirection direction) |
| +void RenderGrid::growGrid(GridTrackSizingDirection direction, size_t positions) |
|
Julien - ping for review
2014/03/21 18:27:19
How about we pass in the _maximum_ position we wan
|
| { |
| + ASSERT(positions >= 1); |
| + |
| if (direction == ForColumns) { |
| const size_t oldColumnSize = m_grid[0].size(); |
| for (size_t row = 0; row < m_grid.size(); ++row) |
| - m_grid[row].grow(oldColumnSize + 1); |
| + m_grid[row].grow(oldColumnSize + positions); |
| } else { |
| const size_t oldRowSize = m_grid.size(); |
| - m_grid.grow(oldRowSize + 1); |
| - m_grid[oldRowSize].grow(m_grid[0].size()); |
| + m_grid.grow(oldRowSize + positions); |
| + for (size_t row = oldRowSize; row < m_grid.size(); ++row) |
| + m_grid[row].grow(m_grid[0].size()); |
| } |
| } |
| @@ -824,7 +835,7 @@ void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au |
| continue; |
| } |
| - growGrid(autoPlacementMinorAxisDirection()); |
| + growGrid(autoPlacementMinorAxisDirection(), 1); |
| OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); |
| ASSERT(emptyGridArea); |
| insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPositionIndex, emptyGridArea->columns.initialPositionIndex); |
| @@ -863,7 +874,7 @@ void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) |
| // We didn't find an empty grid area so we need to create an extra major axis line and insert our gridItem in it. |
| const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? m_grid[0].size() : minorAxisIndex; |
| const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? minorAxisIndex : m_grid.size(); |
| - growGrid(autoPlacementMajorAxisDirection()); |
| + growGrid(autoPlacementMajorAxisDirection(), 1); |
| insertItemIntoGrid(gridItem, rowIndex, columnIndex); |
| } |