Chromium Code Reviews| 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 } else { | 540 } else { |
| 541 for (const auto& trackIndex : flexibleSizedTracksIndex) | 541 for (const auto& trackIndex : flexibleSizedTracksIndex) |
| 542 flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[ trackIndex], gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); | 542 flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[ trackIndex], gridTrackSize(direction, trackIndex).maxTrackBreadth().flex())); |
| 543 | 543 |
| 544 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 544 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
| 545 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); | 545 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); |
| 546 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 546 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 547 const GridSpan span = cachedGridSpan(*gridItem, direction); | 547 const GridSpan span = cachedGridSpan(*gridItem, direction); |
| 548 | 548 |
| 549 // Do not include already processed items. | 549 // Do not include already processed items. |
| 550 if (i > 0 && span.resolvedInitialPosition().toInt() <= flexibleS izedTracksIndex[i - 1]) | 550 if (i > 0 && span.resolvedInitialPosition() <= flexibleSizedTrac ksIndex[i - 1]) |
| 551 continue; | 551 continue; |
| 552 | 552 |
| 553 flexFraction = std::max(flexFraction, findFlexFactorUnitSize(tra cks, span, direction, maxContentForChild(*gridItem, direction, sizingData.column Tracks))); | 553 flexFraction = std::max(flexFraction, findFlexFactorUnitSize(tra cks, span, direction, maxContentForChild(*gridItem, direction, sizingData.column Tracks))); |
| 554 } | 554 } |
| 555 } | 555 } |
| 556 } | 556 } |
| 557 | 557 |
| 558 for (const auto& trackIndex : flexibleSizedTracksIndex) { | 558 for (const auto& trackIndex : flexibleSizedTracksIndex) { |
| 559 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 559 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
| 560 | 560 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 return hypotheticalFactorUnitSize; | 624 return hypotheticalFactorUnitSize; |
| 625 } | 625 } |
| 626 | 626 |
| 627 double LayoutGrid::findFlexFactorUnitSize(const Vector<GridTrack>& tracks, const GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit leftOverSp ace) const | 627 double LayoutGrid::findFlexFactorUnitSize(const Vector<GridTrack>& tracks, const GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit leftOverSp ace) const |
| 628 { | 628 { |
| 629 if (leftOverSpace <= 0) | 629 if (leftOverSpace <= 0) |
| 630 return 0; | 630 return 0; |
| 631 | 631 |
| 632 double flexFactorSum = 0; | 632 double flexFactorSum = 0; |
| 633 Vector<size_t, 8> flexibleTracksIndexes; | 633 Vector<size_t, 8> flexibleTracksIndexes; |
| 634 for (const auto& resolvedPosition : tracksSpan) { | 634 for (const auto& trackIndex : tracksSpan) { |
| 635 size_t trackIndex = resolvedPosition.toInt(); | |
| 636 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 635 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
| 637 if (!trackSize.maxTrackBreadth().isFlex()) { | 636 if (!trackSize.maxTrackBreadth().isFlex()) { |
| 638 leftOverSpace -= tracks[trackIndex].baseSize(); | 637 leftOverSpace -= tracks[trackIndex].baseSize(); |
| 639 } else { | 638 } else { |
| 640 flexibleTracksIndexes.append(trackIndex); | 639 flexibleTracksIndexes.append(trackIndex); |
| 641 flexFactorSum += trackSize.maxTrackBreadth().flex(); | 640 flexFactorSum += trackSize.maxTrackBreadth().flex(); |
| 642 } | 641 } |
| 643 } | 642 } |
| 644 | 643 |
| 645 // The function is not called if we don't have <flex> grid tracks | 644 // The function is not called if we don't have <flex> grid tracks |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); } | 777 bool operator<(const GridItemWithSpan other) const { return m_gridSpan.integ erSpan() < other.m_gridSpan.integerSpan(); } |
| 779 | 778 |
| 780 private: | 779 private: |
| 781 LayoutBox* m_gridItem; | 780 LayoutBox* m_gridItem; |
| 782 GridSpan m_gridSpan; | 781 GridSpan m_gridSpan; |
| 783 }; | 782 }; |
| 784 | 783 |
| 785 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan& span, Gr idTrackSizingDirection direction) const | 784 bool LayoutGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan& span, Gr idTrackSizingDirection direction) const |
| 786 { | 785 { |
| 787 for (const auto& trackPosition : span) { | 786 for (const auto& trackPosition : span) { |
| 788 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition. toInt()); | 787 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition) ; |
| 789 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()) | 788 if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth(). isFlex()) |
| 790 return true; | 789 return true; |
| 791 } | 790 } |
| 792 | 791 |
| 793 return false; | 792 return false; |
| 794 } | 793 } |
| 795 | 794 |
| 796 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) | 795 void LayoutGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData) |
| 797 { | 796 { |
| 798 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 797 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 827 | 826 |
| 828 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 827 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 829 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; | 828 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; |
| 830 if (track.growthLimitIsInfinite()) | 829 if (track.growthLimitIsInfinite()) |
| 831 track.setGrowthLimit(track.baseSize()); | 830 track.setGrowthLimit(track.baseSize()); |
| 832 } | 831 } |
| 833 } | 832 } |
| 834 | 833 |
| 835 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, Vector<GridTrack>& columnTracks) | 834 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, Vector<GridTrack>& columnTracks) |
| 836 { | 835 { |
| 837 const GridResolvedPosition trackPosition = span.resolvedInitialPosition(); | 836 const size_t trackPosition = span.resolvedInitialPosition(); |
| 838 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); | 837 GridTrackSize trackSize = gridTrackSize(direction, trackPosition); |
| 839 | 838 |
| 840 if (trackSize.hasMinContentMinTrackBreadth()) | 839 if (trackSize.hasMinContentMinTrackBreadth()) |
| 841 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, columnTracks))); | 840 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, columnTracks))); |
| 842 else if (trackSize.hasMaxContentMinTrackBreadth()) | 841 else if (trackSize.hasMaxContentMinTrackBreadth()) |
| 843 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, columnTracks))); | 842 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, columnTracks))); |
| 844 else if (trackSize.hasAutoMinTrackBreadth()) | 843 else if (trackSize.hasAutoMinTrackBreadth()) |
| 845 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, columnTracks))); | 844 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, columnTracks))); |
| 846 | 845 |
| 847 if (trackSize.hasMinContentMaxTrackBreadth()) | 846 if (trackSize.hasMinContentMaxTrackBreadth()) |
| 848 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, columnTracks))); | 847 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, columnTracks))); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 | 985 |
| 987 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { | 986 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { |
| 988 GridItemWithSpan& gridItemWithSpan = *it; | 987 GridItemWithSpan& gridItemWithSpan = *it; |
| 989 ASSERT(gridItemWithSpan.gridSpan().integerSpan() > 1); | 988 ASSERT(gridItemWithSpan.gridSpan().integerSpan() > 1); |
| 990 const GridSpan& itemSpan = gridItemWithSpan.gridSpan(); | 989 const GridSpan& itemSpan = gridItemWithSpan.gridSpan(); |
| 991 | 990 |
| 992 sizingData.growBeyondGrowthLimitsTracks.shrink(0); | 991 sizingData.growBeyondGrowthLimitsTracks.shrink(0); |
| 993 sizingData.filteredTracks.shrink(0); | 992 sizingData.filteredTracks.shrink(0); |
| 994 LayoutUnit spanningTracksSize; | 993 LayoutUnit spanningTracksSize; |
| 995 for (const auto& trackPosition : itemSpan) { | 994 for (const auto& trackPosition : itemSpan) { |
| 996 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toI nt()); | 995 GridTrackSize trackSize = gridTrackSize(direction, trackPosition); |
| 997 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; | 996 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition] : sizingData.rowTracks[trackPosition]; |
| 998 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); | 997 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); |
| 999 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) | 998 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) |
| 1000 continue; | 999 continue; |
| 1001 | 1000 |
| 1002 sizingData.filteredTracks.append(&track); | 1001 sizingData.filteredTracks.append(&track); |
| 1003 | 1002 |
| 1004 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) | 1003 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) |
| 1005 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 1004 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
| 1006 } | 1005 } |
| 1007 | 1006 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 | 1098 |
| 1100 if (maximumColumnSize > gridColumnCount()) { | 1099 if (maximumColumnSize > gridColumnCount()) { |
| 1101 for (size_t row = 0; row < gridRowCount(); ++row) | 1100 for (size_t row = 0; row < gridRowCount(); ++row) |
| 1102 m_grid[row].grow(maximumColumnSize); | 1101 m_grid[row].grow(maximumColumnSize); |
| 1103 } | 1102 } |
| 1104 } | 1103 } |
| 1105 | 1104 |
| 1106 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor dinate) | 1105 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor dinate) |
| 1107 { | 1106 { |
| 1108 RELEASE_ASSERT(coordinate.rows.isDefinite() && coordinate.columns.isDefinite ()); | 1107 RELEASE_ASSERT(coordinate.rows.isDefinite() && coordinate.columns.isDefinite ()); |
| 1109 ensureGridSize(coordinate.rows.resolvedFinalPosition().toInt(), coordinate.c olumns.resolvedFinalPosition().toInt()); | 1108 ensureGridSize(coordinate.rows.resolvedFinalPosition(), coordinate.columns.r esolvedFinalPosition()); |
| 1110 | 1109 |
| 1111 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row s.end(); ++row) { | 1110 for (const auto& row : coordinate.rows) { |
| 1112 for (GridSpan::iterator column = coordinate.columns.begin(); column != c oordinate.columns.end(); ++column) | 1111 for (const auto& column: coordinate.columns) |
| 1113 m_grid[row.toInt()][column.toInt()].append(&child); | 1112 m_grid[row][column].append(&child); |
| 1114 } | 1113 } |
| 1115 } | 1114 } |
| 1116 | 1115 |
| 1117 void LayoutGrid::placeItemsOnGrid() | 1116 void LayoutGrid::placeItemsOnGrid() |
| 1118 { | 1117 { |
| 1119 if (!m_gridIsDirty) | 1118 if (!m_gridIsDirty) |
| 1120 return; | 1119 return; |
| 1121 | 1120 |
| 1122 ASSERT(m_gridItemCoordinate.isEmpty()); | 1121 ASSERT(m_gridItemCoordinate.isEmpty()); |
| 1123 | 1122 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1179 populator.collectChild(child); | 1178 populator.collectChild(child); |
| 1180 m_gridItemsIndexesMap.set(child, childIndex++); | 1179 m_gridItemsIndexesMap.set(child, childIndex++); |
| 1181 | 1180 |
| 1182 // This function bypasses the cache (cachedGridCoordinate()) as it is us ed to build it. | 1181 // This function bypasses the cache (cachedGridCoordinate()) as it is us ed to build it. |
| 1183 GridSpan rowPositions = GridResolvedPosition::resolveGridPositionsFromSt yle(*style(), *child, ForRows); | 1182 GridSpan rowPositions = GridResolvedPosition::resolveGridPositionsFromSt yle(*style(), *child, ForRows); |
| 1184 GridSpan columnPositions = GridResolvedPosition::resolveGridPositionsFro mStyle(*style(), *child, ForColumns); | 1183 GridSpan columnPositions = GridResolvedPosition::resolveGridPositionsFro mStyle(*style(), *child, ForColumns); |
| 1185 m_gridItemCoordinate.set(child, GridCoordinate(rowPositions, columnPosit ions)); | 1184 m_gridItemCoordinate.set(child, GridCoordinate(rowPositions, columnPosit ions)); |
| 1186 | 1185 |
| 1187 // |positions| is 0 if we need to run the auto-placement algorithm. | 1186 // |positions| is 0 if we need to run the auto-placement algorithm. |
| 1188 if (rowPositions.isDefinite()) { | 1187 if (rowPositions.isDefinite()) { |
| 1189 maximumRowIndex = std::max<size_t>(maximumRowIndex, rowPositions.res olvedFinalPosition().toInt()); | 1188 maximumRowIndex = std::max<size_t>(maximumRowIndex, rowPositions.res olvedFinalPosition()); |
| 1190 } else { | 1189 } else { |
| 1191 // Grow the grid for items with a definite row span, getting the lar gest such span. | 1190 // Grow the grid for items with a definite row span, getting the lar gest such span. |
| 1192 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA utoPlacementPosition(*style(), *child, ForRows, GridResolvedPosition(0)); | 1191 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA utoPlacementPosition(*style(), *child, ForRows, 0); |
| 1193 maximumRowIndex = std::max<size_t>(maximumRowIndex, positions.resolv edFinalPosition().toInt()); | 1192 maximumRowIndex = std::max<size_t>(maximumRowIndex, positions.resolv edFinalPosition()); |
| 1194 } | 1193 } |
| 1195 | 1194 |
| 1196 if (columnPositions.isDefinite()) { | 1195 if (columnPositions.isDefinite()) { |
| 1197 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, columnPosi tions.resolvedFinalPosition().toInt()); | 1196 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, columnPosi tions.resolvedFinalPosition()); |
| 1198 } else { | 1197 } else { |
| 1199 // Grow the grid for items with a definite column span, getting the largest such span. | 1198 // Grow the grid for items with a definite column span, getting the largest such span. |
| 1200 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA utoPlacementPosition(*style(), *child, ForColumns, GridResolvedPosition(0)); | 1199 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA utoPlacementPosition(*style(), *child, ForColumns, 0); |
| 1201 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions. resolvedFinalPosition().toInt()); | 1200 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions. resolvedFinalPosition()); |
| 1202 } | 1201 } |
| 1203 } | 1202 } |
| 1204 | 1203 |
| 1205 m_grid.grow(maximumRowIndex); | 1204 m_grid.grow(maximumRowIndex); |
| 1206 for (auto& column : m_grid) | 1205 for (auto& column : m_grid) |
| 1207 column.grow(maximumColumnIndex); | 1206 column.grow(maximumColumnIndex); |
| 1208 } | 1207 } |
| 1209 | 1208 |
| 1210 PassOwnPtr<GridCoordinate> LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOu tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection , const GridSpan& specifiedPositions) const | 1209 PassOwnPtr<GridCoordinate> LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOu tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection , const GridSpan& specifiedPositions) const |
| 1211 { | 1210 { |
| 1212 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ? ForRows : ForColumns; | 1211 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ? ForRows : ForColumns; |
| 1213 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn Count() : gridRowCount(); | 1212 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn Count() : gridRowCount(); |
| 1214 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition sFromAutoPlacementPosition(*style(), gridItem, crossDirection, GridResolvedPosit ion(endOfCrossDirection)); | 1213 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition sFromAutoPlacementPosition(*style(), gridItem, crossDirection, endOfCrossDirecti on); |
| 1215 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci fiedPositions : crossDirectionPositions)); | 1214 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci fiedPositions : crossDirectionPositions)); |
| 1216 } | 1215 } |
| 1217 | 1216 |
| 1218 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au toGridItems) | 1217 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au toGridItems) |
| 1219 { | 1218 { |
| 1220 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; | 1219 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; |
| 1221 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 1220 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 1222 | 1221 |
| 1223 // Mapping between the major axis tracks (rows or columns) and the last auto -placed item's position inserted on | 1222 // Mapping between the major axis tracks (rows or columns) and the last auto -placed item's position inserted on |
| 1224 // that track. This is needed to implement "sparse" packing for items locked to a given track. | 1223 // that track. This is needed to implement "sparse" packing for items locked to a given track. |
| 1225 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo | 1224 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo |
| 1226 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe roKeyHashTraits<unsigned>> minorAxisCursors; | 1225 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe roKeyHashTraits<unsigned>> minorAxisCursors; |
| 1227 | 1226 |
| 1228 for (const auto& autoGridItem : autoGridItems) { | 1227 for (const auto& autoGridItem : autoGridItems) { |
| 1229 GridSpan majorAxisPositions = cachedGridSpan(*autoGridItem, autoPlacemen tMajorAxisDirection()); | 1228 GridSpan majorAxisPositions = cachedGridSpan(*autoGridItem, autoPlacemen tMajorAxisDirection()); |
| 1230 ASSERT(majorAxisPositions.isDefinite()); | 1229 ASSERT(majorAxisPositions.isDefinite()); |
| 1231 ASSERT(!cachedGridSpan(*autoGridItem, autoPlacementMinorAxisDirection()) .isDefinite()); | 1230 ASSERT(!cachedGridSpan(*autoGridItem, autoPlacementMinorAxisDirection()) .isDefinite()); |
| 1232 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti on(), GridResolvedPosition(0)); | 1231 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti on(), 0); |
| 1233 unsigned majorAxisInitialPosition = majorAxisPositions.resolvedInitialPo sition().toInt(); | 1232 unsigned majorAxisInitialPosition = majorAxisPositions.resolvedInitialPo sition(); |
| 1234 | 1233 |
| 1235 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions.resolvedInitialPosition().toInt(), isGridAutoFlowDense ? 0 : minorAx isCursors.get(majorAxisInitialPosition)); | 1234 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions.resolvedInitialPosition(), isGridAutoFlowDense ? 0 : minorAxisCursor s.get(majorAxisInitialPosition)); |
| 1236 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA xisPositions.integerSpan(), minorAxisPositions.integerSpan()); | 1235 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA xisPositions.integerSpan(), minorAxisPositions.integerSpan()); |
| 1237 if (!emptyGridArea) | 1236 if (!emptyGridArea) |
| 1238 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(* autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); | 1237 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(* autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); |
| 1239 | 1238 |
| 1240 m_gridItemCoordinate.set(autoGridItem, *emptyGridArea); | 1239 m_gridItemCoordinate.set(autoGridItem, *emptyGridArea); |
| 1241 insertItemIntoGrid(*autoGridItem, *emptyGridArea); | 1240 insertItemIntoGrid(*autoGridItem, *emptyGridArea); |
| 1242 | 1241 |
| 1243 if (!isGridAutoFlowDense) | 1242 if (!isGridAutoFlowDense) |
| 1244 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG ridArea->rows.resolvedInitialPosition().toInt() : emptyGridArea->columns.resolve dInitialPosition().toInt()); | 1243 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG ridArea->rows.resolvedInitialPosition() : emptyGridArea->columns.resolvedInitial Position()); |
| 1245 } | 1244 } |
| 1246 } | 1245 } |
| 1247 | 1246 |
| 1248 void LayoutGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri dItems) | 1247 void LayoutGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri dItems) |
| 1249 { | 1248 { |
| 1250 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); | 1249 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); |
| 1251 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 1250 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 1252 | 1251 |
| 1253 for (const auto& autoGridItem : autoGridItems) { | 1252 for (const auto& autoGridItem : autoGridItems) { |
| 1254 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); | 1253 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); |
| 1255 | 1254 |
| 1256 // If grid-auto-flow is dense, reset auto-placement cursor. | 1255 // If grid-auto-flow is dense, reset auto-placement cursor. |
| 1257 if (isGridAutoFlowDense) { | 1256 if (isGridAutoFlowDense) { |
| 1258 autoPlacementCursor.first = 0; | 1257 autoPlacementCursor.first = 0; |
| 1259 autoPlacementCursor.second = 0; | 1258 autoPlacementCursor.second = 0; |
| 1260 } | 1259 } |
| 1261 } | 1260 } |
| 1262 } | 1261 } |
| 1263 | 1262 |
| 1264 void LayoutGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz e_t, size_t>& autoPlacementCursor) | 1263 void LayoutGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz e_t, size_t>& autoPlacementCursor) |
| 1265 { | 1264 { |
| 1266 GridSpan minorAxisPositions = cachedGridSpan(gridItem, autoPlacementMinorAxi sDirection()); | 1265 GridSpan minorAxisPositions = cachedGridSpan(gridItem, autoPlacementMinorAxi sDirection()); |
| 1267 ASSERT(!cachedGridSpan(gridItem, autoPlacementMajorAxisDirection()).isDefini te()); | 1266 ASSERT(!cachedGridSpan(gridItem, autoPlacementMajorAxisDirection()).isDefini te()); |
| 1268 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), Gri dResolvedPosition(0)); | 1267 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), 0); |
| 1269 | 1268 |
| 1270 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum ns) ? gridColumnCount() : gridRowCount(); | 1269 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum ns) ? gridColumnCount() : gridRowCount(); |
| 1271 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; | 1270 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; |
| 1272 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; | 1271 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; |
| 1273 | 1272 |
| 1274 OwnPtr<GridCoordinate> emptyGridArea; | 1273 OwnPtr<GridCoordinate> emptyGridArea; |
| 1275 if (minorAxisPositions.isDefinite()) { | 1274 if (minorAxisPositions.isDefinite()) { |
| 1276 // Move to the next track in major axis if initial position in minor axi s is before auto-placement cursor. | 1275 // Move to the next track in major axis if initial position in minor axi s is before auto-placement cursor. |
| 1277 if (minorAxisPositions.resolvedInitialPosition().toInt() < minorAxisAuto PlacementCursor) | 1276 if (minorAxisPositions.resolvedInitialPosition() < minorAxisAutoPlacemen tCursor) |
| 1278 majorAxisAutoPlacementCursor++; | 1277 majorAxisAutoPlacementCursor++; |
| 1279 | 1278 |
| 1280 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { | 1279 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { |
| 1281 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), min orAxisPositions.resolvedInitialPosition().toInt(), majorAxisAutoPlacementCursor) ; | 1280 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), min orAxisPositions.resolvedInitialPosition(), majorAxisAutoPlacementCursor); |
| 1282 emptyGridArea = iterator.nextEmptyGridArea(minorAxisPositions.intege rSpan(), majorAxisPositions.integerSpan()); | 1281 emptyGridArea = iterator.nextEmptyGridArea(minorAxisPositions.intege rSpan(), majorAxisPositions.integerSpan()); |
| 1283 } | 1282 } |
| 1284 | 1283 |
| 1285 if (!emptyGridArea) | 1284 if (!emptyGridArea) |
| 1286 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); | 1285 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); |
| 1287 } else { | 1286 } else { |
| 1288 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions FromAutoPlacementPosition(*style(), gridItem, autoPlacementMinorAxisDirection(), GridResolvedPosition(0)); | 1287 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions FromAutoPlacementPosition(*style(), gridItem, autoPlacementMinorAxisDirection(), 0); |
| 1289 | 1288 |
| 1290 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; majorAxisInde x < endOfMajorAxis; ++majorAxisIndex) { | 1289 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; majorAxisInde x < endOfMajorAxis; ++majorAxisIndex) { |
| 1291 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex, minorAxisAutoPlacementCursor); | 1290 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj orAxisIndex, minorAxisAutoPlacementCursor); |
| 1292 emptyGridArea = iterator.nextEmptyGridArea(majorAxisPositions.intege rSpan(), minorAxisPositions.integerSpan()); | 1291 emptyGridArea = iterator.nextEmptyGridArea(majorAxisPositions.intege rSpan(), minorAxisPositions.integerSpan()); |
| 1293 | 1292 |
| 1294 if (emptyGridArea) { | 1293 if (emptyGridArea) { |
| 1295 // Check that it fits in the minor axis direction, as we shouldn 't grow in that direction here (it was already managed in populateExplicitGridAn dOrderIterator()). | 1294 // Check that it fits in the minor axis direction, as we shouldn 't grow in that direction here (it was already managed in populateExplicitGridAn dOrderIterator()). |
| 1296 GridResolvedPosition minorAxisFinalPositionIndex = autoPlacement MinorAxisDirection() == ForColumns ? emptyGridArea->columns.resolvedFinalPositio n() : emptyGridArea->rows.resolvedFinalPosition(); | 1295 size_t minorAxisFinalPositionIndex = autoPlacementMinorAxisDirec tion() == ForColumns ? emptyGridArea->columns.resolvedFinalPosition() : emptyGri dArea->rows.resolvedFinalPosition(); |
| 1297 const size_t endOfMinorAxis = autoPlacementMinorAxisDirection() == ForColumns ? gridColumnCount() : gridRowCount(); | 1296 const size_t endOfMinorAxis = autoPlacementMinorAxisDirection() == ForColumns ? gridColumnCount() : gridRowCount(); |
| 1298 if (minorAxisFinalPositionIndex.toInt() <= endOfMinorAxis) | 1297 if (minorAxisFinalPositionIndex <= endOfMinorAxis) |
| 1299 break; | 1298 break; |
| 1300 | 1299 |
| 1301 // Discard empty grid area as it does not fit in the minor axis direction. | 1300 // Discard empty grid area as it does not fit in the minor axis direction. |
| 1302 // We don't need to create a new empty grid area yet as we might find a valid one in the next iteration. | 1301 // We don't need to create a new empty grid area yet as we might find a valid one in the next iteration. |
| 1303 emptyGridArea = nullptr; | 1302 emptyGridArea = nullptr; |
| 1304 } | 1303 } |
| 1305 | 1304 |
| 1306 // As we're moving to the next track in the major axis we should res et the auto-placement cursor in the minor axis. | 1305 // As we're moving to the next track in the major axis we should res et the auto-placement cursor in the minor axis. |
| 1307 minorAxisAutoPlacementCursor = 0; | 1306 minorAxisAutoPlacementCursor = 0; |
| 1308 } | 1307 } |
| 1309 | 1308 |
| 1310 if (!emptyGridArea) | 1309 if (!emptyGridArea) |
| 1311 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); | 1310 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); |
| 1312 } | 1311 } |
| 1313 | 1312 |
| 1314 m_gridItemCoordinate.set(&gridItem, *emptyGridArea); | 1313 m_gridItemCoordinate.set(&gridItem, *emptyGridArea); |
| 1315 insertItemIntoGrid(gridItem, *emptyGridArea); | 1314 insertItemIntoGrid(gridItem, *emptyGridArea); |
| 1316 // Move auto-placement cursor to the new position. | 1315 // Move auto-placement cursor to the new position. |
| 1317 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition().to Int(); | 1316 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition(); |
| 1318 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition( ).toInt(); | 1317 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition( ); |
| 1319 } | 1318 } |
| 1320 | 1319 |
| 1321 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const | 1320 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const |
| 1322 { | 1321 { |
| 1323 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 1322 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 1324 } | 1323 } |
| 1325 | 1324 |
| 1326 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const | 1325 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const |
| 1327 { | 1326 { |
| 1328 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 1327 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1411 applyStretchAlignmentToChildIfNeeded(*child); | 1410 applyStretchAlignmentToChildIfNeeded(*child); |
| 1412 | 1411 |
| 1413 child->layoutIfNeeded(); | 1412 child->layoutIfNeeded(); |
| 1414 | 1413 |
| 1415 // We need pending layouts to be done in order to compute auto-margins p roperly. | 1414 // We need pending layouts to be done in order to compute auto-margins p roperly. |
| 1416 updateAutoMarginsInColumnAxisIfNeeded(*child); | 1415 updateAutoMarginsInColumnAxisIfNeeded(*child); |
| 1417 updateAutoMarginsInRowAxisIfNeeded(*child); | 1416 updateAutoMarginsInRowAxisIfNeeded(*child); |
| 1418 | 1417 |
| 1419 #if ENABLE(ASSERT) | 1418 #if ENABLE(ASSERT) |
| 1420 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1419 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
| 1421 ASSERT(coordinate.columns.resolvedInitialPosition().toInt() < sizingData .columnTracks.size()); | 1420 ASSERT(coordinate.columns.resolvedInitialPosition() < sizingData.columnT racks.size()); |
| 1422 ASSERT(coordinate.rows.resolvedInitialPosition().toInt() < sizingData.ro wTracks.size()); | 1421 ASSERT(coordinate.rows.resolvedInitialPosition() < sizingData.rowTracks. size()); |
| 1423 #endif | 1422 #endif |
| 1424 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1423 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
| 1425 | 1424 |
| 1426 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is | 1425 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is |
| 1427 // not visible | 1426 // not visible |
| 1428 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1427 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
| 1429 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h) | 1428 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h) |
| 1430 m_gridItemsOverflowingGridArea.append(child); | 1429 m_gridItemsOverflowingGridArea.append(child); |
| 1431 } | 1430 } |
| 1432 } | 1431 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1479 if (!positions.isDefinite()) { | 1478 if (!positions.isDefinite()) { |
| 1480 offset = LayoutUnit(); | 1479 offset = LayoutUnit(); |
| 1481 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic alHeight(); | 1480 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic alHeight(); |
| 1482 return; | 1481 return; |
| 1483 } | 1482 } |
| 1484 | 1483 |
| 1485 GridPosition startPosition = (direction == ForColumns) ? child.style()->grid ColumnStart() : child.style()->gridRowStart(); | 1484 GridPosition startPosition = (direction == ForColumns) ? child.style()->grid ColumnStart() : child.style()->gridRowStart(); |
| 1486 GridPosition endPosition = (direction == ForColumns) ? child.style()->gridCo lumnEnd() : child.style()->gridRowEnd(); | 1485 GridPosition endPosition = (direction == ForColumns) ? child.style()->gridCo lumnEnd() : child.style()->gridRowEnd(); |
| 1487 size_t lastTrackIndex = (direction == ForColumns ? gridColumnCount() : gridR owCount()) - 1; | 1486 size_t lastTrackIndex = (direction == ForColumns ? gridColumnCount() : gridR owCount()) - 1; |
| 1488 | 1487 |
| 1488 // TODO(rego): We could simply subtract 1 once we store integers in GridSpan . | |
| 1489 size_t previousFinalPosition = positions.resolvedFinalPosition() ? positions .resolvedFinalPosition() - 1 : 0; | |
| 1489 bool startIsAuto = startPosition.isAuto() | 1490 bool startIsAuto = startPosition.isAuto() |
| 1490 || (startPosition.isNamedGridArea() && !GridResolvedPosition::isValidNam edLineOrArea(startPosition.namedGridLine(), styleRef(), GridResolvedPosition::in itialPositionSide(direction))) | 1491 || (startPosition.isNamedGridArea() && !GridResolvedPosition::isValidNam edLineOrArea(startPosition.namedGridLine(), styleRef(), GridResolvedPosition::in itialPositionSide(direction))) |
| 1491 || (positions.resolvedInitialPosition().toInt() > lastTrackIndex); | 1492 || (positions.resolvedInitialPosition() > lastTrackIndex); |
| 1492 bool endIsAuto = endPosition.isAuto() | 1493 bool endIsAuto = endPosition.isAuto() |
| 1493 || (endPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamed LineOrArea(endPosition.namedGridLine(), styleRef(), GridResolvedPosition::finalP ositionSide(direction))) | 1494 || (endPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamed LineOrArea(endPosition.namedGridLine(), styleRef(), GridResolvedPosition::finalP ositionSide(direction))) |
| 1494 || (positions.resolvedFinalPosition().prev().toInt() > lastTrackIndex); | 1495 || (previousFinalPosition > lastTrackIndex); |
| 1495 | 1496 |
| 1496 GridResolvedPosition firstPosition = GridResolvedPosition(0); | 1497 size_t firstPosition = 0; |
| 1497 GridResolvedPosition initialPosition = startIsAuto ? firstPosition : positio ns.resolvedInitialPosition(); | 1498 size_t initialPosition = startIsAuto ? firstPosition : positions.resolvedIni tialPosition(); |
| 1498 GridResolvedPosition lastPosition = GridResolvedPosition(lastTrackIndex); | 1499 size_t lastPosition = lastTrackIndex; |
| 1499 GridResolvedPosition finalPosition = endIsAuto ? lastPosition : positions.re solvedFinalPosition().prev(); | 1500 size_t finalPosition = endIsAuto ? lastPosition : previousFinalPosition; |
| 1500 | 1501 |
| 1501 // Positioned children do not grow the grid, so we need to clamp the positio ns to avoid ending up outside of it. | 1502 // Positioned children do not grow the grid, so we need to clamp the positio ns to avoid ending up outside of it. |
| 1502 initialPosition = std::min<GridResolvedPosition>(initialPosition, lastPositi on); | 1503 initialPosition = std::min(initialPosition, lastPosition); |
| 1503 finalPosition = std::min<GridResolvedPosition>(finalPosition, lastPosition); | 1504 finalPosition = std::min(finalPosition, lastPosition); |
| 1504 | 1505 |
| 1505 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ? m_columnPositions[initialPosition.toInt()] : m_rowPositions[initialPosition.toI nt()]; | 1506 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ? m_columnPositions[initialPosition] : m_rowPositions[initialPosition]; |
| 1506 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition.nex t().toInt()] : m_rowPositions[finalPosition.next().toInt()]; | 1507 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition + 1 ] : m_rowPositions[finalPosition + 1]; |
| 1507 | 1508 |
| 1508 breadth = end - start; | 1509 breadth = end - start; |
| 1509 | 1510 |
| 1510 if (startIsAuto) | 1511 if (startIsAuto) |
| 1511 breadth -= (direction == ForColumns) ? borderStart() : borderBefore(); | 1512 breadth -= (direction == ForColumns) ? borderStart() : borderBefore(); |
| 1512 else | 1513 else |
| 1513 start -= ((direction == ForColumns) ? borderStart() : borderBefore()); | 1514 start -= ((direction == ForColumns) ? borderStart() : borderBefore()); |
| 1514 | 1515 |
| 1515 if (endIsAuto) { | 1516 if (endIsAuto) { |
| 1516 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter(); | 1517 breadth -= (direction == ForColumns) ? borderEnd() : borderAfter(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1538 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const | 1539 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const |
| 1539 { | 1540 { |
| 1540 GridCoordinate coordinate = cachedGridCoordinate(gridItem); | 1541 GridCoordinate coordinate = cachedGridCoordinate(gridItem); |
| 1541 return direction == ForColumns ? coordinate.columns : coordinate.rows; | 1542 return direction == ForColumns ? coordinate.columns : coordinate.rows; |
| 1542 } | 1543 } |
| 1543 | 1544 |
| 1544 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const | 1545 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const |
| 1545 { | 1546 { |
| 1546 const GridSpan& span = cachedGridSpan(child, direction); | 1547 const GridSpan& span = cachedGridSpan(child, direction); |
| 1547 LayoutUnit gridAreaBreadth = 0; | 1548 LayoutUnit gridAreaBreadth = 0; |
| 1548 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) | 1549 for (const auto& trackPosition : span) |
| 1549 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); | 1550 gridAreaBreadth += tracks[trackPosition].baseSize(); |
| 1550 | 1551 |
| 1551 gridAreaBreadth += guttersSize(direction, span.integerSpan()); | 1552 gridAreaBreadth += guttersSize(direction, span.integerSpan()); |
| 1552 | 1553 |
| 1553 return gridAreaBreadth; | 1554 return gridAreaBreadth; |
| 1554 } | 1555 } |
| 1555 | 1556 |
| 1556 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const | 1557 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing Data) const |
| 1557 { | 1558 { |
| 1558 // We need the cached value when available because Content Distribution alig nment properties | 1559 // We need the cached value when available because Content Distribution alig nment properties |
| 1559 // may have some influence in the final grid area breadth. | 1560 // may have some influence in the final grid area breadth. |
| 1560 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; | 1561 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; |
| 1561 const GridSpan& span = cachedGridSpan(child, direction); | 1562 const GridSpan& span = cachedGridSpan(child, direction); |
| 1562 const Vector<LayoutUnit>& linePositions = (direction == ForColumns) ? m_colu mnPositions : m_rowPositions; | 1563 const Vector<LayoutUnit>& linePositions = (direction == ForColumns) ? m_colu mnPositions : m_rowPositions; |
| 1563 LayoutUnit initialTrackPosition = linePositions[span.resolvedInitialPosition ().toInt()]; | 1564 LayoutUnit initialTrackPosition = linePositions[span.resolvedInitialPosition ()]; |
| 1564 LayoutUnit finalTrackPosition = linePositions[span.resolvedFinalPosition().p rev().toInt()]; | 1565 size_t previousFinfalPosition = span.resolvedFinalPosition() ? span.resolved FinalPosition() - 1 : 0; |
|
rune
2015/12/03 09:36:49
Finfal?
| |
| 1566 LayoutUnit finalTrackPosition = linePositions[previousFinfalPosition]; | |
| 1565 // Track Positions vector stores the 'start' grid line of each track, so w h ave to add last track's baseSize. | 1567 // Track Positions vector stores the 'start' grid line of each track, so w h ave to add last track's baseSize. |
| 1566 return finalTrackPosition - initialTrackPosition + tracks[span.resolvedFinal Position().prev().toInt()].baseSize(); | 1568 return finalTrackPosition - initialTrackPosition + tracks[previousFinfalPosi tion].baseSize(); |
| 1567 } | 1569 } |
| 1568 | 1570 |
| 1569 void LayoutGrid::populateGridPositions(GridSizingData& sizingData) | 1571 void LayoutGrid::populateGridPositions(GridSizingData& sizingData) |
| 1570 { | 1572 { |
| 1571 // Since we add alignment offsets and track gutters, grid lines are not alwa ys adjacent. Hence we will have to | 1573 // Since we add alignment offsets and track gutters, grid lines are not alwa ys adjacent. Hence we will have to |
| 1572 // assume from now on that we just store positions of the initial grid lines of each track, | 1574 // assume from now on that we just store positions of the initial grid lines of each track, |
| 1573 // except the last one, which is the only one considered as a final grid lin e of a track. | 1575 // except the last one, which is the only one considered as a final grid lin e of a track. |
| 1574 // FIXME: This will affect the computed style value of grid tracks size, sin ce we are | 1576 // FIXME: This will affect the computed style value of grid tracks size, sin ce we are |
| 1575 // using these positions to compute them. | 1577 // using these positions to compute them. |
| 1576 | 1578 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1863 | 1865 |
| 1864 static inline LayoutUnit offsetBetweenTracks(ContentDistributionType distributio n, const Vector<LayoutUnit>& trackPositions, const LayoutUnit& childBreadth) | 1866 static inline LayoutUnit offsetBetweenTracks(ContentDistributionType distributio n, const Vector<LayoutUnit>& trackPositions, const LayoutUnit& childBreadth) |
| 1865 { | 1867 { |
| 1866 return (distribution == ContentDistributionStretch || ContentDistributionStr etch == ContentDistributionDefault) ? LayoutUnit() : trackPositions[1] - trackPo sitions[0] - childBreadth; | 1868 return (distribution == ContentDistributionStretch || ContentDistributionStr etch == ContentDistributionDefault) ? LayoutUnit() : trackPositions[1] - trackPo sitions[0] - childBreadth; |
| 1867 | 1869 |
| 1868 } | 1870 } |
| 1869 | 1871 |
| 1870 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child) const | 1872 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child) const |
| 1871 { | 1873 { |
| 1872 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); | 1874 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); |
| 1873 size_t childStartLine = rowsSpan.resolvedInitialPosition().toInt(); | 1875 size_t childStartLine = rowsSpan.resolvedInitialPosition(); |
| 1874 LayoutUnit startOfRow = m_rowPositions[childStartLine]; | 1876 LayoutUnit startOfRow = m_rowPositions[childStartLine]; |
| 1875 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); | 1877 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); |
| 1876 if (hasAutoMarginsInColumnAxis(child)) | 1878 if (hasAutoMarginsInColumnAxis(child)) |
| 1877 return startPosition; | 1879 return startPosition; |
| 1878 GridAxisPosition axisPosition = columnAxisPositionForChild(child); | 1880 GridAxisPosition axisPosition = columnAxisPositionForChild(child); |
| 1879 switch (axisPosition) { | 1881 switch (axisPosition) { |
| 1880 case GridAxisStart: | 1882 case GridAxisStart: |
| 1881 return startPosition; | 1883 return startPosition; |
| 1882 case GridAxisEnd: | 1884 case GridAxisEnd: |
| 1883 case GridAxisCenter: { | 1885 case GridAxisCenter: { |
| 1884 size_t childEndLine = rowsSpan.resolvedFinalPosition().toInt(); | 1886 size_t childEndLine = rowsSpan.resolvedFinalPosition(); |
| 1885 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 1887 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
| 1886 // m_rowPositions include gutters so we need to substract them to get th e actual end position for a given | 1888 // m_rowPositions include gutters so we need to substract them to get th e actual end position for a given |
| 1887 // row (this does not have to be done for the last track as there are no more m_rowPositions after it) | 1889 // row (this does not have to be done for the last track as there are no more m_rowPositions after it) |
| 1888 if (childEndLine < m_rowPositions.size() - 1) | 1890 if (childEndLine < m_rowPositions.size() - 1) |
| 1889 endOfRow -= guttersSize(ForRows, 2); | 1891 endOfRow -= guttersSize(ForRows, 2); |
| 1890 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); | 1892 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); |
| 1891 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s ize() - 1) | 1893 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s ize() - 1) |
| 1892 endOfRow -= offsetBetweenTracks(styleRef().alignContentDistribution( ), m_rowPositions, childBreadth); | 1894 endOfRow -= offsetBetweenTracks(styleRef().alignContentDistribution( ), m_rowPositions, childBreadth); |
| 1893 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().alignSelfOverflowAlignment(), endOfRow - startOfRow, childBreadth); | 1895 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().alignSelfOverflowAlignment(), endOfRow - startOfRow, childBreadth); |
| 1894 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); | 1896 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); |
| 1895 } | 1897 } |
| 1896 } | 1898 } |
| 1897 | 1899 |
| 1898 ASSERT_NOT_REACHED(); | 1900 ASSERT_NOT_REACHED(); |
| 1899 return 0; | 1901 return 0; |
| 1900 } | 1902 } |
| 1901 | 1903 |
| 1902 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child) const | 1904 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child) const |
| 1903 { | 1905 { |
| 1904 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); | 1906 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); |
| 1905 size_t childStartLine = columnsSpan.resolvedInitialPosition().toInt(); | 1907 size_t childStartLine = columnsSpan.resolvedInitialPosition(); |
| 1906 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; | 1908 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; |
| 1907 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); | 1909 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); |
| 1908 if (hasAutoMarginsInRowAxis(child)) | 1910 if (hasAutoMarginsInRowAxis(child)) |
| 1909 return startPosition; | 1911 return startPosition; |
| 1910 GridAxisPosition axisPosition = rowAxisPositionForChild(child); | 1912 GridAxisPosition axisPosition = rowAxisPositionForChild(child); |
| 1911 switch (axisPosition) { | 1913 switch (axisPosition) { |
| 1912 case GridAxisStart: | 1914 case GridAxisStart: |
| 1913 return startPosition; | 1915 return startPosition; |
| 1914 case GridAxisEnd: | 1916 case GridAxisEnd: |
| 1915 case GridAxisCenter: { | 1917 case GridAxisCenter: { |
| 1916 size_t childEndLine = columnsSpan.resolvedFinalPosition().toInt(); | 1918 size_t childEndLine = columnsSpan.resolvedFinalPosition(); |
| 1917 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 1919 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
| 1918 // m_columnPositions include gutters so we need to substract them to get the actual end position for a given | 1920 // m_columnPositions include gutters so we need to substract them to get the actual end position for a given |
| 1919 // column (this does not have to be done for the last track as there are no more m_columnPositions after it) | 1921 // column (this does not have to be done for the last track as there are no more m_columnPositions after it) |
| 1920 if (childEndLine < m_columnPositions.size() - 1) | 1922 if (childEndLine < m_columnPositions.size() - 1) |
| 1921 endOfColumn -= guttersSize(ForRows, 2); | 1923 endOfColumn -= guttersSize(ForRows, 2); |
| 1922 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); | 1924 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); |
| 1923 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition s.size() - 1) | 1925 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition s.size() - 1) |
| 1924 endOfColumn -= offsetBetweenTracks(styleRef().justifyContentDistribu tion(), m_columnPositions, childBreadth); | 1926 endOfColumn -= offsetBetweenTracks(styleRef().justifyContentDistribu tion(), m_columnPositions, childBreadth); |
| 1925 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); | 1927 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); |
| 1926 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); | 1928 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2057 | 2059 |
| 2058 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 2060 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); |
| 2059 } | 2061 } |
| 2060 | 2062 |
| 2061 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2063 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
| 2062 { | 2064 { |
| 2063 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2065 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2064 } | 2066 } |
| 2065 | 2067 |
| 2066 } // namespace blink | 2068 } // namespace blink |
| OLD | NEW |