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 spanningAreas) |
Julien - ping for review
2014/03/21 18:18:02
Note that this introduces some O(N^2) behavior. It
| |
126 { | |
127 if (m_direction == ForColumns) { | |
128 for (size_t i = m_columnIndex; i < m_columnIndex + spanningAreas; ++ i) { | |
129 const GridCell& children = m_grid[m_rowIndex][i]; | |
130 if (!children.isEmpty()) | |
131 return false; | |
132 } | |
133 } else { | |
134 for (size_t i = m_rowIndex; i < m_rowIndex + spanningAreas; ++i) { | |
135 const GridCell& children = m_grid[i][m_columnIndex]; | |
136 if (!children.isEmpty()) | |
137 return false; | |
138 } | |
139 } | |
140 | |
141 return true; | |
142 } | |
143 | |
144 PassOwnPtr<GridCoordinate> nextEmptyGridArea(size_t spanningAreas) | |
Julien - ping for review
2014/03/21 18:18:02
It is weird to have the *same* |spanningAreas| for
| |
126 { | 145 { |
127 ASSERT(!m_grid.isEmpty()); | 146 ASSERT(!m_grid.isEmpty()); |
147 ASSERT(spanningAreas >= 1); | |
128 | 148 |
129 size_t& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m _columnIndex; | 149 size_t& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m _columnIndex; |
130 const size_t endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_gr id.size() : m_grid[0].size(); | 150 const size_t endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_gr id.size() : m_grid[0].size(); |
131 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { | 151 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { |
132 const GridCell& children = m_grid[m_rowIndex][m_columnIndex]; | 152 if (areCellsEmpty(spanningAreas)) { |
133 if (children.isEmpty()) { | 153 GridSpan rowSpan = GridSpan(m_rowIndex, (m_direction == ForColum ns) ? m_rowIndex : m_rowIndex + spanningAreas - 1); |
134 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate(Grid Span(m_rowIndex, m_rowIndex), GridSpan(m_columnIndex, m_columnIndex))); | 154 GridSpan columnSpan = GridSpan(m_columnIndex, (m_direction == Fo rColumns) ? m_columnIndex + spanningAreas - 1 : m_columnIndex); |
155 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate(rowS pan, columnSpan)); | |
Julien - ping for review
2014/03/21 18:18:02
I wonder if just having a single m_direction == Fo
| |
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 would return the same grid area over and over. |
136 ++varyingTrackIndex; | 157 ++varyingTrackIndex; |
137 return result.release(); | 158 return result.release(); |
138 } | 159 } |
139 } | 160 } |
140 return nullptr; | 161 return nullptr; |
141 } | 162 } |
142 | 163 |
143 private: | 164 private: |
144 const GridRepresentation& m_grid; | 165 const GridRepresentation& m_grid; |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 m_grid.grow(maximumRowIndex); | 833 m_grid.grow(maximumRowIndex); |
813 for (size_t i = 0; i < m_grid.size(); ++i) | 834 for (size_t i = 0; i < m_grid.size(); ++i) |
814 m_grid[i].grow(maximumColumnIndex); | 835 m_grid[i].grow(maximumColumnIndex); |
815 } | 836 } |
816 | 837 |
817 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems) | 838 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems) |
818 { | 839 { |
819 for (size_t i = 0; i < autoGridItems.size(); ++i) { | 840 for (size_t i = 0; i < autoGridItems.size(); ++i) { |
820 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection()); | 841 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection()); |
821 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex); | 842 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex); |
822 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) { | 843 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(ma jorAxisPositions->finalPositionIndex - majorAxisPositions->initialPositionIndex + 1)) { |
Julien - ping for review
2014/03/21 18:18:02
How about adding a helper function to return the s
| |
823 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi tionIndex, emptyGridArea->columns.initialPositionIndex); | 844 insertItemIntoGrid(autoGridItems[i], *emptyGridArea); |
824 continue; | 845 continue; |
825 } | 846 } |
826 | 847 |
827 growGrid(autoPlacementMinorAxisDirection()); | 848 growGrid(autoPlacementMinorAxisDirection()); |
828 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); | 849 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA xisPositions->finalPositionIndex - majorAxisPositions->initialPositionIndex + 1) ; |
829 ASSERT(emptyGridArea); | 850 ASSERT(emptyGridArea); |
830 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); | 851 insertItemIntoGrid(autoGridItems[i], *emptyGridArea); |
831 } | 852 } |
832 } | 853 } |
833 | 854 |
834 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems) | 855 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems) |
835 { | 856 { |
836 for (size_t i = 0; i < autoGridItems.size(); ++i) | 857 for (size_t i = 0; i < autoGridItems.size(); ++i) |
837 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); | 858 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); |
838 } | 859 } |
839 | 860 |
840 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) | 861 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) |
841 { | 862 { |
842 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem , autoPlacementMinorAxisDirection()); | 863 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem , autoPlacementMinorAxisDirection()); |
843 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect ion())); | 864 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect ion())); |
844 size_t minorAxisIndex = 0; | |
845 if (minorAxisPositions) { | 865 if (minorAxisPositions) { |
846 minorAxisIndex = minorAxisPositions->initialPositionIndex; | 866 size_t minorAxisIndex = minorAxisPositions->initialPositionIndex; |
847 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx isIndex); | 867 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx isIndex); |
848 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) { | 868 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(mi norAxisPositions->finalPositionIndex - minorAxisPositions->initialPositionIndex + 1)) { |
849 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPositionInde x, emptyGridArea->columns.initialPositionIndex); | 869 insertItemIntoGrid(gridItem, *emptyGridArea); |
850 return; | 870 return; |
851 } | 871 } |
852 } else { | 872 } else { |
853 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC olumns) ? gridColumnCount() : gridRowCount(); | 873 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC olumns) ? gridColumnCount() : gridRowCount(); |
854 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major AxisIndex) { | 874 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major AxisIndex) { |
855 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex); | 875 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex); |
856 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a()) { | 876 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a(1)) { |
857 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); | 877 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); |
858 return; | 878 return; |
859 } | 879 } |
860 } | 880 } |
861 } | 881 } |
862 | 882 |
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. | 883 // 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; | 884 GridSpan minorAxisSpan = minorAxisPositions ? *minorAxisPositions : GridSpan (0, 0); |
865 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? minorAxisIndex : m_grid.size(); | 885 GridSpan columnSpan = (autoPlacementMajorAxisDirection() == ForColumns) ? Gr idSpan(m_grid[0].size(), m_grid[0].size()) : minorAxisSpan; |
886 GridSpan rowSpan = (autoPlacementMajorAxisDirection() == ForColumns) ? minor AxisSpan : GridSpan(m_grid.size(), m_grid.size()); | |
866 growGrid(autoPlacementMajorAxisDirection()); | 887 growGrid(autoPlacementMajorAxisDirection()); |
867 insertItemIntoGrid(gridItem, rowIndex, columnIndex); | 888 insertItemIntoGrid(gridItem, GridCoordinate(rowSpan, columnSpan)); |
868 } | 889 } |
869 | 890 |
870 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const | 891 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const |
871 { | 892 { |
872 GridAutoFlow flow = style()->gridAutoFlow(); | 893 GridAutoFlow flow = style()->gridAutoFlow(); |
873 ASSERT(flow != AutoFlowNone); | 894 ASSERT(flow != AutoFlowNone); |
874 return (flow == AutoFlowColumn) ? ForColumns : ForRows; | 895 return (flow == AutoFlowColumn) ? ForColumns : ForRows; |
875 } | 896 } |
876 | 897 |
877 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const | 898 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1382 if (isOutOfFlowPositioned()) | 1403 if (isOutOfFlowPositioned()) |
1383 return "RenderGrid (positioned)"; | 1404 return "RenderGrid (positioned)"; |
1384 if (isAnonymous()) | 1405 if (isAnonymous()) |
1385 return "RenderGrid (generated)"; | 1406 return "RenderGrid (generated)"; |
1386 if (isRelPositioned()) | 1407 if (isRelPositioned()) |
1387 return "RenderGrid (relative positioned)"; | 1408 return "RenderGrid (relative positioned)"; |
1388 return "RenderGrid"; | 1409 return "RenderGrid"; |
1389 } | 1410 } |
1390 | 1411 |
1391 } // namespace WebCore | 1412 } // namespace WebCore |
OLD | NEW |