| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 GridTrackSizingDirection direction) const { | 157 GridTrackSizingDirection direction) const { |
| 158 GridArea area = gridItemArea(gridItem); | 158 GridArea area = gridItemArea(gridItem); |
| 159 return direction == ForColumns ? area.columns : area.rows; | 159 return direction == ForColumns ? area.columns : area.rows; |
| 160 } | 160 } |
| 161 | 161 |
| 162 void LayoutGrid::Grid::setHasAnyOrthogonalGridItem( | 162 void LayoutGrid::Grid::setHasAnyOrthogonalGridItem( |
| 163 bool hasAnyOrthogonalGridItem) { | 163 bool hasAnyOrthogonalGridItem) { |
| 164 m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; | 164 m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void LayoutGrid::Grid::clear() { | 167 void LayoutGrid::Grid::setNeedsItemsPlacement(bool needsItemsPlacement) { |
| 168 m_needsItemsPlacement = needsItemsPlacement; |
| 169 |
| 170 if (!needsItemsPlacement) { |
| 171 m_grid.shrinkToFit(); |
| 172 return; |
| 173 } |
| 174 |
| 168 m_grid.resize(0); | 175 m_grid.resize(0); |
| 169 m_gridItemArea.clear(); | 176 m_gridItemArea.clear(); |
| 170 m_gridItemsIndexesMap.clear(); | 177 m_gridItemsIndexesMap.clear(); |
| 171 m_hasAnyOrthogonalGridItem = false; | 178 m_hasAnyOrthogonalGridItem = false; |
| 172 m_smallestRowStart = 0; | 179 m_smallestRowStart = 0; |
| 173 m_smallestColumnStart = 0; | 180 m_smallestColumnStart = 0; |
| 174 m_autoRepeatColumns = 0; | 181 m_autoRepeatColumns = 0; |
| 175 m_autoRepeatRows = 0; | 182 m_autoRepeatRows = 0; |
| 176 m_autoRepeatEmptyColumns = nullptr; | 183 m_autoRepeatEmptyColumns = nullptr; |
| 177 m_autoRepeatEmptyRows = nullptr; | 184 m_autoRepeatEmptyRows = nullptr; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // during each axis track sizing. It's cached here because we need it to | 462 // during each axis track sizing. It's cached here because we need it to |
| 456 // compute relative sizes. | 463 // compute relative sizes. |
| 457 LayoutUnit m_availableSpace; | 464 LayoutUnit m_availableSpace; |
| 458 }; | 465 }; |
| 459 | 466 |
| 460 struct GridItemsSpanGroupRange { | 467 struct GridItemsSpanGroupRange { |
| 461 Vector<GridItemWithSpan>::iterator rangeStart; | 468 Vector<GridItemWithSpan>::iterator rangeStart; |
| 462 Vector<GridItemWithSpan>::iterator rangeEnd; | 469 Vector<GridItemWithSpan>::iterator rangeEnd; |
| 463 }; | 470 }; |
| 464 | 471 |
| 465 LayoutGrid::LayoutGrid(Element* element) | 472 LayoutGrid::LayoutGrid(Element* element) : LayoutBlock(element), m_grid(this) { |
| 466 : LayoutBlock(element), m_grid(this), m_gridIsDirty(true) { | |
| 467 ASSERT(!childrenInline()); | 473 ASSERT(!childrenInline()); |
| 468 if (!isAnonymous()) | 474 if (!isAnonymous()) |
| 469 UseCounter::count(document(), UseCounter::CSSGridLayout); | 475 UseCounter::count(document(), UseCounter::CSSGridLayout); |
| 470 } | 476 } |
| 471 | 477 |
| 472 LayoutGrid::~LayoutGrid() {} | 478 LayoutGrid::~LayoutGrid() {} |
| 473 | 479 |
| 474 LayoutGrid* LayoutGrid::createAnonymous(Document* document) { | 480 LayoutGrid* LayoutGrid::createAnonymous(Document* document) { |
| 475 LayoutGrid* layoutGrid = new LayoutGrid(nullptr); | 481 LayoutGrid* layoutGrid = new LayoutGrid(nullptr); |
| 476 layoutGrid->setDocumentForAnonymous(document); | 482 layoutGrid->setDocumentForAnonymous(document); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 computeTrackSizesForDefiniteSize(ForRows, sizingData, | 593 computeTrackSizesForDefiniteSize(ForRows, sizingData, |
| 588 availableSpaceForRows); | 594 availableSpaceForRows); |
| 589 } | 595 } |
| 590 } | 596 } |
| 591 | 597 |
| 592 void LayoutGrid::layoutBlock(bool relayoutChildren) { | 598 void LayoutGrid::layoutBlock(bool relayoutChildren) { |
| 593 ASSERT(needsLayout()); | 599 ASSERT(needsLayout()); |
| 594 | 600 |
| 595 // We cannot perform a simplifiedLayout() on a dirty grid that | 601 // We cannot perform a simplifiedLayout() on a dirty grid that |
| 596 // has positioned items to be laid out. | 602 // has positioned items to be laid out. |
| 597 if (!relayoutChildren && (!m_gridIsDirty || !posChildNeedsLayout()) && | 603 if (!relayoutChildren && |
| 604 (!m_grid.needsItemsPlacement() || !posChildNeedsLayout()) && |
| 598 simplifiedLayout()) | 605 simplifiedLayout()) |
| 599 return; | 606 return; |
| 600 | 607 |
| 601 SubtreeLayoutScope layoutScope(*this); | 608 SubtreeLayoutScope layoutScope(*this); |
| 602 | 609 |
| 603 { | 610 { |
| 604 // LayoutState needs this deliberate scope to pop before updating scroll | 611 // LayoutState needs this deliberate scope to pop before updating scroll |
| 605 // information (which may trigger relayout). | 612 // information (which may trigger relayout). |
| 606 LayoutState state(*this); | 613 LayoutState state(*this); |
| 607 | 614 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 630 // TODO(svillar): we won't need to do this once the intrinsic width | 637 // TODO(svillar): we won't need to do this once the intrinsic width |
| 631 // computation is isolated from the LayoutGrid object state (it should not | 638 // computation is isolated from the LayoutGrid object state (it should not |
| 632 // touch any attribute) (see crbug.com/627812) | 639 // touch any attribute) (see crbug.com/627812) |
| 633 size_t autoRepeatColumns = m_grid.autoRepeatTracks(ForColumns); | 640 size_t autoRepeatColumns = m_grid.autoRepeatTracks(ForColumns); |
| 634 if (autoRepeatColumns && | 641 if (autoRepeatColumns && |
| 635 autoRepeatColumns != | 642 autoRepeatColumns != |
| 636 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) | 643 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) |
| 637 dirtyGrid(); | 644 dirtyGrid(); |
| 638 placeItemsOnGrid(m_grid, TrackSizing); | 645 placeItemsOnGrid(m_grid, TrackSizing); |
| 639 | 646 |
| 640 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); | 647 GridSizingData sizingData(numTracks(ForColumns, m_grid), |
| 648 numTracks(ForRows, m_grid)); |
| 641 | 649 |
| 642 // 1- First, the track sizing algorithm is used to resolve the sizes of the | 650 // 1- First, the track sizing algorithm is used to resolve the sizes of the |
| 643 // grid columns. | 651 // grid columns. |
| 644 // At this point the logical width is always definite as the above call to | 652 // At this point the logical width is always definite as the above call to |
| 645 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the | 653 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the |
| 646 // same for heights though because many code paths inside | 654 // same for heights though because many code paths inside |
| 647 // updateLogicalHeight() require a previous call to setLogicalHeight() to | 655 // updateLogicalHeight() require a previous call to setLogicalHeight() to |
| 648 // resolve heights properly (like for positioned items for example). | 656 // resolve heights properly (like for positioned items for example). |
| 649 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 657 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| 650 computeTrackSizesForDefiniteSize(ForColumns, sizingData, | 658 computeTrackSizesForDefiniteSize(ForColumns, sizingData, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 | 797 |
| 790 return gapAccumulator; | 798 return gapAccumulator; |
| 791 } | 799 } |
| 792 | 800 |
| 793 void LayoutGrid::computeIntrinsicLogicalWidths( | 801 void LayoutGrid::computeIntrinsicLogicalWidths( |
| 794 LayoutUnit& minLogicalWidth, | 802 LayoutUnit& minLogicalWidth, |
| 795 LayoutUnit& maxLogicalWidth) const { | 803 LayoutUnit& maxLogicalWidth) const { |
| 796 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(const_cast<Grid&>(m_grid), | 804 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(const_cast<Grid&>(m_grid), |
| 797 IntrinsicSizeComputation); | 805 IntrinsicSizeComputation); |
| 798 | 806 |
| 799 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); | 807 GridSizingData sizingData(numTracks(ForColumns, m_grid), |
| 808 numTracks(ForRows, m_grid)); |
| 800 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, | 809 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, |
| 801 maxLogicalWidth); | 810 maxLogicalWidth); |
| 802 | 811 |
| 803 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 812 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
| 804 minLogicalWidth += scrollbarWidth; | 813 minLogicalWidth += scrollbarWidth; |
| 805 maxLogicalWidth += scrollbarWidth; | 814 maxLogicalWidth += scrollbarWidth; |
| 806 } | 815 } |
| 807 | 816 |
| 808 void LayoutGrid::computeTrackSizesForIndefiniteSize( | 817 void LayoutGrid::computeTrackSizesForIndefiniteSize( |
| 809 GridTrackSizingDirection direction, | 818 GridTrackSizingDirection direction, |
| (...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 // repetitions is the largest possible positive integer that fulfills that | 2021 // repetitions is the largest possible positive integer that fulfills that |
| 2013 // minimum requirement. | 2022 // minimum requirement. |
| 2014 if (needsToFulfillMinimumSize) | 2023 if (needsToFulfillMinimumSize) |
| 2015 ++repetitions; | 2024 ++repetitions; |
| 2016 | 2025 |
| 2017 return repetitions * autoRepeatTrackListLength; | 2026 return repetitions * autoRepeatTrackListLength; |
| 2018 } | 2027 } |
| 2019 | 2028 |
| 2020 std::unique_ptr<LayoutGrid::OrderedTrackIndexSet> | 2029 std::unique_ptr<LayoutGrid::OrderedTrackIndexSet> |
| 2021 LayoutGrid::computeEmptyTracksForAutoRepeat( | 2030 LayoutGrid::computeEmptyTracksForAutoRepeat( |
| 2031 Grid& grid, |
| 2022 GridTrackSizingDirection direction) const { | 2032 GridTrackSizingDirection direction) const { |
| 2023 bool isRowAxis = direction == ForColumns; | 2033 bool isRowAxis = direction == ForColumns; |
| 2024 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || | 2034 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) || |
| 2025 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) | 2035 (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) |
| 2026 return nullptr; | 2036 return nullptr; |
| 2027 | 2037 |
| 2028 std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes; | 2038 std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes; |
| 2029 size_t insertionPoint = isRowAxis | 2039 size_t insertionPoint = isRowAxis |
| 2030 ? styleRef().gridAutoRepeatColumnsInsertionPoint() | 2040 ? styleRef().gridAutoRepeatColumnsInsertionPoint() |
| 2031 : styleRef().gridAutoRepeatRowsInsertionPoint(); | 2041 : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| 2032 size_t firstAutoRepeatTrack = | 2042 size_t firstAutoRepeatTrack = |
| 2033 insertionPoint + std::abs(m_grid.smallestTrackStart(direction)); | 2043 insertionPoint + std::abs(grid.smallestTrackStart(direction)); |
| 2034 size_t lastAutoRepeatTrack = | 2044 size_t lastAutoRepeatTrack = |
| 2035 firstAutoRepeatTrack + autoRepeatCountForDirection(direction); | 2045 firstAutoRepeatTrack + grid.autoRepeatTracks(direction); |
| 2036 | 2046 |
| 2037 if (!m_grid.hasGridItems()) { | 2047 if (!m_grid.hasGridItems()) { |
| 2038 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); | 2048 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 2039 for (size_t trackIndex = firstAutoRepeatTrack; | 2049 for (size_t trackIndex = firstAutoRepeatTrack; |
| 2040 trackIndex < lastAutoRepeatTrack; ++trackIndex) | 2050 trackIndex < lastAutoRepeatTrack; ++trackIndex) |
| 2041 emptyTrackIndexes->add(trackIndex); | 2051 emptyTrackIndexes->add(trackIndex); |
| 2042 } else { | 2052 } else { |
| 2043 for (size_t trackIndex = firstAutoRepeatTrack; | 2053 for (size_t trackIndex = firstAutoRepeatTrack; |
| 2044 trackIndex < lastAutoRepeatTrack; ++trackIndex) { | 2054 trackIndex < lastAutoRepeatTrack; ++trackIndex) { |
| 2045 GridIterator iterator(m_grid, direction, trackIndex); | 2055 GridIterator iterator(grid, direction, trackIndex); |
| 2046 if (!iterator.nextGridItem()) { | 2056 if (!iterator.nextGridItem()) { |
| 2047 if (!emptyTrackIndexes) | 2057 if (!emptyTrackIndexes) |
| 2048 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); | 2058 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 2049 emptyTrackIndexes->add(trackIndex); | 2059 emptyTrackIndexes->add(trackIndex); |
| 2050 } | 2060 } |
| 2051 } | 2061 } |
| 2052 } | 2062 } |
| 2053 return emptyTrackIndexes; | 2063 return emptyTrackIndexes; |
| 2054 } | 2064 } |
| 2055 | 2065 |
| 2056 void LayoutGrid::placeItemsOnGrid(LayoutGrid::Grid& grid, | 2066 void LayoutGrid::placeItemsOnGrid(LayoutGrid::Grid& grid, |
| 2057 SizingOperation sizingOperation) { | 2067 SizingOperation sizingOperation) { |
| 2058 if (!m_gridIsDirty) | 2068 if (!grid.needsItemsPlacement()) |
| 2059 return; | 2069 return; |
| 2060 | 2070 |
| 2061 DCHECK(!grid.hasGridItems()); | 2071 DCHECK(!grid.hasGridItems()); |
| 2062 | 2072 |
| 2063 size_t autoRepeatColumns; | 2073 size_t autoRepeatColumns; |
| 2064 size_t autoRepeatRows = | 2074 size_t autoRepeatRows = |
| 2065 computeAutoRepeatTracksCount(ForRows, sizingOperation); | 2075 computeAutoRepeatTracksCount(ForRows, sizingOperation); |
| 2066 if (sizingOperation == IntrinsicSizeComputation) { | 2076 if (sizingOperation == IntrinsicSizeComputation) { |
| 2067 autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); | 2077 autoRepeatColumns = styleRef().gridAutoRepeatColumns().size(); |
| 2068 } else { | 2078 } else { |
| 2069 autoRepeatColumns = | 2079 autoRepeatColumns = |
| 2070 computeAutoRepeatTracksCount(ForColumns, sizingOperation); | 2080 computeAutoRepeatTracksCount(ForColumns, sizingOperation); |
| 2071 } | 2081 } |
| 2072 m_grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); | 2082 m_grid.setAutoRepeatTracks(autoRepeatRows, autoRepeatColumns); |
| 2073 | 2083 |
| 2074 populateExplicitGridAndOrderIterator(grid); | 2084 populateExplicitGridAndOrderIterator(grid); |
| 2075 | 2085 |
| 2076 // We clear the dirty bit here as the grid sizes have been updated. | |
| 2077 m_gridIsDirty = false; | |
| 2078 bool hasAnyOrthogonalGridItem = false; | |
| 2079 | |
| 2080 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 2086 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
| 2081 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 2087 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
| 2082 #if ENABLE(ASSERT) | 2088 #if ENABLE(ASSERT) |
| 2083 DCHECK(!grid.hasAnyGridItemPaintOrder()); | 2089 DCHECK(!grid.hasAnyGridItemPaintOrder()); |
| 2084 #endif | 2090 #endif |
| 2085 DCHECK(!grid.hasAnyOrthogonalGridItem()); | 2091 DCHECK(!grid.hasAnyOrthogonalGridItem()); |
| 2092 bool hasAnyOrthogonalGridItem = false; |
| 2086 size_t childIndex = 0; | 2093 size_t childIndex = 0; |
| 2087 for (LayoutBox* child = grid.orderIterator().first(); child; | 2094 for (LayoutBox* child = grid.orderIterator().first(); child; |
| 2088 child = grid.orderIterator().next()) { | 2095 child = grid.orderIterator().next()) { |
| 2089 if (child->isOutOfFlowPositioned()) | 2096 if (child->isOutOfFlowPositioned()) |
| 2090 continue; | 2097 continue; |
| 2091 | 2098 |
| 2092 hasAnyOrthogonalGridItem = | 2099 hasAnyOrthogonalGridItem = |
| 2093 hasAnyOrthogonalGridItem || isOrthogonalChild(*child); | 2100 hasAnyOrthogonalGridItem || isOrthogonalChild(*child); |
| 2094 grid.setGridItemPaintOrder(*child, childIndex++); | 2101 grid.setGridItemPaintOrder(*child, childIndex++); |
| 2095 | 2102 |
| 2096 GridArea area = grid.gridItemArea(*child); | 2103 GridArea area = grid.gridItemArea(*child); |
| 2097 if (!area.rows.isIndefinite()) | 2104 if (!area.rows.isIndefinite()) |
| 2098 area.rows.translate(abs(grid.smallestTrackStart(ForRows))); | 2105 area.rows.translate(abs(grid.smallestTrackStart(ForRows))); |
| 2099 if (!area.columns.isIndefinite()) | 2106 if (!area.columns.isIndefinite()) |
| 2100 area.columns.translate(abs(grid.smallestTrackStart(ForColumns))); | 2107 area.columns.translate(abs(grid.smallestTrackStart(ForColumns))); |
| 2101 | 2108 |
| 2102 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 2109 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 2103 grid.setGridItemArea(*child, area); | 2110 grid.setGridItemArea(*child, area); |
| 2104 GridSpan majorAxisPositions = | 2111 GridSpan majorAxisPositions = |
| 2105 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns | 2112 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns |
| 2106 : area.rows; | 2113 : area.rows; |
| 2107 if (majorAxisPositions.isIndefinite()) | 2114 if (majorAxisPositions.isIndefinite()) |
| 2108 autoMajorAxisAutoGridItems.append(child); | 2115 autoMajorAxisAutoGridItems.append(child); |
| 2109 else | 2116 else |
| 2110 specifiedMajorAxisAutoGridItems.append(child); | 2117 specifiedMajorAxisAutoGridItems.append(child); |
| 2111 continue; | 2118 continue; |
| 2112 } | 2119 } |
| 2113 grid.insert(*child, area); | 2120 grid.insert(*child, area); |
| 2114 } | 2121 } |
| 2115 m_grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem); | 2122 grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem); |
| 2116 | 2123 |
| 2117 #if ENABLE(ASSERT) | 2124 #if ENABLE(ASSERT) |
| 2118 if (grid.hasGridItems()) { | 2125 if (grid.hasGridItems()) { |
| 2119 DCHECK_GE(grid.numTracks(ForRows), | 2126 DCHECK_GE(grid.numTracks(ForRows), |
| 2120 GridPositionsResolver::explicitGridRowCount( | 2127 GridPositionsResolver::explicitGridRowCount( |
| 2121 *style(), grid.autoRepeatTracks(ForRows))); | 2128 *style(), grid.autoRepeatTracks(ForRows))); |
| 2122 DCHECK_GE(grid.numTracks(ForColumns), | 2129 DCHECK_GE(grid.numTracks(ForColumns), |
| 2123 GridPositionsResolver::explicitGridColumnCount( | 2130 GridPositionsResolver::explicitGridColumnCount( |
| 2124 *style(), grid.autoRepeatTracks(ForColumns))); | 2131 *style(), grid.autoRepeatTracks(ForColumns))); |
| 2125 } | 2132 } |
| 2126 #endif | 2133 #endif |
| 2127 | 2134 |
| 2128 placeSpecifiedMajorAxisItemsOnGrid(grid, specifiedMajorAxisAutoGridItems); | 2135 placeSpecifiedMajorAxisItemsOnGrid(grid, specifiedMajorAxisAutoGridItems); |
| 2129 placeAutoMajorAxisItemsOnGrid(grid, autoMajorAxisAutoGridItems); | 2136 placeAutoMajorAxisItemsOnGrid(grid, autoMajorAxisAutoGridItems); |
| 2130 | 2137 |
| 2131 grid.shrinkToFit(); | 2138 // Compute collapsable tracks for auto-fit. |
| 2139 grid.setAutoRepeatEmptyColumns( |
| 2140 computeEmptyTracksForAutoRepeat(grid, ForColumns)); |
| 2141 grid.setAutoRepeatEmptyRows(computeEmptyTracksForAutoRepeat(grid, ForRows)); |
| 2132 | 2142 |
| 2133 // Compute collapsable tracks for auto-fit. | 2143 grid.setNeedsItemsPlacement(false); |
| 2134 grid.setAutoRepeatEmptyColumns(computeEmptyTracksForAutoRepeat(ForColumns)); | |
| 2135 grid.setAutoRepeatEmptyRows(computeEmptyTracksForAutoRepeat(ForRows)); | |
| 2136 | 2144 |
| 2137 #if ENABLE(ASSERT) | 2145 #if ENABLE(ASSERT) |
| 2138 for (LayoutBox* child = grid.orderIterator().first(); child; | 2146 for (LayoutBox* child = grid.orderIterator().first(); child; |
| 2139 child = grid.orderIterator().next()) { | 2147 child = grid.orderIterator().next()) { |
| 2140 if (child->isOutOfFlowPositioned()) | 2148 if (child->isOutOfFlowPositioned()) |
| 2141 continue; | 2149 continue; |
| 2142 | 2150 |
| 2143 GridArea area = grid.gridItemArea(*child); | 2151 GridArea area = grid.gridItemArea(*child); |
| 2144 ASSERT(area.rows.isTranslatedDefinite() && | 2152 ASSERT(area.rows.isTranslatedDefinite() && |
| 2145 area.columns.isTranslatedDefinite()); | 2153 area.columns.isTranslatedDefinite()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 } | 2209 } |
| 2202 } | 2210 } |
| 2203 | 2211 |
| 2204 grid.setSmallestTracksStart(smallestRowStart, smallestColumnStart); | 2212 grid.setSmallestTracksStart(smallestRowStart, smallestColumnStart); |
| 2205 grid.ensureGridSize(maximumRowIndex + abs(smallestRowStart), | 2213 grid.ensureGridSize(maximumRowIndex + abs(smallestRowStart), |
| 2206 maximumColumnIndex + abs(smallestColumnStart)); | 2214 maximumColumnIndex + abs(smallestColumnStart)); |
| 2207 } | 2215 } |
| 2208 | 2216 |
| 2209 std::unique_ptr<GridArea> | 2217 std::unique_ptr<GridArea> |
| 2210 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2218 LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2219 const Grid& grid, |
| 2211 const LayoutBox& gridItem, | 2220 const LayoutBox& gridItem, |
| 2212 GridTrackSizingDirection specifiedDirection, | 2221 GridTrackSizingDirection specifiedDirection, |
| 2213 const GridSpan& specifiedPositions) const { | 2222 const GridSpan& specifiedPositions) const { |
| 2214 GridTrackSizingDirection crossDirection = | 2223 GridTrackSizingDirection crossDirection = |
| 2215 specifiedDirection == ForColumns ? ForRows : ForColumns; | 2224 specifiedDirection == ForColumns ? ForRows : ForColumns; |
| 2216 const size_t endOfCrossDirection = m_grid.numTracks(crossDirection); | 2225 const size_t endOfCrossDirection = grid.numTracks(crossDirection); |
| 2217 size_t crossDirectionSpanSize = | 2226 size_t crossDirectionSpanSize = |
| 2218 GridPositionsResolver::spanSizeForAutoPlacedItem(*style(), gridItem, | 2227 GridPositionsResolver::spanSizeForAutoPlacedItem(*style(), gridItem, |
| 2219 crossDirection); | 2228 crossDirection); |
| 2220 GridSpan crossDirectionPositions = GridSpan::translatedDefiniteGridSpan( | 2229 GridSpan crossDirectionPositions = GridSpan::translatedDefiniteGridSpan( |
| 2221 endOfCrossDirection, endOfCrossDirection + crossDirectionSpanSize); | 2230 endOfCrossDirection, endOfCrossDirection + crossDirectionSpanSize); |
| 2222 return wrapUnique( | 2231 return wrapUnique( |
| 2223 new GridArea(specifiedDirection == ForColumns ? crossDirectionPositions | 2232 new GridArea(specifiedDirection == ForColumns ? crossDirectionPositions |
| 2224 : specifiedPositions, | 2233 : specifiedPositions, |
| 2225 specifiedDirection == ForColumns ? specifiedPositions | 2234 specifiedDirection == ForColumns ? specifiedPositions |
| 2226 : crossDirectionPositions)); | 2235 : crossDirectionPositions)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2249 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2258 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2250 *style(), *autoGridItem, autoPlacementMinorAxisDirection()); | 2259 *style(), *autoGridItem, autoPlacementMinorAxisDirection()); |
| 2251 unsigned majorAxisInitialPosition = majorAxisPositions.startLine(); | 2260 unsigned majorAxisInitialPosition = majorAxisPositions.startLine(); |
| 2252 | 2261 |
| 2253 GridIterator iterator( | 2262 GridIterator iterator( |
| 2254 grid, autoPlacementMajorAxisDirection(), majorAxisPositions.startLine(), | 2263 grid, autoPlacementMajorAxisDirection(), majorAxisPositions.startLine(), |
| 2255 isGridAutoFlowDense ? 0 | 2264 isGridAutoFlowDense ? 0 |
| 2256 : minorAxisCursors.get(majorAxisInitialPosition)); | 2265 : minorAxisCursors.get(majorAxisInitialPosition)); |
| 2257 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( | 2266 std::unique_ptr<GridArea> emptyGridArea = iterator.nextEmptyGridArea( |
| 2258 majorAxisPositions.integerSpan(), minorAxisSpanSize); | 2267 majorAxisPositions.integerSpan(), minorAxisSpanSize); |
| 2259 if (!emptyGridArea) | 2268 if (!emptyGridArea) { |
| 2260 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2269 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2261 *autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); | 2270 grid, *autoGridItem, autoPlacementMajorAxisDirection(), |
| 2271 majorAxisPositions); |
| 2272 } |
| 2262 | 2273 |
| 2263 grid.insert(*autoGridItem, *emptyGridArea); | 2274 grid.insert(*autoGridItem, *emptyGridArea); |
| 2264 | 2275 |
| 2265 if (!isGridAutoFlowDense) | 2276 if (!isGridAutoFlowDense) |
| 2266 minorAxisCursors.set(majorAxisInitialPosition, | 2277 minorAxisCursors.set(majorAxisInitialPosition, |
| 2267 isForColumns ? emptyGridArea->rows.startLine() | 2278 isForColumns ? emptyGridArea->rows.startLine() |
| 2268 : emptyGridArea->columns.startLine()); | 2279 : emptyGridArea->columns.startLine()); |
| 2269 } | 2280 } |
| 2270 } | 2281 } |
| 2271 | 2282 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2316 majorAxisAutoPlacementCursor++; | 2327 majorAxisAutoPlacementCursor++; |
| 2317 | 2328 |
| 2318 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { | 2329 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { |
| 2319 GridIterator iterator(grid, autoPlacementMinorAxisDirection(), | 2330 GridIterator iterator(grid, autoPlacementMinorAxisDirection(), |
| 2320 minorAxisPositions.startLine(), | 2331 minorAxisPositions.startLine(), |
| 2321 majorAxisAutoPlacementCursor); | 2332 majorAxisAutoPlacementCursor); |
| 2322 emptyGridArea = iterator.nextEmptyGridArea( | 2333 emptyGridArea = iterator.nextEmptyGridArea( |
| 2323 minorAxisPositions.integerSpan(), majorAxisSpanSize); | 2334 minorAxisPositions.integerSpan(), majorAxisSpanSize); |
| 2324 } | 2335 } |
| 2325 | 2336 |
| 2326 if (!emptyGridArea) | 2337 if (!emptyGridArea) { |
| 2327 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2338 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2328 gridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); | 2339 grid, gridItem, autoPlacementMinorAxisDirection(), |
| 2340 minorAxisPositions); |
| 2341 } |
| 2329 } else { | 2342 } else { |
| 2330 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( | 2343 size_t minorAxisSpanSize = GridPositionsResolver::spanSizeForAutoPlacedItem( |
| 2331 *style(), gridItem, autoPlacementMinorAxisDirection()); | 2344 *style(), gridItem, autoPlacementMinorAxisDirection()); |
| 2332 | 2345 |
| 2333 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; | 2346 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; |
| 2334 majorAxisIndex < endOfMajorAxis; ++majorAxisIndex) { | 2347 majorAxisIndex < endOfMajorAxis; ++majorAxisIndex) { |
| 2335 GridIterator iterator(grid, autoPlacementMajorAxisDirection(), | 2348 GridIterator iterator(grid, autoPlacementMajorAxisDirection(), |
| 2336 majorAxisIndex, minorAxisAutoPlacementCursor); | 2349 majorAxisIndex, minorAxisAutoPlacementCursor); |
| 2337 emptyGridArea = | 2350 emptyGridArea = |
| 2338 iterator.nextEmptyGridArea(majorAxisSpanSize, minorAxisSpanSize); | 2351 iterator.nextEmptyGridArea(majorAxisSpanSize, minorAxisSpanSize); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2356 emptyGridArea = nullptr; | 2369 emptyGridArea = nullptr; |
| 2357 } | 2370 } |
| 2358 | 2371 |
| 2359 // As we're moving to the next track in the major axis we should reset the | 2372 // As we're moving to the next track in the major axis we should reset the |
| 2360 // auto-placement cursor in the minor axis. | 2373 // auto-placement cursor in the minor axis. |
| 2361 minorAxisAutoPlacementCursor = 0; | 2374 minorAxisAutoPlacementCursor = 0; |
| 2362 } | 2375 } |
| 2363 | 2376 |
| 2364 if (!emptyGridArea) | 2377 if (!emptyGridArea) |
| 2365 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 2378 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 2366 gridItem, autoPlacementMinorAxisDirection(), | 2379 grid, gridItem, autoPlacementMinorAxisDirection(), |
| 2367 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); | 2380 GridSpan::translatedDefiniteGridSpan(0, minorAxisSpanSize)); |
| 2368 } | 2381 } |
| 2369 | 2382 |
| 2370 grid.insert(gridItem, *emptyGridArea); | 2383 grid.insert(gridItem, *emptyGridArea); |
| 2371 // Move auto-placement cursor to the new position. | 2384 // Move auto-placement cursor to the new position. |
| 2372 autoPlacementCursor.first = emptyGridArea->rows.startLine(); | 2385 autoPlacementCursor.first = emptyGridArea->rows.startLine(); |
| 2373 autoPlacementCursor.second = emptyGridArea->columns.startLine(); | 2386 autoPlacementCursor.second = emptyGridArea->columns.startLine(); |
| 2374 } | 2387 } |
| 2375 | 2388 |
| 2376 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { | 2389 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const { |
| 2377 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 2390 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 2378 } | 2391 } |
| 2379 | 2392 |
| 2380 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { | 2393 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const { |
| 2381 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 2394 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| 2382 } | 2395 } |
| 2383 | 2396 |
| 2384 void LayoutGrid::dirtyGrid() { | 2397 void LayoutGrid::dirtyGrid() { |
| 2385 if (m_gridIsDirty) | 2398 if (m_grid.needsItemsPlacement()) |
| 2386 return; | 2399 return; |
| 2387 | 2400 |
| 2388 m_grid.clear(); | 2401 m_grid.setNeedsItemsPlacement(true); |
| 2389 m_gridItemsOverflowingGridArea.resize(0); | 2402 m_gridItemsOverflowingGridArea.resize(0); |
| 2390 m_gridIsDirty = true; | |
| 2391 } | 2403 } |
| 2392 | 2404 |
| 2393 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( | 2405 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle( |
| 2394 GridTrackSizingDirection direction) const { | 2406 GridTrackSizingDirection direction) const { |
| 2395 bool isRowAxis = direction == ForColumns; | 2407 bool isRowAxis = direction == ForColumns; |
| 2396 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2408 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 2397 size_t numPositions = positions.size(); | 2409 size_t numPositions = positions.size(); |
| 2398 LayoutUnit offsetBetweenTracks = | 2410 LayoutUnit offsetBetweenTracks = |
| 2399 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2411 isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 2400 | 2412 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2625 // end up with negative values, as the positioned items do not create implicit | 2637 // end up with negative values, as the positioned items do not create implicit |
| 2626 // tracks per spec. | 2638 // tracks per spec. |
| 2627 int smallestStart = abs(m_grid.smallestTrackStart(direction)); | 2639 int smallestStart = abs(m_grid.smallestTrackStart(direction)); |
| 2628 int startLine = positions.untranslatedStartLine() + smallestStart; | 2640 int startLine = positions.untranslatedStartLine() + smallestStart; |
| 2629 int endLine = positions.untranslatedEndLine() + smallestStart; | 2641 int endLine = positions.untranslatedEndLine() + smallestStart; |
| 2630 | 2642 |
| 2631 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() | 2643 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() |
| 2632 : child.style()->gridRowStart(); | 2644 : child.style()->gridRowStart(); |
| 2633 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() | 2645 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() |
| 2634 : child.style()->gridRowEnd(); | 2646 : child.style()->gridRowEnd(); |
| 2635 int lastLine = numTracks(direction); | 2647 int lastLine = numTracks(direction, m_grid); |
| 2636 | 2648 |
| 2637 bool startIsAuto = | 2649 bool startIsAuto = |
| 2638 startPosition.isAuto() || | 2650 startPosition.isAuto() || |
| 2639 (startPosition.isNamedGridArea() && | 2651 (startPosition.isNamedGridArea() && |
| 2640 !NamedLineCollection::isValidNamedLineOrArea( | 2652 !NamedLineCollection::isValidNamedLineOrArea( |
| 2641 startPosition.namedGridLine(), styleRef(), | 2653 startPosition.namedGridLine(), styleRef(), |
| 2642 GridPositionsResolver::initialPositionSide(direction))) || | 2654 GridPositionsResolver::initialPositionSide(direction))) || |
| 2643 (startLine < 0) || (startLine > lastLine); | 2655 (startLine < 0) || (startLine > lastLine); |
| 2644 bool endIsAuto = endPosition.isAuto() || | 2656 bool endIsAuto = endPosition.isAuto() || |
| 2645 (endPosition.isNamedGridArea() && | 2657 (endPosition.isNamedGridArea() && |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3568 const LayoutPoint& paintOffset) const { | 3580 const LayoutPoint& paintOffset) const { |
| 3569 if (m_grid.hasGridItems()) | 3581 if (m_grid.hasGridItems()) |
| 3570 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 3582 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 3571 } | 3583 } |
| 3572 | 3584 |
| 3573 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { | 3585 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { |
| 3574 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); | 3586 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); |
| 3575 return m_hasDefiniteLogicalHeight.value(); | 3587 return m_hasDefiniteLogicalHeight.value(); |
| 3576 } | 3588 } |
| 3577 | 3589 |
| 3578 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { | 3590 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction, |
| 3591 const Grid& grid) const { |
| 3579 // Due to limitations in our internal representation, we cannot know the | 3592 // Due to limitations in our internal representation, we cannot know the |
| 3580 // number of columns from m_grid *if* there is no row (because m_grid would be | 3593 // number of columns from m_grid *if* there is no row (because m_grid would be |
| 3581 // empty). That's why in that case we need to get it from the style. Note that | 3594 // empty). That's why in that case we need to get it from the style. Note that |
| 3582 // we know for sure that there are't any implicit tracks, because not having | 3595 // we know for sure that there are't any implicit tracks, because not having |
| 3583 // rows implies that there are no "normal" children (out-of-flow children are | 3596 // rows implies that there are no "normal" children (out-of-flow children are |
| 3584 // not stored in m_grid). | 3597 // not stored in m_grid). |
| 3585 if (direction == ForRows) | 3598 if (direction == ForRows) |
| 3586 return m_grid.numTracks(ForRows); | 3599 return grid.numTracks(ForRows); |
| 3587 | 3600 |
| 3588 return m_grid.numTracks(ForRows) | 3601 return grid.numTracks(ForRows) |
| 3589 ? m_grid.numTracks(ForColumns) | 3602 ? grid.numTracks(ForColumns) |
| 3590 : GridPositionsResolver::explicitGridColumnCount( | 3603 : GridPositionsResolver::explicitGridColumnCount( |
| 3591 styleRef(), m_grid.autoRepeatTracks(ForColumns)); | 3604 styleRef(), grid.autoRepeatTracks(ForColumns)); |
| 3592 } | 3605 } |
| 3593 | 3606 |
| 3594 } // namespace blink | 3607 } // namespace blink |
| OLD | NEW |