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