| Index: Source/core/rendering/RenderGrid.cpp
|
| diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp
|
| index 351881084b582f24de06651ade28f7fd5595239d..0cd0be39b5e6eac5a7a4f2f24ec9e9e59b421fea 100644
|
| --- a/Source/core/rendering/RenderGrid.cpp
|
| +++ b/Source/core/rendering/RenderGrid.cpp
|
| @@ -191,19 +191,27 @@ 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();
|
| + return;
|
| } 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));
|
| - }
|
| + // Ensure that the grid is big enough to contain new grid item.
|
| + if (gridRowCount() <= rowPositions->finalPositionIndex)
|
| + growGrid(ForRows, rowPositions->finalPositionIndex);
|
| + if (gridColumnCount() <= columnPositions->finalPositionIndex)
|
| + growGrid(ForColumns, columnPositions->finalPositionIndex);
|
| +
|
| + insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *columnPositions));
|
| }
|
| }
|
|
|
| @@ -709,16 +717,18 @@ bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire
|
| }
|
| #endif
|
|
|
| -void RenderGrid::growGrid(GridTrackSizingDirection direction)
|
| +void RenderGrid::growGrid(GridTrackSizingDirection direction, size_t maximumPositionIndex)
|
| {
|
| if (direction == ForColumns) {
|
| - const size_t oldColumnSize = m_grid[0].size();
|
| + ASSERT(maximumPositionIndex >= m_grid[0].size());
|
| for (size_t row = 0; row < m_grid.size(); ++row)
|
| - m_grid[row].grow(oldColumnSize + 1);
|
| + m_grid[row].grow(maximumPositionIndex + 1);
|
| } else {
|
| + ASSERT(maximumPositionIndex >= m_grid.size());
|
| const size_t oldRowSize = m_grid.size();
|
| - m_grid.grow(oldRowSize + 1);
|
| - m_grid[oldRowSize].grow(m_grid[0].size());
|
| + m_grid.grow(maximumPositionIndex + 1);
|
| + for (size_t row = oldRowSize; row < m_grid.size(); ++row)
|
| + m_grid[row].grow(m_grid[0].size());
|
| }
|
| }
|
|
|
| @@ -824,7 +834,7 @@ void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au
|
| continue;
|
| }
|
|
|
| - growGrid(autoPlacementMinorAxisDirection());
|
| + growGrid(autoPlacementMinorAxisDirection(), autoPlacementMinorAxisDirection() == ForColumns ? m_grid[0].size() : m_grid.size());
|
| OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea();
|
| ASSERT(emptyGridArea);
|
| insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPositionIndex, emptyGridArea->columns.initialPositionIndex);
|
| @@ -863,7 +873,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(), autoPlacementMajorAxisDirection() == ForColumns ? m_grid[0].size() : m_grid.size());
|
| insertItemIntoGrid(gridItem, rowIndex, columnIndex);
|
| }
|
|
|
|
|