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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { | 115 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { |
116 const GridCell& children = m_grid[m_rowIndex][m_columnIndex]; | 116 const GridCell& children = m_grid[m_rowIndex][m_columnIndex]; |
117 if (m_childIndex < children.size()) | 117 if (m_childIndex < children.size()) |
118 return children[m_childIndex++]; | 118 return children[m_childIndex++]; |
119 | 119 |
120 m_childIndex = 0; | 120 m_childIndex = 0; |
121 } | 121 } |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 | 124 |
125 PassOwnPtr<GridCoordinate> nextEmptyGridArea() | 125 bool areCellsEmpty(size_t spanningPositions) |
126 { | |
127 // This adds a O(N^2) behavior that shouldn't be a big deal as we expect spanning areas to be small. | |
128 if (m_direction == ForColumns) { | |
129 for (size_t i = m_columnIndex; i < m_columnIndex + spanningPositions ; ++i) { | |
130 const GridCell& children = m_grid[m_rowIndex][i]; | |
131 if (!children.isEmpty()) | |
132 return false; | |
133 } | |
134 } else { | |
135 for (size_t i = m_rowIndex; i < m_rowIndex + spanningPositions; ++i) { | |
136 const GridCell& children = m_grid[i][m_columnIndex]; | |
137 if (!children.isEmpty()) | |
138 return false; | |
139 } | |
140 } | |
141 | |
142 return true; | |
143 } | |
144 | |
145 PassOwnPtr<GridCoordinate> nextEmptyGridArea(size_t spanningPositions) | |
Julien - ping for review
2014/04/04 00:10:16
|spanningPositions| confuses me: that's because it
| |
126 { | 146 { |
127 ASSERT(!m_grid.isEmpty()); | 147 ASSERT(!m_grid.isEmpty()); |
148 ASSERT(spanningPositions >= 1); | |
128 | 149 |
129 size_t& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m _columnIndex; | 150 if (m_direction == ForColumns) { |
130 const size_t endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_gr id.size() : m_grid[0].size(); | 151 for (; m_rowIndex < m_grid.size(); ++m_rowIndex) { |
131 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { | 152 if (areCellsEmpty(spanningPositions)) { |
132 const GridCell& children = m_grid[m_rowIndex][m_columnIndex]; | 153 GridSpan rowSpan = GridSpan(m_rowIndex, m_rowIndex); |
133 if (children.isEmpty()) { | 154 GridSpan columnSpan = GridSpan(m_columnIndex, m_columnIndex + spanningPositions - 1); |
134 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate(Grid Span(m_rowIndex, m_rowIndex), GridSpan(m_columnIndex, m_columnIndex))); | 155 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate( rowSpan, columnSpan)); |
135 // Advance the iterator to avoid an infinite loop where we would return the same grid area over and over. | 156 // Advance the iterator to avoid an infinite loop where we w ould return the same grid area over and over. |
136 ++varyingTrackIndex; | 157 ++m_rowIndex; |
137 return result.release(); | 158 return result.release(); |
159 } | |
160 } | |
161 } else { | |
162 for (; m_columnIndex < m_grid[0].size(); ++m_columnIndex) { | |
163 if (areCellsEmpty(spanningPositions)) { | |
164 GridSpan rowSpan = GridSpan(m_rowIndex, m_rowIndex + spannin gPositions - 1); | |
165 GridSpan columnSpan = GridSpan(m_columnIndex, m_columnIndex) ; | |
166 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate( rowSpan, columnSpan)); | |
167 // Advance the iterator to avoid an infinite loop where we w ould return the same grid area over and over. | |
168 ++m_columnIndex; | |
169 return result.release(); | |
170 } | |
138 } | 171 } |
139 } | 172 } |
173 | |
140 return nullptr; | 174 return nullptr; |
141 } | 175 } |
142 | 176 |
143 private: | 177 private: |
144 const GridRepresentation& m_grid; | 178 const GridRepresentation& m_grid; |
145 GridTrackSizingDirection m_direction; | 179 GridTrackSizingDirection m_direction; |
146 size_t m_rowIndex; | 180 size_t m_rowIndex; |
147 size_t m_columnIndex; | 181 size_t m_columnIndex; |
148 size_t m_childIndex; | 182 size_t m_childIndex; |
149 }; | 183 }; |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 m_grid.grow(maximumRowIndex); | 846 m_grid.grow(maximumRowIndex); |
813 for (size_t i = 0; i < m_grid.size(); ++i) | 847 for (size_t i = 0; i < m_grid.size(); ++i) |
814 m_grid[i].grow(maximumColumnIndex); | 848 m_grid[i].grow(maximumColumnIndex); |
815 } | 849 } |
816 | 850 |
817 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems) | 851 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems) |
818 { | 852 { |
819 for (size_t i = 0; i < autoGridItems.size(); ++i) { | 853 for (size_t i = 0; i < autoGridItems.size(); ++i) { |
820 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection()); | 854 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection()); |
821 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex); | 855 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex); |
822 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) { | 856 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(ma jorAxisPositions->spanningPositions())) { |
823 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi tionIndex, emptyGridArea->columns.initialPositionIndex); | 857 insertItemIntoGrid(autoGridItems[i], *emptyGridArea); |
824 continue; | 858 continue; |
825 } | 859 } |
826 | 860 |
827 growGrid(autoPlacementMinorAxisDirection()); | 861 growGrid(autoPlacementMinorAxisDirection()); |
828 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); | 862 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA xisPositions->spanningPositions()); |
829 ASSERT(emptyGridArea); | 863 ASSERT(emptyGridArea); |
830 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); | 864 insertItemIntoGrid(autoGridItems[i], *emptyGridArea); |
831 } | 865 } |
832 } | 866 } |
833 | 867 |
834 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems) | 868 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems) |
835 { | 869 { |
836 for (size_t i = 0; i < autoGridItems.size(); ++i) | 870 for (size_t i = 0; i < autoGridItems.size(); ++i) |
837 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); | 871 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); |
838 } | 872 } |
839 | 873 |
840 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) | 874 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) |
841 { | 875 { |
842 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem , autoPlacementMinorAxisDirection()); | 876 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem , autoPlacementMinorAxisDirection()); |
843 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect ion())); | 877 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect ion())); |
844 size_t minorAxisIndex = 0; | |
845 if (minorAxisPositions) { | 878 if (minorAxisPositions) { |
846 minorAxisIndex = minorAxisPositions->initialPositionIndex; | 879 size_t minorAxisIndex = minorAxisPositions->initialPositionIndex; |
847 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx isIndex); | 880 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx isIndex); |
848 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) { | 881 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(mi norAxisPositions->spanningPositions())) { |
849 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPositionInde x, emptyGridArea->columns.initialPositionIndex); | 882 insertItemIntoGrid(gridItem, *emptyGridArea); |
850 return; | 883 return; |
851 } | 884 } |
852 } else { | 885 } else { |
853 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC olumns) ? gridColumnCount() : gridRowCount(); | 886 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC olumns) ? gridColumnCount() : gridRowCount(); |
854 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major AxisIndex) { | 887 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major AxisIndex) { |
855 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex); | 888 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex); |
856 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a()) { | 889 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a(1)) { |
857 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); | 890 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); |
858 return; | 891 return; |
859 } | 892 } |
860 } | 893 } |
861 } | 894 } |
862 | 895 |
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. | 896 // 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; | 897 GridSpan minorAxisSpan = minorAxisPositions ? *minorAxisPositions : GridSpan (0, 0); |
865 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? minorAxisIndex : m_grid.size(); | 898 GridSpan columnSpan = (autoPlacementMajorAxisDirection() == ForColumns) ? Gr idSpan(m_grid[0].size(), m_grid[0].size()) : minorAxisSpan; |
899 GridSpan rowSpan = (autoPlacementMajorAxisDirection() == ForColumns) ? minor AxisSpan : GridSpan(m_grid.size(), m_grid.size()); | |
866 growGrid(autoPlacementMajorAxisDirection()); | 900 growGrid(autoPlacementMajorAxisDirection()); |
867 insertItemIntoGrid(gridItem, rowIndex, columnIndex); | 901 insertItemIntoGrid(gridItem, GridCoordinate(rowSpan, columnSpan)); |
868 } | 902 } |
869 | 903 |
870 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const | 904 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const |
871 { | 905 { |
872 GridAutoFlow flow = style()->gridAutoFlow(); | 906 GridAutoFlow flow = style()->gridAutoFlow(); |
873 ASSERT(flow != AutoFlowNone); | 907 ASSERT(flow != AutoFlowNone); |
874 return (flow == AutoFlowColumn) ? ForColumns : ForRows; | 908 return (flow == AutoFlowColumn) ? ForColumns : ForRows; |
875 } | 909 } |
876 | 910 |
877 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const | 911 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 if (isOutOfFlowPositioned()) | 1416 if (isOutOfFlowPositioned()) |
1383 return "RenderGrid (positioned)"; | 1417 return "RenderGrid (positioned)"; |
1384 if (isAnonymous()) | 1418 if (isAnonymous()) |
1385 return "RenderGrid (generated)"; | 1419 return "RenderGrid (generated)"; |
1386 if (isRelPositioned()) | 1420 if (isRelPositioned()) |
1387 return "RenderGrid (relative positioned)"; | 1421 return "RenderGrid (relative positioned)"; |
1388 return "RenderGrid"; | 1422 return "RenderGrid"; |
1389 } | 1423 } |
1390 | 1424 |
1391 } // namespace WebCore | 1425 } // namespace WebCore |
OLD | NEW |