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