| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/layout/Grid.h" | 5 #include "core/layout/Grid.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutGrid.h" | 7 #include "core/layout/LayoutGrid.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 m_grid[row].grow(numTracks(ForColumns)); | 24 m_grid[row].grow(numTracks(ForColumns)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 if (maximumColumnSize > numTracks(ForColumns)) { | 27 if (maximumColumnSize > numTracks(ForColumns)) { |
| 28 for (size_t row = 0; row < numTracks(ForRows); ++row) | 28 for (size_t row = 0; row < numTracks(ForRows); ++row) |
| 29 m_grid[row].grow(maximumColumnSize); | 29 m_grid[row].grow(maximumColumnSize); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 void Grid::insert(LayoutBox& child, const GridArea& area) { | 33 void Grid::insert(LayoutBox& child, const GridArea& area) { |
| 34 DCHECK(area.rows.isTranslatedDefinite() && | 34 DCHECK(area.rows.isTranslatedDefinite()); |
| 35 area.columns.isTranslatedDefinite()); | 35 DCHECK(area.columns.isTranslatedDefinite()); |
| 36 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 36 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
| 37 | 37 |
| 38 for (const auto& row : area.rows) { | 38 for (const auto& row : area.rows) { |
| 39 for (const auto& column : area.columns) | 39 for (const auto& column : area.columns) |
| 40 m_grid[row][column].push_back(&child); | 40 m_grid[row][column].push_back(&child); |
| 41 } | 41 } |
| 42 | 42 |
| 43 setGridItemArea(child, area); | 43 setGridItemArea(child, area); |
| 44 } | 44 } |
| 45 | 45 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 size_t varyingTrackIndex) | 157 size_t varyingTrackIndex) |
| 158 : m_grid(grid.m_grid), | 158 : m_grid(grid.m_grid), |
| 159 m_direction(direction), | 159 m_direction(direction), |
| 160 m_rowIndex((direction == ForColumns) ? varyingTrackIndex | 160 m_rowIndex((direction == ForColumns) ? varyingTrackIndex |
| 161 : fixedTrackIndex), | 161 : fixedTrackIndex), |
| 162 m_columnIndex((direction == ForColumns) ? fixedTrackIndex | 162 m_columnIndex((direction == ForColumns) ? fixedTrackIndex |
| 163 : varyingTrackIndex), | 163 : varyingTrackIndex), |
| 164 m_childIndex(0) { | 164 m_childIndex(0) { |
| 165 DCHECK(!m_grid.isEmpty()); | 165 DCHECK(!m_grid.isEmpty()); |
| 166 DCHECK(!m_grid[0].isEmpty()); | 166 DCHECK(!m_grid[0].isEmpty()); |
| 167 DCHECK(m_rowIndex < m_grid.size()); | 167 DCHECK_LT(m_rowIndex, m_grid.size()); |
| 168 DCHECK(m_columnIndex < m_grid[0].size()); | 168 DCHECK_LT(m_columnIndex, m_grid[0].size()); |
| 169 } | 169 } |
| 170 | 170 |
| 171 LayoutBox* GridIterator::nextGridItem() { | 171 LayoutBox* GridIterator::nextGridItem() { |
| 172 DCHECK(!m_grid.isEmpty()); | 172 DCHECK(!m_grid.isEmpty()); |
| 173 DCHECK(!m_grid[0].isEmpty()); | 173 DCHECK(!m_grid[0].isEmpty()); |
| 174 | 174 |
| 175 size_t& varyingTrackIndex = | 175 size_t& varyingTrackIndex = |
| 176 (m_direction == ForColumns) ? m_rowIndex : m_columnIndex; | 176 (m_direction == ForColumns) ? m_rowIndex : m_columnIndex; |
| 177 const size_t endOfVaryingTrackIndex = | 177 const size_t endOfVaryingTrackIndex = |
| 178 (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size(); | 178 (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 return true; | 207 return true; |
| 208 } | 208 } |
| 209 | 209 |
| 210 std::unique_ptr<GridArea> GridIterator::nextEmptyGridArea( | 210 std::unique_ptr<GridArea> GridIterator::nextEmptyGridArea( |
| 211 size_t fixedTrackSpan, | 211 size_t fixedTrackSpan, |
| 212 size_t varyingTrackSpan) { | 212 size_t varyingTrackSpan) { |
| 213 DCHECK(!m_grid.isEmpty()); | 213 DCHECK(!m_grid.isEmpty()); |
| 214 DCHECK(!m_grid[0].isEmpty()); | 214 DCHECK(!m_grid[0].isEmpty()); |
| 215 DCHECK(fixedTrackSpan >= 1 && varyingTrackSpan >= 1); | 215 DCHECK_GE(fixedTrackSpan, 1u); |
| 216 DCHECK_GE(varyingTrackSpan, 1u); |
| 216 | 217 |
| 217 size_t rowSpan = | 218 size_t rowSpan = |
| 218 (m_direction == ForColumns) ? varyingTrackSpan : fixedTrackSpan; | 219 (m_direction == ForColumns) ? varyingTrackSpan : fixedTrackSpan; |
| 219 size_t columnSpan = | 220 size_t columnSpan = |
| 220 (m_direction == ForColumns) ? fixedTrackSpan : varyingTrackSpan; | 221 (m_direction == ForColumns) ? fixedTrackSpan : varyingTrackSpan; |
| 221 | 222 |
| 222 size_t& varyingTrackIndex = | 223 size_t& varyingTrackIndex = |
| 223 (m_direction == ForColumns) ? m_rowIndex : m_columnIndex; | 224 (m_direction == ForColumns) ? m_rowIndex : m_columnIndex; |
| 224 const size_t endOfVaryingTrackIndex = | 225 const size_t endOfVaryingTrackIndex = |
| 225 (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size(); | 226 (m_direction == ForColumns) ? m_grid.size() : m_grid[0].size(); |
| 226 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { | 227 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex) { |
| 227 if (checkEmptyCells(rowSpan, columnSpan)) { | 228 if (checkEmptyCells(rowSpan, columnSpan)) { |
| 228 std::unique_ptr<GridArea> result = WTF::wrapUnique( | 229 std::unique_ptr<GridArea> result = WTF::wrapUnique( |
| 229 new GridArea(GridSpan::translatedDefiniteGridSpan( | 230 new GridArea(GridSpan::translatedDefiniteGridSpan( |
| 230 m_rowIndex, m_rowIndex + rowSpan), | 231 m_rowIndex, m_rowIndex + rowSpan), |
| 231 GridSpan::translatedDefiniteGridSpan( | 232 GridSpan::translatedDefiniteGridSpan( |
| 232 m_columnIndex, m_columnIndex + columnSpan))); | 233 m_columnIndex, m_columnIndex + columnSpan))); |
| 233 // Advance the iterator to avoid an infinite loop where we would return | 234 // Advance the iterator to avoid an infinite loop where we would return |
| 234 // the same grid area over and over. | 235 // the same grid area over and over. |
| 235 ++varyingTrackIndex; | 236 ++varyingTrackIndex; |
| 236 return result; | 237 return result; |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 return nullptr; | 240 return nullptr; |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |