OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 RenderBlock::addChild(newChild, beforeChild); | 184 RenderBlock::addChild(newChild, beforeChild); |
185 | 185 |
186 if (gridIsDirty()) | 186 if (gridIsDirty()) |
187 return; | 187 return; |
188 | 188 |
189 if (!newChild->isBox()) { | 189 if (!newChild->isBox()) { |
190 dirtyGrid(); | 190 dirtyGrid(); |
191 return; | 191 return; |
192 } | 192 } |
193 | 193 |
| 194 if (style()->gridAutoFlow() != AutoFlowNone) { |
| 195 // The grid needs to be recomputed as it might contain auto-placed items
that will change their position. |
| 196 dirtyGrid(); |
| 197 return; |
| 198 } |
| 199 |
194 RenderBox* newChildBox = toRenderBox(newChild); | 200 RenderBox* newChildBox = toRenderBox(newChild); |
195 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F
orRows); | 201 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F
orRows); |
196 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox
, ForColumns); | 202 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox
, ForColumns); |
197 if (!rowPositions || !columnPositions) { | 203 if (!rowPositions || !columnPositions) { |
198 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. | 204 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. |
199 dirtyGrid(); | 205 dirtyGrid(); |
| 206 return; |
200 } else { | 207 } else { |
201 if (gridRowCount() <= rowPositions->finalPositionIndex || gridColumnCoun
t() <= columnPositions->finalPositionIndex) { | 208 // Ensure that the grid is big enough to contain new grid item. |
202 // FIXME: We could just insert the new child provided we had a primi
tive to arbitrarily grow the grid. | 209 if (gridRowCount() <= rowPositions->finalPositionIndex) |
203 dirtyGrid(); | 210 growGrid(ForRows, rowPositions->finalPositionIndex); |
204 } else { | 211 if (gridColumnCount() <= columnPositions->finalPositionIndex) |
205 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *colum
nPositions)); | 212 growGrid(ForColumns, columnPositions->finalPositionIndex); |
206 } | 213 |
| 214 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *columnPos
itions)); |
207 } | 215 } |
208 } | 216 } |
209 | 217 |
210 void RenderGrid::removeChild(RenderObject* child) | 218 void RenderGrid::removeChild(RenderObject* child) |
211 { | 219 { |
212 RenderBlock::removeChild(child); | 220 RenderBlock::removeChild(child); |
213 | 221 |
214 if (gridIsDirty()) | 222 if (gridIsDirty()) |
215 return; | 223 return; |
216 | 224 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 for (size_t i = 0; i < tracks.size(); ++i) { | 710 for (size_t i = 0; i < tracks.size(); ++i) { |
703 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 711 const GridTrackSize& trackSize = gridTrackSize(direction, i); |
704 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 712 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
705 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].m_usedBreadth) | 713 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].m_usedBreadth) |
706 return false; | 714 return false; |
707 } | 715 } |
708 return true; | 716 return true; |
709 } | 717 } |
710 #endif | 718 #endif |
711 | 719 |
712 void RenderGrid::growGrid(GridTrackSizingDirection direction) | 720 void RenderGrid::growGrid(GridTrackSizingDirection direction, size_t maximumPosi
tionIndex) |
713 { | 721 { |
714 if (direction == ForColumns) { | 722 if (direction == ForColumns) { |
715 const size_t oldColumnSize = m_grid[0].size(); | 723 ASSERT(maximumPositionIndex >= m_grid[0].size()); |
716 for (size_t row = 0; row < m_grid.size(); ++row) | 724 for (size_t row = 0; row < m_grid.size(); ++row) |
717 m_grid[row].grow(oldColumnSize + 1); | 725 m_grid[row].grow(maximumPositionIndex + 1); |
718 } else { | 726 } else { |
| 727 ASSERT(maximumPositionIndex >= m_grid.size()); |
719 const size_t oldRowSize = m_grid.size(); | 728 const size_t oldRowSize = m_grid.size(); |
720 m_grid.grow(oldRowSize + 1); | 729 m_grid.grow(maximumPositionIndex + 1); |
721 m_grid[oldRowSize].grow(m_grid[0].size()); | 730 for (size_t row = oldRowSize; row < m_grid.size(); ++row) |
| 731 m_grid[row].grow(m_grid[0].size()); |
722 } | 732 } |
723 } | 733 } |
724 | 734 |
725 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor
dinate) | 735 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor
dinate) |
726 { | 736 { |
727 for (size_t row = coordinate.rows.initialPositionIndex; row <= coordinate.ro
ws.finalPositionIndex; ++row) { | 737 for (size_t row = coordinate.rows.initialPositionIndex; row <= coordinate.ro
ws.finalPositionIndex; ++row) { |
728 for (size_t column = coordinate.columns.initialPositionIndex; column <=
coordinate.columns.finalPositionIndex; ++column) | 738 for (size_t column = coordinate.columns.initialPositionIndex; column <=
coordinate.columns.finalPositionIndex; ++column) |
729 m_grid[row][column].append(child); | 739 m_grid[row][column].append(child); |
730 } | 740 } |
731 | 741 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au
toGridItems) | 827 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au
toGridItems) |
818 { | 828 { |
819 for (size_t i = 0; i < autoGridItems.size(); ++i) { | 829 for (size_t i = 0; i < autoGridItems.size(); ++i) { |
820 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); | 830 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); |
821 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex); | 831 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex); |
822 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ | 832 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ |
823 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex, emptyGridArea->columns.initialPositionIndex); | 833 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex, emptyGridArea->columns.initialPositionIndex); |
824 continue; | 834 continue; |
825 } | 835 } |
826 | 836 |
827 growGrid(autoPlacementMinorAxisDirection()); | 837 growGrid(autoPlacementMinorAxisDirection(), autoPlacementMinorAxisDirect
ion() == ForColumns ? m_grid[0].size() : m_grid.size()); |
828 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); | 838 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); |
829 ASSERT(emptyGridArea); | 839 ASSERT(emptyGridArea); |
830 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); | 840 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); |
831 } | 841 } |
832 } | 842 } |
833 | 843 |
834 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri
dItems) | 844 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri
dItems) |
835 { | 845 { |
836 for (size_t i = 0; i < autoGridItems.size(); ++i) | 846 for (size_t i = 0; i < autoGridItems.size(); ++i) |
837 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); | 847 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); |
(...skipping 18 matching lines...) Expand all Loading... |
856 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre
a()) { | 866 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre
a()) { |
857 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); | 867 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); |
858 return; | 868 return; |
859 } | 869 } |
860 } | 870 } |
861 } | 871 } |
862 | 872 |
863 // We didn't find an empty grid area so we need to create an extra major axi
s line and insert our gridItem in it. | 873 // We didn't find an empty grid area so we need to create an extra major axi
s line and insert our gridItem in it. |
864 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns)
? m_grid[0].size() : minorAxisIndex; | 874 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns)
? m_grid[0].size() : minorAxisIndex; |
865 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ?
minorAxisIndex : m_grid.size(); | 875 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ?
minorAxisIndex : m_grid.size(); |
866 growGrid(autoPlacementMajorAxisDirection()); | 876 growGrid(autoPlacementMajorAxisDirection(), autoPlacementMajorAxisDirection(
) == ForColumns ? m_grid[0].size() : m_grid.size()); |
867 insertItemIntoGrid(gridItem, rowIndex, columnIndex); | 877 insertItemIntoGrid(gridItem, rowIndex, columnIndex); |
868 } | 878 } |
869 | 879 |
870 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const | 880 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const |
871 { | 881 { |
872 GridAutoFlow flow = style()->gridAutoFlow(); | 882 GridAutoFlow flow = style()->gridAutoFlow(); |
873 ASSERT(flow != AutoFlowNone); | 883 ASSERT(flow != AutoFlowNone); |
874 return (flow == AutoFlowColumn) ? ForColumns : ForRows; | 884 return (flow == AutoFlowColumn) ? ForColumns : ForRows; |
875 } | 885 } |
876 | 886 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 if (isOutOfFlowPositioned()) | 1392 if (isOutOfFlowPositioned()) |
1383 return "RenderGrid (positioned)"; | 1393 return "RenderGrid (positioned)"; |
1384 if (isAnonymous()) | 1394 if (isAnonymous()) |
1385 return "RenderGrid (generated)"; | 1395 return "RenderGrid (generated)"; |
1386 if (isRelPositioned()) | 1396 if (isRelPositioned()) |
1387 return "RenderGrid (relative positioned)"; | 1397 return "RenderGrid (relative positioned)"; |
1388 return "RenderGrid"; | 1398 return "RenderGrid"; |
1389 } | 1399 } |
1390 | 1400 |
1391 } // namespace WebCore | 1401 } // namespace WebCore |
OLD | NEW |