| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 for (size_t row = oldRowSize; row < numRows(); ++row) | 50 for (size_t row = oldRowSize; row < numRows(); ++row) |
| 51 m_grid[row].grow(numColumns()); | 51 m_grid[row].grow(numColumns()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (maximumColumnSize > numColumns()) { | 54 if (maximumColumnSize > numColumns()) { |
| 55 for (size_t row = 0; row < numRows(); ++row) | 55 for (size_t row = 0; row < numRows(); ++row) |
| 56 m_grid[row].grow(maximumColumnSize); | 56 m_grid[row].grow(maximumColumnSize); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void LayoutGrid::Grid::insert(LayoutBox& child, const GridArea& area) { | 60 void LayoutGrid::Grid::insert(LayoutBox& child, |
| 61 const GridArea& area, |
| 62 bool isOrthogonalChild) { |
| 61 DCHECK(area.rows.isTranslatedDefinite() && | 63 DCHECK(area.rows.isTranslatedDefinite() && |
| 62 area.columns.isTranslatedDefinite()); | 64 area.columns.isTranslatedDefinite()); |
| 63 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 65 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
| 64 | 66 |
| 65 for (const auto& row : area.rows) { | 67 for (const auto& row : area.rows) { |
| 66 for (const auto& column : area.columns) | 68 for (const auto& column : area.columns) |
| 67 m_grid[row][column].append(&child); | 69 m_grid[row][column].append(&child); |
| 68 } | 70 } |
| 71 |
| 72 setGridItemArea(child, area); |
| 73 |
| 74 m_hasAnyOrthogonalChildren = m_hasAnyOrthogonalChildren || isOrthogonalChild; |
| 69 } | 75 } |
| 70 | 76 |
| 77 void LayoutGrid::Grid::setSmallestTracksStart(int rowStart, int columnStart) { |
| 78 m_smallestRowStart = rowStart; |
| 79 m_smallestColumnStart = columnStart; |
| 80 } |
| 81 |
| 82 int LayoutGrid::Grid::smallestTrackStart( |
| 83 GridTrackSizingDirection direction) const { |
| 84 return direction == ForRows ? m_smallestRowStart : m_smallestColumnStart; |
| 85 } |
| 86 |
| 87 GridArea LayoutGrid::Grid::gridItemArea(const LayoutBox& item) const { |
| 88 DCHECK(m_gridItemArea.contains(&item)); |
| 89 return m_gridItemArea.get(&item); |
| 90 } |
| 91 |
| 92 void LayoutGrid::Grid::setGridItemArea(const LayoutBox& item, GridArea area) { |
| 93 m_gridItemArea.set(&item, area); |
| 94 } |
| 95 |
| 96 size_t LayoutGrid::Grid::gridItemPaintOrder(const LayoutBox& item) const { |
| 97 return m_gridItemsIndexesMap.get(&item); |
| 98 } |
| 99 |
| 100 void LayoutGrid::Grid::setGridItemPaintOrder(const LayoutBox& item, |
| 101 size_t order) { |
| 102 m_gridItemsIndexesMap.set(&item, order); |
| 103 } |
| 104 |
| 105 #if ENABLE(ASSERT) |
| 106 bool LayoutGrid::Grid::hasAnyGridItemPaintOrder() const { |
| 107 return !m_gridItemsIndexesMap.isEmpty(); |
| 108 } |
| 109 #endif |
| 110 |
| 71 void LayoutGrid::Grid::clear() { | 111 void LayoutGrid::Grid::clear() { |
| 72 m_grid.resize(0); | 112 m_grid.resize(0); |
| 113 m_gridItemArea.clear(); |
| 114 m_gridItemsIndexesMap.clear(); |
| 115 m_hasAnyOrthogonalChildren = false; |
| 116 m_smallestRowStart = 0; |
| 117 m_smallestColumnStart = 0; |
| 73 } | 118 } |
| 74 | 119 |
| 75 class GridTrack { | 120 class GridTrack { |
| 76 public: | 121 public: |
| 77 GridTrack() : m_infinitelyGrowable(false) {} | 122 GridTrack() : m_infinitelyGrowable(false) {} |
| 78 | 123 |
| 79 LayoutUnit baseSize() const { | 124 LayoutUnit baseSize() const { |
| 80 DCHECK(isGrowthLimitBiggerThanBaseSize()); | 125 DCHECK(isGrowthLimitBiggerThanBaseSize()); |
| 81 return m_baseSize; | 126 return m_baseSize; |
| 82 } | 127 } |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // In orthogonal flow cases column track's size is determined by using the | 524 // In orthogonal flow cases column track's size is determined by using the |
| 480 // computed row track's size, which it was estimated during the first cycle of | 525 // computed row track's size, which it was estimated during the first cycle of |
| 481 // the sizing algorithm. | 526 // the sizing algorithm. |
| 482 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns | 527 // Hence we need to repeat computeUsedBreadthOfGridTracks for both, columns |
| 483 // and rows, to determine the final values. | 528 // and rows, to determine the final values. |
| 484 // TODO (lajava): orthogonal flows is just one of the cases which may require | 529 // TODO (lajava): orthogonal flows is just one of the cases which may require |
| 485 // a new cycle of the sizing algorithm; there may be more. In addition, not | 530 // a new cycle of the sizing algorithm; there may be more. In addition, not |
| 486 // all the cases with orthogonal flows require this extra cycle; we need a | 531 // all the cases with orthogonal flows require this extra cycle; we need a |
| 487 // more specific condition to detect whether child's min-content contribution | 532 // more specific condition to detect whether child's min-content contribution |
| 488 // has changed or not. | 533 // has changed or not. |
| 489 if (m_hasAnyOrthogonalChildren) { | 534 if (m_grid.hasAnyOrthogonalChildren()) { |
| 490 computeTrackSizesForDefiniteSize(ForColumns, sizingData, | 535 computeTrackSizesForDefiniteSize(ForColumns, sizingData, |
| 491 availableSpaceForColumns); | 536 availableSpaceForColumns); |
| 492 computeTrackSizesForDefiniteSize(ForRows, sizingData, | 537 computeTrackSizesForDefiniteSize(ForRows, sizingData, |
| 493 availableSpaceForRows); | 538 availableSpaceForRows); |
| 494 } | 539 } |
| 495 } | 540 } |
| 496 | 541 |
| 497 void LayoutGrid::layoutBlock(bool relayoutChildren) { | 542 void LayoutGrid::layoutBlock(bool relayoutChildren) { |
| 498 ASSERT(needsLayout()); | 543 ASSERT(needsLayout()); |
| 499 | 544 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), | 920 tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), |
| 876 direction, initialFreeSpace); | 921 direction, initialFreeSpace); |
| 877 } else { | 922 } else { |
| 878 for (const auto& trackIndex : flexibleSizedTracksIndex) | 923 for (const auto& trackIndex : flexibleSizedTracksIndex) |
| 879 flexFraction = std::max( | 924 flexFraction = std::max( |
| 880 flexFraction, | 925 flexFraction, |
| 881 normalizedFlexFraction( | 926 normalizedFlexFraction( |
| 882 tracks[trackIndex], | 927 tracks[trackIndex], |
| 883 gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); | 928 gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); |
| 884 | 929 |
| 885 if (!m_gridItemArea.isEmpty()) { | 930 if (m_grid.hasInFlowGridItems()) { |
| 886 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 931 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
| 887 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); | 932 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); |
| 888 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 933 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 889 const GridSpan span = cachedGridSpan(*gridItem, direction); | 934 const GridSpan span = cachedGridSpan(*gridItem, direction); |
| 890 | 935 |
| 891 // Do not include already processed items. | 936 // Do not include already processed items. |
| 892 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) | 937 if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1]) |
| 893 continue; | 938 continue; |
| 894 | 939 |
| 895 flexFraction = std::max( | 940 flexFraction = std::max( |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 : styleRef().gridAutoRepeatRowsInsertionPoint(); | 1171 : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| 1127 size_t autoRepeatTracksCount = autoRepeatCountForDirection(direction); | 1172 size_t autoRepeatTracksCount = autoRepeatCountForDirection(direction); |
| 1128 | 1173 |
| 1129 // We should not use GridPositionsResolver::explicitGridXXXCount() for this | 1174 // We should not use GridPositionsResolver::explicitGridXXXCount() for this |
| 1130 // because the explicit grid might be larger than the number of tracks in | 1175 // because the explicit grid might be larger than the number of tracks in |
| 1131 // grid-template-rows|columns (if grid-template-areas is specified for | 1176 // grid-template-rows|columns (if grid-template-areas is specified for |
| 1132 // example). | 1177 // example). |
| 1133 size_t explicitTracksCount = trackStyles.size() + autoRepeatTracksCount; | 1178 size_t explicitTracksCount = trackStyles.size() + autoRepeatTracksCount; |
| 1134 | 1179 |
| 1135 int untranslatedIndexAsInt = | 1180 int untranslatedIndexAsInt = |
| 1136 translatedIndex + | 1181 translatedIndex + m_grid.smallestTrackStart(direction); |
| 1137 (isRowAxis ? m_smallestColumnStart : m_smallestRowStart); | |
| 1138 size_t autoTrackStylesSize = autoTrackStyles.size(); | 1182 size_t autoTrackStylesSize = autoTrackStyles.size(); |
| 1139 if (untranslatedIndexAsInt < 0) { | 1183 if (untranslatedIndexAsInt < 0) { |
| 1140 int index = untranslatedIndexAsInt % static_cast<int>(autoTrackStylesSize); | 1184 int index = untranslatedIndexAsInt % static_cast<int>(autoTrackStylesSize); |
| 1141 // We need to traspose the index because the first negative implicit line | 1185 // We need to traspose the index because the first negative implicit line |
| 1142 // will get the last defined auto track and so on. | 1186 // will get the last defined auto track and so on. |
| 1143 index += index ? autoTrackStylesSize : 0; | 1187 index += index ? autoTrackStylesSize : 0; |
| 1144 return autoTrackStyles[index]; | 1188 return autoTrackStyles[index]; |
| 1145 } | 1189 } |
| 1146 | 1190 |
| 1147 size_t untranslatedIndex = static_cast<size_t>(untranslatedIndexAsInt); | 1191 size_t untranslatedIndex = static_cast<size_t>(untranslatedIndexAsInt); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 return true; | 1445 return true; |
| 1402 } | 1446 } |
| 1403 | 1447 |
| 1404 return false; | 1448 return false; |
| 1405 } | 1449 } |
| 1406 | 1450 |
| 1407 void LayoutGrid::resolveContentBasedTrackSizingFunctions( | 1451 void LayoutGrid::resolveContentBasedTrackSizingFunctions( |
| 1408 GridTrackSizingDirection direction, | 1452 GridTrackSizingDirection direction, |
| 1409 GridSizingData& sizingData) const { | 1453 GridSizingData& sizingData) const { |
| 1410 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 1454 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
| 1411 if (!m_gridItemArea.isEmpty()) { | 1455 if (m_grid.hasInFlowGridItems()) { |
| 1412 HashSet<LayoutBox*> itemsSet; | 1456 HashSet<LayoutBox*> itemsSet; |
| 1413 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1457 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 1414 GridIterator iterator(m_grid, direction, trackIndex); | 1458 GridIterator iterator(m_grid, direction, trackIndex); |
| 1415 GridTrack& track = (direction == ForColumns) | 1459 GridTrack& track = (direction == ForColumns) |
| 1416 ? sizingData.columnTracks[trackIndex] | 1460 ? sizingData.columnTracks[trackIndex] |
| 1417 : sizingData.rowTracks[trackIndex]; | 1461 : sizingData.rowTracks[trackIndex]; |
| 1418 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 1462 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 1419 if (itemsSet.add(gridItem).isNewEntry) { | 1463 if (itemsSet.add(gridItem).isNewEntry) { |
| 1420 const GridSpan& span = cachedGridSpan(*gridItem, direction); | 1464 const GridSpan& span = cachedGridSpan(*gridItem, direction); |
| 1421 if (span.integerSpan() == 1) { | 1465 if (span.integerSpan() == 1) { |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 bool isRowAxis = direction == ForColumns; | 1980 bool isRowAxis = direction == ForColumns; |
| 1937 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || | 1981 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || |
| 1938 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) | 1982 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) |
| 1939 return nullptr; | 1983 return nullptr; |
| 1940 | 1984 |
| 1941 std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes; | 1985 std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes; |
| 1942 size_t insertionPoint = isRowAxis | 1986 size_t insertionPoint = isRowAxis |
| 1943 ? styleRef().gridAutoRepeatColumnsInsertionPoint() | 1987 ? styleRef().gridAutoRepeatColumnsInsertionPoint() |
| 1944 : styleRef().gridAutoRepeatRowsInsertionPoint(); | 1988 : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| 1945 size_t firstAutoRepeatTrack = | 1989 size_t firstAutoRepeatTrack = |
| 1946 insertionPoint + | 1990 insertionPoint + std::abs(m_grid.smallestTrackStart(direction)); |
| 1947 std::abs(isRowAxis ? m_smallestColumnStart : m_smallestRowStart); | |
| 1948 size_t lastAutoRepeatTrack = | 1991 size_t lastAutoRepeatTrack = |
| 1949 firstAutoRepeatTrack + autoRepeatCountForDirection(direction); | 1992 firstAutoRepeatTrack + autoRepeatCountForDirection(direction); |
| 1950 | 1993 |
| 1951 if (m_gridItemArea.isEmpty()) { | 1994 if (!m_grid.hasInFlowGridItems()) { |
| 1952 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); | 1995 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 1953 for (size_t trackIndex = firstAutoRepeatTrack; | 1996 for (size_t trackIndex = firstAutoRepeatTrack; |
| 1954 trackIndex < lastAutoRepeatTrack; ++trackIndex) | 1997 trackIndex < lastAutoRepeatTrack; ++trackIndex) |
| 1955 emptyTrackIndexes->add(trackIndex); | 1998 emptyTrackIndexes->add(trackIndex); |
| 1956 } else { | 1999 } else { |
| 1957 for (size_t trackIndex = firstAutoRepeatTrack; | 2000 for (size_t trackIndex = firstAutoRepeatTrack; |
| 1958 trackIndex < lastAutoRepeatTrack; ++trackIndex) { | 2001 trackIndex < lastAutoRepeatTrack; ++trackIndex) { |
| 1959 GridIterator iterator(m_grid, direction, trackIndex); | 2002 GridIterator iterator(m_grid, direction, trackIndex); |
| 1960 if (!iterator.nextGridItem()) { | 2003 if (!iterator.nextGridItem()) { |
| 1961 if (!emptyTrackIndexes) | 2004 if (!emptyTrackIndexes) |
| 1962 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); | 2005 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 1963 emptyTrackIndexes->add(trackIndex); | 2006 emptyTrackIndexes->add(trackIndex); |
| 1964 } | 2007 } |
| 1965 } | 2008 } |
| 1966 } | 2009 } |
| 1967 return emptyTrackIndexes; | 2010 return emptyTrackIndexes; |
| 1968 } | 2011 } |
| 1969 | 2012 |
| 1970 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) { | 2013 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) { |
| 1971 if (!m_gridIsDirty) | 2014 if (!m_gridIsDirty) |
| 1972 return; | 2015 return; |
| 1973 | 2016 |
| 1974 DCHECK(m_gridItemArea.isEmpty()); | 2017 DCHECK(!m_grid.hasInFlowGridItems()); |
| 1975 | 2018 |
| 1976 if (sizingOperation == IntrinsicSizeComputation) { | 2019 if (sizingOperation == IntrinsicSizeComputation) { |
| 1977 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); | 2020 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); |
| 1978 } else { | 2021 } else { |
| 1979 m_autoRepeatColumns = | 2022 m_autoRepeatColumns = |
| 1980 computeAutoRepeatTracksCount(ForColumns, sizingOperation); | 2023 computeAutoRepeatTracksCount(ForColumns, sizingOperation); |
| 1981 } | 2024 } |
| 1982 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation); | 2025 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation); |
| 1983 | 2026 |
| 1984 populateExplicitGridAndOrderIterator(); | 2027 populateExplicitGridAndOrderIterator(); |
| 1985 | 2028 |
| 1986 // We clear the dirty bit here as the grid sizes have been updated. | 2029 // We clear the dirty bit here as the grid sizes have been updated. |
| 1987 m_gridIsDirty = false; | 2030 m_gridIsDirty = false; |
| 1988 | 2031 |
| 1989 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 2032 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
| 1990 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 2033 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
| 1991 DCHECK(m_gridItemsIndexesMap.isEmpty()); | 2034 #if ENABLE(ASSERT) |
| 2035 DCHECK(!m_grid.hasAnyGridItemPaintOrder()); |
| 2036 #endif |
| 2037 DCHECK(!m_grid.hasAnyOrthogonalChildren()); |
| 1992 size_t childIndex = 0; | 2038 size_t childIndex = 0; |
| 1993 m_hasAnyOrthogonalChildren = false; | |
| 1994 for (LayoutBox* child = m_orderIterator.first(); child; | 2039 for (LayoutBox* child = m_orderIterator.first(); child; |
| 1995 child = m_orderIterator.next()) { | 2040 child = m_orderIterator.next()) { |
| 1996 if (child->isOutOfFlowPositioned()) | 2041 if (child->isOutOfFlowPositioned()) |
| 1997 continue; | 2042 continue; |
| 1998 | 2043 |
| 1999 m_gridItemsIndexesMap.set(child, childIndex++); | 2044 m_grid.setGridItemPaintOrder(*child, childIndex++); |
| 2000 | 2045 |
| 2001 m_hasAnyOrthogonalChildren = | 2046 GridArea area = m_grid.gridItemArea(*child); |
| 2002 m_hasAnyOrthogonalChildren || isOrthogonalChild(*child); | |
| 2003 | |
| 2004 GridArea area = cachedGridArea(*child); | |
| 2005 if (!area.rows.isIndefinite()) | 2047 if (!area.rows.isIndefinite()) |
| 2006 area.rows.translate(abs(m_smallestRowStart)); | 2048 area.rows.translate(abs(m_grid.smallestTrackStart(ForRows))); |
| 2007 if (!area.columns.isIndefinite()) | 2049 if (!area.columns.isIndefinite()) |
| 2008 area.columns.translate(abs(m_smallestColumnStart)); | 2050 area.columns.translate(abs(m_grid.smallestTrackStart(ForColumns))); |
| 2009 m_gridItemArea.set(child, area); | |
| 2010 | 2051 |
| 2011 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 2052 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 2053 m_grid.setGridItemArea(*child, area); |
| 2012 GridSpan majorAxisPositions = | 2054 GridSpan majorAxisPositions = |
| 2013 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns | 2055 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns |
| 2014 : area.rows; | 2056 : area.rows; |
| 2015 if (majorAxisPositions.isIndefinite()) | 2057 if (majorAxisPositions.isIndefinite()) |
| 2016 autoMajorAxisAutoGridItems.append(child); | 2058 autoMajorAxisAutoGridItems.append(child); |
| 2017 else | 2059 else |
| 2018 specifiedMajorAxisAutoGridItems.append(child); | 2060 specifiedMajorAxisAutoGridItems.append(child); |
| 2019 continue; | 2061 continue; |
| 2020 } | 2062 } |
| 2021 m_grid.insert(*child, area); | 2063 m_grid.insert(*child, area, isOrthogonalChild(*child)); |
| 2022 } | 2064 } |
| 2023 | 2065 |
| 2024 #if ENABLE(ASSERT) | 2066 #if ENABLE(ASSERT) |
| 2025 if (!m_gridItemArea.isEmpty()) { | 2067 if (m_grid.hasInFlowGridItems()) { |
| 2026 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( | 2068 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( |
| 2027 *style(), m_autoRepeatRows)); | 2069 *style(), m_autoRepeatRows)); |
| 2028 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( | 2070 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( |
| 2029 *style(), m_autoRepeatColumns)); | 2071 *style(), m_autoRepeatColumns)); |
| 2030 } | 2072 } |
| 2031 #endif | 2073 #endif |
| 2032 | 2074 |
| 2033 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 2075 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 2034 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 2076 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 2035 | 2077 |
| 2036 m_grid.shrinkToFit(); | 2078 m_grid.shrinkToFit(); |
| 2037 | 2079 |
| 2038 // Compute collapsable tracks for auto-fit. | 2080 // Compute collapsable tracks for auto-fit. |
| 2039 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); | 2081 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); |
| 2040 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); | 2082 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); |
| 2041 | 2083 |
| 2042 #if ENABLE(ASSERT) | 2084 #if ENABLE(ASSERT) |
| 2043 for (LayoutBox* child = m_orderIterator.first(); child; | 2085 for (LayoutBox* child = m_orderIterator.first(); child; |
| 2044 child = m_orderIterator.next()) { | 2086 child = m_orderIterator.next()) { |
| 2045 if (child->isOutOfFlowPositioned()) | 2087 if (child->isOutOfFlowPositioned()) |
| 2046 continue; | 2088 continue; |
| 2047 | 2089 |
| 2048 GridArea area = cachedGridArea(*child); | 2090 GridArea area = m_grid.gridItemArea(*child); |
| 2049 ASSERT(area.rows.isTranslatedDefinite() && | 2091 ASSERT(area.rows.isTranslatedDefinite() && |
| 2050 area.columns.isTranslatedDefinite()); | 2092 area.columns.isTranslatedDefinite()); |
| 2051 } | 2093 } |
| 2052 #endif | 2094 #endif |
| 2053 } | 2095 } |
| 2054 | 2096 |
| 2055 void LayoutGrid::populateExplicitGridAndOrderIterator() { | 2097 void LayoutGrid::populateExplicitGridAndOrderIterator() { |
| 2056 OrderIteratorPopulator populator(m_orderIterator); | 2098 OrderIteratorPopulator populator(m_orderIterator); |
| 2057 | 2099 int smallestRowStart = 0; |
| 2058 m_smallestRowStart = m_smallestColumnStart = 0; | 2100 int smallestColumnStart = 0; |
| 2059 | 2101 |
| 2060 size_t maximumRowIndex = | 2102 size_t maximumRowIndex = |
| 2061 GridPositionsResolver::explicitGridRowCount(*style(), m_autoRepeatRows); | 2103 GridPositionsResolver::explicitGridRowCount(*style(), m_autoRepeatRows); |
| 2062 size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount( | 2104 size_t maximumColumnIndex = GridPositionsResolver::explicitGridColumnCount( |
| 2063 *style(), m_autoRepeatColumns); | 2105 *style(), m_autoRepeatColumns); |
| 2064 | 2106 |
| 2065 for (LayoutBox* child = firstInFlowChildBox(); child; | 2107 for (LayoutBox* child = firstInFlowChildBox(); child; |
| 2066 child = child->nextInFlowSiblingBox()) { | 2108 child = child->nextInFlowSiblingBox()) { |
| 2067 populator.collectChild(child); | 2109 populator.collectChild(child); |
| 2068 | 2110 |
| 2069 // This function bypasses the cache (cachedGridArea()) as it is used to | 2111 // This function bypasses the cache (gridItemArea()) as it is used to |
| 2070 // build it. | 2112 // build it. |
| 2071 GridSpan rowPositions = | 2113 GridSpan rowPositions = |
| 2072 GridPositionsResolver::resolveGridPositionsFromStyle( | 2114 GridPositionsResolver::resolveGridPositionsFromStyle( |
| 2073 *style(), *child, ForRows, m_autoRepeatRows); | 2115 *style(), *child, ForRows, m_autoRepeatRows); |
| 2074 GridSpan columnPositions = | 2116 GridSpan columnPositions = |
| 2075 GridPositionsResolver::resolveGridPositionsFromStyle( | 2117 GridPositionsResolver::resolveGridPositionsFromStyle( |
| 2076 *style(), *child, ForColumns, m_autoRepeatColumns); | 2118 *style(), *child, ForColumns, m_autoRepeatColumns); |
| 2077 m_gridItemArea.set(child, GridArea(rowPositions, columnPositions)); | 2119 m_grid.setGridItemArea(*child, GridArea(rowPositions, columnPositions)); |
| 2078 | 2120 |
| 2079 // |positions| is 0 if we need to run the auto-placement algorithm. | 2121 // |positions| is 0 if we need to run the auto-placement algorithm. |
| 2080 if (!rowPositions.isIndefinite()) { | 2122 if (!rowPositions.isIndefinite()) { |
| 2081 m_smallestRowStart = | 2123 smallestRowStart = |
| 2082 std::min(m_smallestRowStart, rowPositions.untranslatedStartLine()); | 2124 std::min(smallestRowStart, rowPositions.untranslatedStartLine()); |
| 2083 maximumRowIndex = | 2125 maximumRowIndex = |
| 2084 std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine()); | 2126 std::max<int>(maximumRowIndex, rowPositions.untranslatedEndLine()); |
| 2085 } else { | 2127 } else { |
| 2086 // Grow the grid for items with a definite row span, getting the largest | 2128 // Grow the grid for items with a definite row span, getting the largest |
| 2087 // such span. | 2129 // such span. |
| 2088 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2130 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2089 *style(), *child, ForRows); | 2131 *style(), *child, ForRows); |
| 2090 maximumRowIndex = std::max(maximumRowIndex, spanSize); | 2132 maximumRowIndex = std::max(maximumRowIndex, spanSize); |
| 2091 } | 2133 } |
| 2092 | 2134 |
| 2093 if (!columnPositions.isIndefinite()) { | 2135 if (!columnPositions.isIndefinite()) { |
| 2094 m_smallestColumnStart = std::min(m_smallestColumnStart, | 2136 smallestColumnStart = std::min(smallestColumnStart, |
| 2095 columnPositions.untranslatedStartLine()); | 2137 columnPositions.untranslatedStartLine()); |
| 2096 maximumColumnIndex = std::max<int>(maximumColumnIndex, | 2138 maximumColumnIndex = std::max<int>(maximumColumnIndex, |
| 2097 columnPositions.untranslatedEndLine()); | 2139 columnPositions.untranslatedEndLine()); |
| 2098 } else { | 2140 } else { |
| 2099 // Grow the grid for items with a definite column span, getting the | 2141 // Grow the grid for items with a definite column span, getting the |
| 2100 // largest such span. | 2142 // largest such span. |
| 2101 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2143 size_t spanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2102 *style(), *child, ForColumns); | 2144 *style(), *child, ForColumns); |
| 2103 maximumColumnIndex = std::max(maximumColumnIndex, spanSize); | 2145 maximumColumnIndex = std::max(maximumColumnIndex, spanSize); |
| 2104 } | 2146 } |
| 2105 } | 2147 } |
| 2106 | 2148 |
| 2107 m_grid.ensureGridSize(maximumRowIndex + abs(m_smallestRowStart), | 2149 m_grid.setSmallestTracksStart(smallestRowStart, smallestColumnStart); |
| 2108 maximumColumnIndex + abs(m_smallestColumnStart)); | 2150 m_grid.ensureGridSize(maximumRowIndex + abs(smallestRowStart), |
| 2151 maximumColumnIndex + abs(smallestColumnStart)); |
| 2109 } | 2152 } |
| 2110 | 2153 |
| 2111 std::unique_ptr<GridArea> | 2154 std::unique_ptr<GridArea> |
| 2112 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2155 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2113 const LayoutBox& gridItem, | 2156 const LayoutBox& gridItem, |
| 2114 GridTrackSizingDirection specifiedDirection, | 2157 GridTrackSizingDirection specifiedDirection, |
| 2115 const GridSpan& specifiedPositions) const { | 2158 const GridSpan& specifiedPositions) const { |
| 2116 GridTrackSizingDirection crossDirection = | 2159 GridTrackSizingDirection crossDirection = |
| 2117 specifiedDirection == ForColumns ? ForRows : ForColumns; | 2160 specifiedDirection == ForColumns ? ForRows : ForColumns; |
| 2118 const size_t endOfCrossDirection = | 2161 const size_t endOfCrossDirection = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2156 majorAxisPositions.startLine(), | 2199 majorAxisPositions.startLine(), |
| 2157 isGridAutoFlowDense | 2200 isGridAutoFlowDense |
| 2158 ? 0 | 2201 ? 0 |
| 2159 : minorAxisCursors.get(majorAxisInitialPosition)); | 2202 : minorAxisCursors.get(majorAxisInitialPosition)); |
| 2160 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( | 2203 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( |
| 2161 majorAxisPositions.integerSpan(), minorAxisSpanSize); | 2204 majorAxisPositions.integerSpan(), minorAxisSpanSize); |
| 2162 if (!emptyGridArea) | 2205 if (!emptyGridArea) |
| 2163 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2206 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2164 *autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); | 2207 *autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); |
| 2165 | 2208 |
| 2166 m_gridItemArea.set(autoGridItem, *emptyGridArea); | 2209 m_grid.insert(*autoGridItem, *emptyGridArea, |
| 2167 m_grid.insert(*autoGridItem, *emptyGridArea); | 2210 isOrthogonalChild(*autoGridItem)); |
| 2168 | 2211 |
| 2169 if (!isGridAutoFlowDense) | 2212 if (!isGridAutoFlowDense) |
| 2170 minorAxisCursors.set(majorAxisInitialPosition, | 2213 minorAxisCursors.set(majorAxisInitialPosition, |
| 2171 isForColumns ? emptyGridArea->rows.startLine() | 2214 isForColumns ? emptyGridArea->rows.startLine() |
| 2172 : emptyGridArea->columns.startLine()); | 2215 : emptyGridArea->columns.startLine()); |
| 2173 } | 2216 } |
| 2174 } | 2217 } |
| 2175 | 2218 |
| 2176 void LayoutGrid::placeAutoMajorAxisItemsOnGrid( | 2219 void LayoutGrid::placeAutoMajorAxisItemsOnGrid( |
| 2177 const Vector<LayoutBox*>& autoGridItems) { | 2220 const Vector<LayoutBox*>& autoGridItems) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2264 // auto-placement cursor in the minor axis. | 2307 // auto-placement cursor in the minor axis. |
| 2265 minorAxisAutoPlacementCursor = 0; | 2308 minorAxisAutoPlacementCursor = 0; |
| 2266 } | 2309 } |
| 2267 | 2310 |
| 2268 if (!emptyGridArea) | 2311 if (!emptyGridArea) |
| 2269 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2312 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2270 gridItem, autoPlacementMinorAxisDirection(), | 2313 gridItem, autoPlacementMinorAxisDirection(), |
| 2271 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); | 2314 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); |
| 2272 } | 2315 } |
| 2273 | 2316 |
| 2274 m_gridItemArea.set(&gridItem, *emptyGridArea); | 2317 m_grid.insert(gridItem, *emptyGridArea, isOrthogonalChild(gridItem)); |
| 2275 m_grid.insert(gridItem, *emptyGridArea); | |
| 2276 // Move auto-placement cursor to the new position. | 2318 // Move auto-placement cursor to the new position. |
| 2277 autoPlacementCursor.first = emptyGridArea->rows.startLine(); | 2319 autoPlacementCursor.first = emptyGridArea->rows.startLine(); |
| 2278 autoPlacementCursor.second = emptyGridArea->columns.startLine(); | 2320 autoPlacementCursor.second = emptyGridArea->columns.startLine(); |
| 2279 } | 2321 } |
| 2280 | 2322 |
| 2281 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { | 2323 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { |
| 2282 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 2324 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 2283 } | 2325 } |
| 2284 | 2326 |
| 2285 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { | 2327 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { |
| 2286 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 2328 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| 2287 } | 2329 } |
| 2288 | 2330 |
| 2289 void LayoutGrid::dirtyGrid() { | 2331 void LayoutGrid::dirtyGrid() { |
| 2290 if (m_gridIsDirty) | 2332 if (m_gridIsDirty) |
| 2291 return; | 2333 return; |
| 2292 | 2334 |
| 2293 m_grid.clear(); | 2335 m_grid.clear(); |
| 2294 m_gridItemArea.clear(); | |
| 2295 m_gridItemsOverflowingGridArea.resize(0); | 2336 m_gridItemsOverflowingGridArea.resize(0); |
| 2296 m_gridItemsIndexesMap.clear(); | |
| 2297 m_autoRepeatColumns = 0; | 2337 m_autoRepeatColumns = 0; |
| 2298 m_autoRepeatRows = 0; | 2338 m_autoRepeatRows = 0; |
| 2299 m_gridIsDirty = true; | 2339 m_gridIsDirty = true; |
| 2300 m_autoRepeatEmptyColumns = nullptr; | 2340 m_autoRepeatEmptyColumns = nullptr; |
| 2301 m_autoRepeatEmptyRows = nullptr; | 2341 m_autoRepeatEmptyRows = nullptr; |
| 2302 } | 2342 } |
| 2303 | 2343 |
| 2304 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( | 2344 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( |
| 2305 GridTrackSizingDirection direction) const { | 2345 GridTrackSizingDirection direction) const { |
| 2306 bool isRowAxis = direction == ForColumns; | 2346 bool isRowAxis = direction == ForColumns; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2438 // before stretching, are not set yet. | 2478 // before stretching, are not set yet. |
| 2439 applyStretchAlignmentToChildIfNeeded(*child); | 2479 applyStretchAlignmentToChildIfNeeded(*child); |
| 2440 | 2480 |
| 2441 child->layoutIfNeeded(); | 2481 child->layoutIfNeeded(); |
| 2442 | 2482 |
| 2443 // We need pending layouts to be done in order to compute auto-margins | 2483 // We need pending layouts to be done in order to compute auto-margins |
| 2444 // properly. | 2484 // properly. |
| 2445 updateAutoMarginsInColumnAxisIfNeeded(*child); | 2485 updateAutoMarginsInColumnAxisIfNeeded(*child); |
| 2446 updateAutoMarginsInRowAxisIfNeeded(*child); | 2486 updateAutoMarginsInRowAxisIfNeeded(*child); |
| 2447 | 2487 |
| 2448 const GridArea& area = cachedGridArea(*child); | 2488 const GridArea& area = m_grid.gridItemArea(*child); |
| 2449 #if ENABLE(ASSERT) | 2489 #if ENABLE(ASSERT) |
| 2450 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); | 2490 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); |
| 2451 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); | 2491 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); |
| 2452 #endif | 2492 #endif |
| 2453 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 2493 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
| 2454 | 2494 |
| 2455 // Keep track of children overflowing their grid area as we might need to | 2495 // Keep track of children overflowing their grid area as we might need to |
| 2456 // paint them even if the grid-area is not visible. Using physical | 2496 // paint them even if the grid-area is not visible. Using physical |
| 2457 // dimensions for simplicity, so we can forget about orthogonalty. | 2497 // dimensions for simplicity, so we can forget about orthogonalty. |
| 2458 LayoutUnit childGridAreaHeight = | 2498 LayoutUnit childGridAreaHeight = |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 *style(), child, direction, autoRepeatCountForDirection(direction)); | 2565 *style(), child, direction, autoRepeatCountForDirection(direction)); |
| 2526 if (positions.isIndefinite()) { | 2566 if (positions.isIndefinite()) { |
| 2527 offset = LayoutUnit(); | 2567 offset = LayoutUnit(); |
| 2528 breadth = isForColumns ? clientLogicalWidth() : clientLogicalHeight(); | 2568 breadth = isForColumns ? clientLogicalWidth() : clientLogicalHeight(); |
| 2529 return; | 2569 return; |
| 2530 } | 2570 } |
| 2531 | 2571 |
| 2532 // For positioned items we cannot use GridSpan::translate(). Because we could | 2572 // For positioned items we cannot use GridSpan::translate(). Because we could |
| 2533 // end up with negative values, as the positioned items do not create implicit | 2573 // end up with negative values, as the positioned items do not create implicit |
| 2534 // tracks per spec. | 2574 // tracks per spec. |
| 2535 int smallestStart = | 2575 int smallestStart = abs(m_grid.smallestTrackStart(direction)); |
| 2536 abs(isForColumns ? m_smallestColumnStart : m_smallestRowStart); | |
| 2537 int startLine = positions.untranslatedStartLine() + smallestStart; | 2576 int startLine = positions.untranslatedStartLine() + smallestStart; |
| 2538 int endLine = positions.untranslatedEndLine() + smallestStart; | 2577 int endLine = positions.untranslatedEndLine() + smallestStart; |
| 2539 | 2578 |
| 2540 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() | 2579 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() |
| 2541 : child.style()->gridRowStart(); | 2580 : child.style()->gridRowStart(); |
| 2542 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() | 2581 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() |
| 2543 : child.style()->gridRowEnd(); | 2582 : child.style()->gridRowEnd(); |
| 2544 int lastLine = numTracks(direction); | 2583 int lastLine = numTracks(direction); |
| 2545 | 2584 |
| 2546 bool startIsAuto = | 2585 bool startIsAuto = |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2608 borderLogicalLeft(); | 2647 borderLogicalLeft(); |
| 2609 | 2648 |
| 2610 if (endLine > 0 && endLine < lastLine) { | 2649 if (endLine > 0 && endLine < lastLine) { |
| 2611 offset += guttersSize(direction, endLine - 1, 2, TrackSizing); | 2650 offset += guttersSize(direction, endLine - 1, 2, TrackSizing); |
| 2612 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2651 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 2613 } | 2652 } |
| 2614 } | 2653 } |
| 2615 } | 2654 } |
| 2616 } | 2655 } |
| 2617 | 2656 |
| 2618 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const { | |
| 2619 ASSERT(m_gridItemArea.contains(&gridItem)); | |
| 2620 return m_gridItemArea.get(&gridItem); | |
| 2621 } | |
| 2622 | |
| 2623 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, | 2657 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, |
| 2624 GridTrackSizingDirection direction) const { | 2658 GridTrackSizingDirection direction) const { |
| 2625 GridArea area = cachedGridArea(gridItem); | 2659 GridArea area = m_grid.gridItemArea(gridItem); |
| 2626 return direction == ForColumns ? area.columns : area.rows; | 2660 return direction == ForColumns ? area.columns : area.rows; |
| 2627 } | 2661 } |
| 2628 | 2662 |
| 2629 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild( | 2663 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild( |
| 2630 const LayoutBox& child, | 2664 const LayoutBox& child, |
| 2631 SizingOperation sizingOperation) const { | 2665 SizingOperation sizingOperation) const { |
| 2632 DCHECK(isOrthogonalChild(child)); | 2666 DCHECK(isOrthogonalChild(child)); |
| 2633 const GridSpan& span = cachedGridSpan(child, ForRows); | 2667 const GridSpan& span = cachedGridSpan(child, ForRows); |
| 2634 LayoutUnit gridAreaSize; | 2668 LayoutUnit gridAreaSize; |
| 2635 bool gridAreaIsIndefinite = false; | 2669 bool gridAreaIsIndefinite = false; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2996 | 3030 |
| 2997 return baseline + beforeMarginInLineDirection(direction); | 3031 return baseline + beforeMarginInLineDirection(direction); |
| 2998 } | 3032 } |
| 2999 | 3033 |
| 3000 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const { | 3034 bool LayoutGrid::isInlineBaselineAlignedChild(const LayoutBox* child) const { |
| 3001 return alignSelfForChild(*child).position() == ItemPositionBaseline && | 3035 return alignSelfForChild(*child).position() == ItemPositionBaseline && |
| 3002 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); | 3036 !isOrthogonalChild(*child) && !hasAutoMarginsInColumnAxis(*child); |
| 3003 } | 3037 } |
| 3004 | 3038 |
| 3005 int LayoutGrid::firstLineBoxBaseline() const { | 3039 int LayoutGrid::firstLineBoxBaseline() const { |
| 3006 if (isWritingModeRoot() || m_gridItemArea.isEmpty()) | 3040 if (isWritingModeRoot() || !m_grid.hasInFlowGridItems()) |
| 3007 return -1; | 3041 return -1; |
| 3008 const LayoutBox* baselineChild = nullptr; | 3042 const LayoutBox* baselineChild = nullptr; |
| 3009 const LayoutBox* firstChild = nullptr; | 3043 const LayoutBox* firstChild = nullptr; |
| 3010 bool isBaselineAligned = false; | 3044 bool isBaselineAligned = false; |
| 3011 // Finding the first grid item in grid order. | 3045 // Finding the first grid item in grid order. |
| 3012 for (size_t column = 0; !isBaselineAligned && column < m_grid.numColumns(); | 3046 for (size_t column = 0; !isBaselineAligned && column < m_grid.numColumns(); |
| 3013 column++) { | 3047 column++) { |
| 3014 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { | 3048 for (size_t index = 0; index < m_grid.cell(0, column).size(); index++) { |
| 3015 const LayoutBox* child = m_grid.cell(0, column)[index]; | 3049 const LayoutBox* child = m_grid.cell(0, column)[index]; |
| 3016 DCHECK(!child->isOutOfFlowPositioned()); | 3050 DCHECK(!child->isOutOfFlowPositioned()); |
| 3017 // If an item participates in baseline alignmen, we select such item. | 3051 // If an item participates in baseline alignmen, we select such item. |
| 3018 if (isInlineBaselineAlignedChild(child)) { | 3052 if (isInlineBaselineAlignedChild(child)) { |
| 3019 // TODO (lajava): self-baseline and content-baseline alignment | 3053 // TODO (lajava): self-baseline and content-baseline alignment |
| 3020 // still not implemented. | 3054 // still not implemented. |
| 3021 baselineChild = child; | 3055 baselineChild = child; |
| 3022 isBaselineAligned = true; | 3056 isBaselineAligned = true; |
| 3023 break; | 3057 break; |
| 3024 } | 3058 } |
| 3025 if (!baselineChild) { | 3059 if (!baselineChild) { |
| 3026 // Use dom order for items in the same cell. | 3060 // Use dom order for items in the same cell. |
| 3027 if (!firstChild || (m_gridItemsIndexesMap.get(child) < | 3061 if (!firstChild || (m_grid.gridItemPaintOrder(*child) < |
| 3028 m_gridItemsIndexesMap.get(firstChild))) | 3062 m_grid.gridItemPaintOrder(*firstChild))) |
| 3029 firstChild = child; | 3063 firstChild = child; |
| 3030 } | 3064 } |
| 3031 } | 3065 } |
| 3032 if (!baselineChild && firstChild) | 3066 if (!baselineChild && firstChild) |
| 3033 baselineChild = firstChild; | 3067 baselineChild = firstChild; |
| 3034 } | 3068 } |
| 3035 | 3069 |
| 3036 if (!baselineChild) | 3070 if (!baselineChild) |
| 3037 return -1; | 3071 return -1; |
| 3038 | 3072 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3481 // See comment in findChildLogicalPosition() about why we need sometimes to | 3515 // See comment in findChildLogicalPosition() about why we need sometimes to |
| 3482 // translate from RTL to LTR the rowAxisOffset coordinate. | 3516 // translate from RTL to LTR the rowAxisOffset coordinate. |
| 3483 return LayoutPoint(style()->isLeftToRightDirection() | 3517 return LayoutPoint(style()->isLeftToRightDirection() |
| 3484 ? rowAxisOffset | 3518 ? rowAxisOffset |
| 3485 : translateRTLCoordinate(rowAxisOffset), | 3519 : translateRTLCoordinate(rowAxisOffset), |
| 3486 columnAxisOffset); | 3520 columnAxisOffset); |
| 3487 } | 3521 } |
| 3488 | 3522 |
| 3489 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, | 3523 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, |
| 3490 const LayoutPoint& paintOffset) const { | 3524 const LayoutPoint& paintOffset) const { |
| 3491 if (!m_gridItemArea.isEmpty()) | 3525 if (m_grid.hasInFlowGridItems()) |
| 3492 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 3526 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 3493 } | 3527 } |
| 3494 | 3528 |
| 3495 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { | 3529 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { |
| 3496 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); | 3530 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); |
| 3497 return m_hasDefiniteLogicalHeight.value(); | 3531 return m_hasDefiniteLogicalHeight.value(); |
| 3498 } | 3532 } |
| 3499 | 3533 |
| 3500 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { | 3534 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { |
| 3501 // Due to limitations in our internal representation, we cannot know the | 3535 // Due to limitations in our internal representation, we cannot know the |
| 3502 // number of columns from m_grid *if* there is no row (because m_grid would be | 3536 // number of columns from m_grid *if* there is no row (because m_grid would be |
| 3503 // empty). That's why in that case we need to get it from the style. Note that | 3537 // empty). That's why in that case we need to get it from the style. Note that |
| 3504 // we know for sure that there are't any implicit tracks, because not having | 3538 // we know for sure that there are't any implicit tracks, because not having |
| 3505 // rows implies that there are no "normal" children (out-of-flow children are | 3539 // rows implies that there are no "normal" children (out-of-flow children are |
| 3506 // not stored in m_grid). | 3540 // not stored in m_grid). |
| 3507 if (direction == ForRows) | 3541 if (direction == ForRows) |
| 3508 return m_grid.numRows(); | 3542 return m_grid.numRows(); |
| 3509 | 3543 |
| 3510 return m_grid.numRows() ? m_grid.numColumns() | 3544 return m_grid.numRows() ? m_grid.numColumns() |
| 3511 : GridPositionsResolver::explicitGridColumnCount( | 3545 : GridPositionsResolver::explicitGridColumnCount( |
| 3512 styleRef(), m_autoRepeatColumns); | 3546 styleRef(), m_autoRepeatColumns); |
| 3513 } | 3547 } |
| 3514 | 3548 |
| 3515 } // namespace blink | 3549 } // namespace blink |
| OLD | NEW |