| 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 24 matching lines...) Expand all Loading... |
| 35 #include "wtf/PtrUtil.h" | 35 #include "wtf/PtrUtil.h" |
| 36 #include <algorithm> | 36 #include <algorithm> |
| 37 #include <memory> | 37 #include <memory> |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 static const int infinity = -1; | 41 static const int infinity = -1; |
| 42 | 42 |
| 43 class GridItemWithSpan; | 43 class GridItemWithSpan; |
| 44 | 44 |
| 45 void LayoutGrid::Grid::ensureGridSize(size_t maximumRowSize, |
| 46 size_t maximumColumnSize) { |
| 47 const size_t oldRowSize = numRows(); |
| 48 if (maximumRowSize > oldRowSize) { |
| 49 m_grid.grow(maximumRowSize); |
| 50 for (size_t row = oldRowSize; row < numRows(); ++row) |
| 51 m_grid[row].grow(numColumns()); |
| 52 } |
| 53 |
| 54 if (maximumColumnSize > numColumns()) { |
| 55 for (size_t row = 0; row < numRows(); ++row) |
| 56 m_grid[row].grow(maximumColumnSize); |
| 57 } |
| 58 } |
| 59 |
| 60 void LayoutGrid::Grid::insert(LayoutBox& child, const GridArea& area) { |
| 61 DCHECK(area.rows.isTranslatedDefinite() && |
| 62 area.columns.isTranslatedDefinite()); |
| 63 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
| 64 |
| 65 for (const auto& row : area.rows) { |
| 66 for (const auto& column : area.columns) |
| 67 m_grid[row][column].append(&child); |
| 68 } |
| 69 } |
| 70 |
| 71 void LayoutGrid::Grid::clear() { |
| 72 m_grid.resize(0); |
| 73 } |
| 74 |
| 45 class GridTrack { | 75 class GridTrack { |
| 46 public: | 76 public: |
| 47 GridTrack() : m_infinitelyGrowable(false) {} | 77 GridTrack() : m_infinitelyGrowable(false) {} |
| 48 | 78 |
| 49 LayoutUnit baseSize() const { | 79 LayoutUnit baseSize() const { |
| 50 DCHECK(isGrowthLimitBiggerThanBaseSize()); | 80 DCHECK(isGrowthLimitBiggerThanBaseSize()); |
| 51 return m_baseSize; | 81 return m_baseSize; |
| 52 } | 82 } |
| 53 | 83 |
| 54 LayoutUnit growthLimit() const { | 84 LayoutUnit growthLimit() const { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 ForbidInfinity, | 175 ForbidInfinity, |
| 146 }; | 176 }; |
| 147 | 177 |
| 148 class LayoutGrid::GridIterator { | 178 class LayoutGrid::GridIterator { |
| 149 WTF_MAKE_NONCOPYABLE(GridIterator); | 179 WTF_MAKE_NONCOPYABLE(GridIterator); |
| 150 | 180 |
| 151 public: | 181 public: |
| 152 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g | 182 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g |
| 153 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd | 183 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd |
| 154 // column. | 184 // column. |
| 155 GridIterator(const GridRepresentation& grid, | 185 GridIterator(const Grid& grid, |
| 156 GridTrackSizingDirection direction, | 186 GridTrackSizingDirection direction, |
| 157 size_t fixedTrackIndex, | 187 size_t fixedTrackIndex, |
| 158 size_t varyingTrackIndex = 0) | 188 size_t varyingTrackIndex = 0) |
| 159 : m_grid(grid), | 189 : m_grid(grid.m_grid), |
| 160 m_direction(direction), | 190 m_direction(direction), |
| 161 m_rowIndex((direction == ForColumns) ? varyingTrackIndex | 191 m_rowIndex((direction == ForColumns) ? varyingTrackIndex |
| 162 : fixedTrackIndex), | 192 : fixedTrackIndex), |
| 163 m_columnIndex((direction == ForColumns) ? fixedTrackIndex | 193 m_columnIndex((direction == ForColumns) ? fixedTrackIndex |
| 164 : varyingTrackIndex), | 194 : varyingTrackIndex), |
| 165 m_childIndex(0) { | 195 m_childIndex(0) { |
| 166 DCHECK(!m_grid.isEmpty()); | 196 DCHECK(!m_grid.isEmpty()); |
| 167 DCHECK(!m_grid[0].isEmpty()); | 197 DCHECK(!m_grid[0].isEmpty()); |
| 168 DCHECK(m_rowIndex < m_grid.size()); | 198 DCHECK(m_rowIndex < m_grid.size()); |
| 169 DCHECK(m_columnIndex < m_grid[0].size()); | 199 DCHECK(m_columnIndex < m_grid[0].size()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Advance the iterator to avoid an infinite loop where we would return | 263 // Advance the iterator to avoid an infinite loop where we would return |
| 234 // the same grid area over and over. | 264 // the same grid area over and over. |
| 235 ++varyingTrackIndex; | 265 ++varyingTrackIndex; |
| 236 return result; | 266 return result; |
| 237 } | 267 } |
| 238 } | 268 } |
| 239 return nullptr; | 269 return nullptr; |
| 240 } | 270 } |
| 241 | 271 |
| 242 private: | 272 private: |
| 243 const GridRepresentation& m_grid; | 273 const GridAsMatrix& m_grid; |
| 244 GridTrackSizingDirection m_direction; | 274 GridTrackSizingDirection m_direction; |
| 245 size_t m_rowIndex; | 275 size_t m_rowIndex; |
| 246 size_t m_columnIndex; | 276 size_t m_columnIndex; |
| 247 size_t m_childIndex; | 277 size_t m_childIndex; |
| 248 }; | 278 }; |
| 249 | 279 |
| 250 struct LayoutGrid::GridSizingData { | 280 struct LayoutGrid::GridSizingData { |
| 251 WTF_MAKE_NONCOPYABLE(GridSizingData); | 281 WTF_MAKE_NONCOPYABLE(GridSizingData); |
| 252 STACK_ALLOCATED(); | 282 STACK_ALLOCATED(); |
| 253 | 283 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 423 } |
| 394 | 424 |
| 395 bool LayoutGrid::namedGridLinesDefinitionDidChange( | 425 bool LayoutGrid::namedGridLinesDefinitionDidChange( |
| 396 const ComputedStyle& oldStyle) const { | 426 const ComputedStyle& oldStyle) const { |
| 397 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || | 427 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || |
| 398 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); | 428 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); |
| 399 } | 429 } |
| 400 | 430 |
| 401 size_t LayoutGrid::gridColumnCount() const { | 431 size_t LayoutGrid::gridColumnCount() const { |
| 402 DCHECK(!m_gridIsDirty); | 432 DCHECK(!m_gridIsDirty); |
| 403 return m_grid.size() ? m_grid[0].size() : 0; | 433 return m_grid.numColumns(); |
| 404 } | 434 } |
| 405 | 435 |
| 406 size_t LayoutGrid::gridRowCount() const { | 436 size_t LayoutGrid::gridRowCount() const { |
| 407 DCHECK(!m_gridIsDirty); | 437 DCHECK(!m_gridIsDirty); |
| 408 return m_grid.size(); | 438 return m_grid.numRows(); |
| 409 } | 439 } |
| 410 | 440 |
| 411 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( | 441 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( |
| 412 const GridSizingData& sizingData) const { | 442 const GridSizingData& sizingData) const { |
| 413 LayoutUnit logicalHeight; | 443 LayoutUnit logicalHeight; |
| 414 | 444 |
| 415 for (const auto& row : sizingData.rowTracks) | 445 for (const auto& row : sizingData.rowTracks) |
| 416 logicalHeight += row.baseSize(); | 446 logicalHeight += row.baseSize(); |
| 417 | 447 |
| 418 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), | 448 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), |
| (...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 GridTrackSize trackSize = | 1820 GridTrackSize trackSize = |
| 1791 gridTrackSize(direction, i, sizingData.sizingOperation); | 1821 gridTrackSize(direction, i, sizingData.sizingOperation); |
| 1792 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > | 1822 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > |
| 1793 tracks[i].baseSize()) | 1823 tracks[i].baseSize()) |
| 1794 return false; | 1824 return false; |
| 1795 } | 1825 } |
| 1796 return true; | 1826 return true; |
| 1797 } | 1827 } |
| 1798 #endif | 1828 #endif |
| 1799 | 1829 |
| 1800 void LayoutGrid::ensureGridSize(size_t maximumRowSize, | |
| 1801 size_t maximumColumnSize) { | |
| 1802 const size_t oldRowSize = gridRowCount(); | |
| 1803 if (maximumRowSize > oldRowSize) { | |
| 1804 m_grid.grow(maximumRowSize); | |
| 1805 for (size_t row = oldRowSize; row < gridRowCount(); ++row) | |
| 1806 m_grid[row].grow(gridColumnCount()); | |
| 1807 } | |
| 1808 | |
| 1809 if (maximumColumnSize > gridColumnCount()) { | |
| 1810 for (size_t row = 0; row < gridRowCount(); ++row) | |
| 1811 m_grid[row].grow(maximumColumnSize); | |
| 1812 } | |
| 1813 } | |
| 1814 | |
| 1815 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridArea& area) { | |
| 1816 RELEASE_ASSERT(area.rows.isTranslatedDefinite() && | |
| 1817 area.columns.isTranslatedDefinite()); | |
| 1818 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | |
| 1819 | |
| 1820 for (const auto& row : area.rows) { | |
| 1821 for (const auto& column : area.columns) | |
| 1822 m_grid[row][column].append(&child); | |
| 1823 } | |
| 1824 } | |
| 1825 | |
| 1826 size_t LayoutGrid::computeAutoRepeatTracksCount( | 1830 size_t LayoutGrid::computeAutoRepeatTracksCount( |
| 1827 GridTrackSizingDirection direction, | 1831 GridTrackSizingDirection direction, |
| 1828 SizingOperation sizingOperation) const { | 1832 SizingOperation sizingOperation) const { |
| 1829 bool isRowAxis = direction == ForColumns; | 1833 bool isRowAxis = direction == ForColumns; |
| 1830 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns() | 1834 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns() |
| 1831 : styleRef().gridAutoRepeatRows(); | 1835 : styleRef().gridAutoRepeatRows(); |
| 1832 size_t autoRepeatTrackListLength = autoRepeatTracks.size(); | 1836 size_t autoRepeatTrackListLength = autoRepeatTracks.size(); |
| 1833 | 1837 |
| 1834 if (!autoRepeatTrackListLength) | 1838 if (!autoRepeatTrackListLength) |
| 1835 return 0; | 1839 return 0; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 2011 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 2008 GridSpan majorAxisPositions = | 2012 GridSpan majorAxisPositions = |
| 2009 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns | 2013 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns |
| 2010 : area.rows; | 2014 : area.rows; |
| 2011 if (majorAxisPositions.isIndefinite()) | 2015 if (majorAxisPositions.isIndefinite()) |
| 2012 autoMajorAxisAutoGridItems.append(child); | 2016 autoMajorAxisAutoGridItems.append(child); |
| 2013 else | 2017 else |
| 2014 specifiedMajorAxisAutoGridItems.append(child); | 2018 specifiedMajorAxisAutoGridItems.append(child); |
| 2015 continue; | 2019 continue; |
| 2016 } | 2020 } |
| 2017 insertItemIntoGrid(*child, area); | 2021 m_grid.insert(*child, area); |
| 2018 } | 2022 } |
| 2019 | 2023 |
| 2020 #if ENABLE(ASSERT) | 2024 #if ENABLE(ASSERT) |
| 2021 if (!m_gridItemArea.isEmpty()) { | 2025 if (!m_gridItemArea.isEmpty()) { |
| 2022 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( | 2026 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( |
| 2023 *style(), m_autoRepeatRows)); | 2027 *style(), m_autoRepeatRows)); |
| 2024 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( | 2028 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( |
| 2025 *style(), m_autoRepeatColumns)); | 2029 *style(), m_autoRepeatColumns)); |
| 2026 } | 2030 } |
| 2027 #endif | 2031 #endif |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 columnPositions.untranslatedEndLine()); | 2097 columnPositions.untranslatedEndLine()); |
| 2094 } else { | 2098 } else { |
| 2095 // Grow the grid for items with a definite column span, getting the | 2099 // Grow the grid for items with a definite column span, getting the |
| 2096 // largest such span. | 2100 // largest such span. |
| 2097 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2101 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2098 *style(), *child, ForColumns); | 2102 *style(), *child, ForColumns); |
| 2099 maximumColumnIndex = std::max(maximumColumnIndex, spanSize); | 2103 maximumColumnIndex = std::max(maximumColumnIndex, spanSize); |
| 2100 } | 2104 } |
| 2101 } | 2105 } |
| 2102 | 2106 |
| 2103 m_grid.grow(maximumRowIndex + abs(m_smallestRowStart)); | 2107 m_grid.ensureGridSize(maximumRowIndex + abs(m_smallestRowStart), |
| 2104 for (auto& column : m_grid) | 2108 maximumColumnIndex + abs(m_smallestColumnStart)); |
| 2105 column.grow(maximumColumnIndex + abs(m_smallestColumnStart)); | |
| 2106 } | 2109 } |
| 2107 | 2110 |
| 2108 std::unique_ptr<GridArea> | 2111 std::unique_ptr<GridArea> |
| 2109 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2112 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2110 const LayoutBox& gridItem, | 2113 const LayoutBox& gridItem, |
| 2111 GridTrackSizingDirection specifiedDirection, | 2114 GridTrackSizingDirection specifiedDirection, |
| 2112 const GridSpan& specifiedPositions) const { | 2115 const GridSpan& specifiedPositions) const { |
| 2113 GridTrackSizingDirection crossDirection = | 2116 GridTrackSizingDirection crossDirection = |
| 2114 specifiedDirection == ForColumns ? ForRows : ForColumns; | 2117 specifiedDirection == ForColumns ? ForRows : ForColumns; |
| 2115 const size_t endOfCrossDirection = | 2118 const size_t endOfCrossDirection = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2154 isGridAutoFlowDense | 2157 isGridAutoFlowDense |
| 2155 ? 0 | 2158 ? 0 |
| 2156 : minorAxisCursors.get(majorAxisInitialPosition)); | 2159 : minorAxisCursors.get(majorAxisInitialPosition)); |
| 2157 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( | 2160 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( |
| 2158 majorAxisPositions.integerSpan(), minorAxisSpanSize); | 2161 majorAxisPositions.integerSpan(), minorAxisSpanSize); |
| 2159 if (!emptyGridArea) | 2162 if (!emptyGridArea) |
| 2160 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2163 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2161 *autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); | 2164 *autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); |
| 2162 | 2165 |
| 2163 m_gridItemArea.set(autoGridItem, *emptyGridArea); | 2166 m_gridItemArea.set(autoGridItem, *emptyGridArea); |
| 2164 insertItemIntoGrid(*autoGridItem, *emptyGridArea); | 2167 m_grid.insert(*autoGridItem, *emptyGridArea); |
| 2165 | 2168 |
| 2166 if (!isGridAutoFlowDense) | 2169 if (!isGridAutoFlowDense) |
| 2167 minorAxisCursors.set(majorAxisInitialPosition, | 2170 minorAxisCursors.set(majorAxisInitialPosition, |
| 2168 isForColumns ? emptyGridArea->rows.startLine() | 2171 isForColumns ? emptyGridArea->rows.startLine() |
| 2169 : emptyGridArea->columns.startLine()); | 2172 : emptyGridArea->columns.startLine()); |
| 2170 } | 2173 } |
| 2171 } | 2174 } |
| 2172 | 2175 |
| 2173 void LayoutGrid::placeAutoMajorAxisItemsOnGrid( | 2176 void LayoutGrid::placeAutoMajorAxisItemsOnGrid( |
| 2174 const Vector<LayoutBox*>& autoGridItems) { | 2177 const Vector<LayoutBox*>& autoGridItems) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 minorAxisAutoPlacementCursor = 0; | 2265 minorAxisAutoPlacementCursor = 0; |
| 2263 } | 2266 } |
| 2264 | 2267 |
| 2265 if (!emptyGridArea) | 2268 if (!emptyGridArea) |
| 2266 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2269 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2267 gridItem, autoPlacementMinorAxisDirection(), | 2270 gridItem, autoPlacementMinorAxisDirection(), |
| 2268 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); | 2271 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); |
| 2269 } | 2272 } |
| 2270 | 2273 |
| 2271 m_gridItemArea.set(&gridItem, *emptyGridArea); | 2274 m_gridItemArea.set(&gridItem, *emptyGridArea); |
| 2272 insertItemIntoGrid(gridItem, *emptyGridArea); | 2275 m_grid.insert(gridItem, *emptyGridArea); |
| 2273 // Move auto-placement cursor to the new position. | 2276 // Move auto-placement cursor to the new position. |
| 2274 autoPlacementCursor.first = emptyGridArea->rows.startLine(); | 2277 autoPlacementCursor.first = emptyGridArea->rows.startLine(); |
| 2275 autoPlacementCursor.second = emptyGridArea->columns.startLine(); | 2278 autoPlacementCursor.second = emptyGridArea->columns.startLine(); |
| 2276 } | 2279 } |
| 2277 | 2280 |
| 2278 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { | 2281 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { |
| 2279 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 2282 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 2280 } | 2283 } |
| 2281 | 2284 |
| 2282 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { | 2285 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { |
| 2283 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 2286 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| 2284 } | 2287 } |
| 2285 | 2288 |
| 2286 void LayoutGrid::dirtyGrid() { | 2289 void LayoutGrid::dirtyGrid() { |
| 2287 if (m_gridIsDirty) | 2290 if (m_gridIsDirty) |
| 2288 return; | 2291 return; |
| 2289 | 2292 |
| 2290 m_grid.resize(0); | 2293 m_grid.clear(); |
| 2291 m_gridItemArea.clear(); | 2294 m_gridItemArea.clear(); |
| 2292 m_gridItemsOverflowingGridArea.resize(0); | 2295 m_gridItemsOverflowingGridArea.resize(0); |
| 2293 m_gridItemsIndexesMap.clear(); | 2296 m_gridItemsIndexesMap.clear(); |
| 2294 m_autoRepeatColumns = 0; | 2297 m_autoRepeatColumns = 0; |
| 2295 m_autoRepeatRows = 0; | 2298 m_autoRepeatRows = 0; |
| 2296 m_gridIsDirty = true; | 2299 m_gridIsDirty = true; |
| 2297 m_autoRepeatEmptyColumns = nullptr; | 2300 m_autoRepeatEmptyColumns = nullptr; |
| 2298 m_autoRepeatEmptyRows = nullptr; | 2301 m_autoRepeatEmptyRows = nullptr; |
| 2299 } | 2302 } |
| 2300 | 2303 |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 | 2996 |
| 2994 return baseline + beforeMarginInLineDirection(direction); | 2997 return baseline + beforeMarginInLineDirection(direction); |
| 2995 } | 2998 } |
| 2996 | 2999 |
| 2997 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const { | 3000 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const { |
| 2998 return alignSelfForChild(*child).position() == ItemPositionBaseline && | 3001 return alignSelfForChild(*child).position() == ItemPositionBaseline && |
| 2999 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); | 3002 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); |
| 3000 } | 3003 } |
| 3001 | 3004 |
| 3002 int LayoutGrid::firstLineBoxBaseline() const { | 3005 int LayoutGrid::firstLineBoxBaseline() const { |
| 3003 if (isWritingModeRoot() || m_grid.isEmpty()) | 3006 if (isWritingModeRoot() || m_gridItemArea.isEmpty()) |
| 3004 return -1; | 3007 return -1; |
| 3005 const LayoutBox* baselineChild = nullptr; | 3008 const LayoutBox* baselineChild = nullptr; |
| 3006 const LayoutBox* firstChild = nullptr; | 3009 const LayoutBox* firstChild = nullptr; |
| 3007 bool isBaselineAligned = false; | 3010 bool isBaselineAligned = false; |
| 3008 // Finding the first grid item in grid order. | 3011 // Finding the first grid item in grid order. |
| 3009 for (size_t column = 0; !isBaselineAligned && column < m_grid[0].size(); | 3012 for (size_t column = 0; !isBaselineAligned && column < m_grid.numColumns(); |
| 3010 column++) { | 3013 column++) { |
| 3011 for (size_t index = 0; index < m_grid[0][column].size(); index++) { | 3014 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { |
| 3012 const LayoutBox* child = m_grid[0][column][index]; | 3015 const LayoutBox* child = m_grid.cell(0, column)[index]; |
| 3013 DCHECK(!child->isOutOfFlowPositioned()); | 3016 DCHECK(!child->isOutOfFlowPositioned()); |
| 3014 // If an item participates in baseline alignmen, we select such item. | 3017 // If an item participates in baseline alignmen, we select such item. |
| 3015 if (isInlineBaselineAlignedChild(child)) { | 3018 if (isInlineBaselineAlignedChild(child)) { |
| 3016 // TODO (lajava): self-baseline and content-baseline alignment | 3019 // TODO (lajava): self-baseline and content-baseline alignment |
| 3017 // still not implemented. | 3020 // still not implemented. |
| 3018 baselineChild = child; | 3021 baselineChild = child; |
| 3019 isBaselineAligned = true; | 3022 isBaselineAligned = true; |
| 3020 break; | 3023 break; |
| 3021 } | 3024 } |
| 3022 if (!baselineChild) { | 3025 if (!baselineChild) { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3495 } | 3498 } |
| 3496 | 3499 |
| 3497 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { | 3500 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { |
| 3498 // Due to limitations in our internal representation, we cannot know the | 3501 // Due to limitations in our internal representation, we cannot know the |
| 3499 // number of columns from m_grid *if* there is no row (because m_grid would be | 3502 // number of columns from m_grid *if* there is no row (because m_grid would be |
| 3500 // empty). That's why in that case we need to get it from the style. Note that | 3503 // empty). That's why in that case we need to get it from the style. Note that |
| 3501 // we know for sure that there are't any implicit tracks, because not having | 3504 // we know for sure that there are't any implicit tracks, because not having |
| 3502 // rows implies that there are no "normal" children (out-of-flow children are | 3505 // rows implies that there are no "normal" children (out-of-flow children are |
| 3503 // not stored in m_grid). | 3506 // not stored in m_grid). |
| 3504 if (direction == ForRows) | 3507 if (direction == ForRows) |
| 3505 return m_grid.size(); | 3508 return m_grid.numRows(); |
| 3506 | 3509 |
| 3507 return m_grid.size() ? m_grid[0].size() | 3510 return m_grid.numRows() ? m_grid.numColumns() |
| 3508 : GridPositionsResolver::explicitGridColumnCount( | 3511 : GridPositionsResolver::explicitGridColumnCount( |
| 3509 styleRef(), m_autoRepeatColumns); | 3512 styleRef(), m_autoRepeatColumns); |
| 3510 } | 3513 } |
| 3511 | 3514 |
| 3512 } // namespace blink | 3515 } // namespace blink |
| OLD | NEW |