| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 ASSERT(!m_grid.isEmpty()); | 202 ASSERT(!m_grid.isEmpty()); |
| 203 ASSERT(fixedTrackSpan >= 1 && varyingTrackSpan >= 1); | 203 ASSERT(fixedTrackSpan >= 1 && varyingTrackSpan >= 1); |
| 204 | 204 |
| 205 size_t rowSpan = (m_direction == ForColumns) ? varyingTrackSpan : fixedT
rackSpan; | 205 size_t rowSpan = (m_direction == ForColumns) ? varyingTrackSpan : fixedT
rackSpan; |
| 206 size_t columnSpan = (m_direction == ForColumns) ? fixedTrackSpan : varyi
ngTrackSpan; | 206 size_t columnSpan = (m_direction == ForColumns) ? fixedTrackSpan : varyi
ngTrackSpan; |
| 207 | 207 |
| 208 size_t& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m
_columnIndex; | 208 size_t& varyingTrackIndex = (m_direction == ForColumns) ? m_rowIndex : m
_columnIndex; |
| 209 const size_t endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_gr
id.size() : m_grid[0].size(); | 209 const size_t endOfVaryingTrackIndex = (m_direction == ForColumns) ? m_gr
id.size() : m_grid[0].size(); |
| 210 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex)
{ | 210 for (; varyingTrackIndex < endOfVaryingTrackIndex; ++varyingTrackIndex)
{ |
| 211 if (checkEmptyCells(rowSpan, columnSpan)) { | 211 if (checkEmptyCells(rowSpan, columnSpan)) { |
| 212 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate(Grid
Span(m_rowIndex, m_rowIndex + rowSpan), GridSpan(m_columnIndex, m_columnIndex +
columnSpan))); | 212 OwnPtr<GridCoordinate> result = adoptPtr(new GridCoordinate(Grid
Span::definiteGridSpan(m_rowIndex, m_rowIndex + rowSpan), GridSpan::definiteGrid
Span(m_columnIndex, m_columnIndex + columnSpan))); |
| 213 // Advance the iterator to avoid an infinite loop where we would
return the same grid area over and over. | 213 // Advance the iterator to avoid an infinite loop where we would
return the same grid area over and over. |
| 214 ++varyingTrackIndex; | 214 ++varyingTrackIndex; |
| 215 return result.release(); | 215 return result.release(); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 return nullptr; | 218 return nullptr; |
| 219 } | 219 } |
| 220 | 220 |
| 221 private: | 221 private: |
| 222 const GridRepresentation& m_grid; | 222 const GridRepresentation& m_grid; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 for (auto& track : tracks) | 529 for (auto& track : tracks) |
| 530 track.setBaseSize(track.growthLimit()); | 530 track.setBaseSize(track.growthLimit()); |
| 531 } | 531 } |
| 532 | 532 |
| 533 if (flexibleSizedTracksIndex.isEmpty()) | 533 if (flexibleSizedTracksIndex.isEmpty()) |
| 534 return; | 534 return; |
| 535 | 535 |
| 536 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. | 536 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. |
| 537 double flexFraction = 0; | 537 double flexFraction = 0; |
| 538 if (hasDefiniteFreeSpace) { | 538 if (hasDefiniteFreeSpace) { |
| 539 flexFraction = findFlexFactorUnitSize(tracks, GridSpan(0, tracks.size())
, direction, initialFreeSpace); | 539 flexFraction = findFlexFactorUnitSize(tracks, GridSpan::definiteGridSpan
(0, tracks.size()), direction, initialFreeSpace); |
| 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() <= flexibleSiz
edTracksIndex[i - 1]) | 550 if (i > 0 && span.resolvedInitialPosition().toInt() <= flexibleS
izedTracksIndex[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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 | 827 |
| 828 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 828 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 829 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; | 829 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; |
| 830 if (track.growthLimitIsInfinite()) | 830 if (track.growthLimitIsInfinite()) |
| 831 track.setGrowthLimit(track.baseSize()); | 831 track.setGrowthLimit(track.baseSize()); |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 | 834 |
| 835 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid
TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT
rack& track, Vector<GridTrack>& columnTracks) | 835 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid
TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT
rack& track, Vector<GridTrack>& columnTracks) |
| 836 { | 836 { |
| 837 const GridResolvedPosition trackPosition = span.resolvedInitialPosition; | 837 const GridResolvedPosition trackPosition = span.resolvedInitialPosition(); |
| 838 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); | 838 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); |
| 839 | 839 |
| 840 if (trackSize.hasMinContentMinTrackBreadth()) | 840 if (trackSize.hasMinContentMinTrackBreadth()) |
| 841 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem
, direction, columnTracks))); | 841 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem
, direction, columnTracks))); |
| 842 else if (trackSize.hasMaxContentMinTrackBreadth()) | 842 else if (trackSize.hasMaxContentMinTrackBreadth()) |
| 843 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem
, direction, columnTracks))); | 843 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem
, direction, columnTracks))); |
| 844 else if (trackSize.hasAutoMinTrackBreadth()) | 844 else if (trackSize.hasAutoMinTrackBreadth()) |
| 845 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d
irection, columnTracks))); | 845 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d
irection, columnTracks))); |
| 846 | 846 |
| 847 if (trackSize.hasMinContentMaxTrackBreadth()) | 847 if (trackSize.hasMinContentMaxTrackBreadth()) |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 if (maximumColumnSize > gridColumnCount()) { | 1100 if (maximumColumnSize > gridColumnCount()) { |
| 1101 for (size_t row = 0; row < gridRowCount(); ++row) | 1101 for (size_t row = 0; row < gridRowCount(); ++row) |
| 1102 m_grid[row].grow(maximumColumnSize); | 1102 m_grid[row].grow(maximumColumnSize); |
| 1103 } | 1103 } |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor
dinate) | 1106 void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridCoordinate& coor
dinate) |
| 1107 { | 1107 { |
| 1108 ensureGridSize(coordinate.rows.resolvedFinalPosition.toInt(), coordinate.col
umns.resolvedFinalPosition.toInt()); | 1108 ensureGridSize(coordinate.rows.resolvedFinalPosition().toInt(), coordinate.c
olumns.resolvedFinalPosition().toInt()); |
| 1109 | 1109 |
| 1110 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row
s.end(); ++row) { | 1110 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row
s.end(); ++row) { |
| 1111 for (GridSpan::iterator column = coordinate.columns.begin(); column != c
oordinate.columns.end(); ++column) | 1111 for (GridSpan::iterator column = coordinate.columns.begin(); column != c
oordinate.columns.end(); ++column) |
| 1112 m_grid[row.toInt()][column.toInt()].append(&child); | 1112 m_grid[row.toInt()][column.toInt()].append(&child); |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 RELEASE_ASSERT(!m_gridItemCoordinate.contains(&child)); | 1115 RELEASE_ASSERT(!m_gridItemCoordinate.contains(&child)); |
| 1116 m_gridItemCoordinate.set(&child, coordinate); | 1116 m_gridItemCoordinate.set(&child, coordinate); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 void LayoutGrid::placeItemsOnGrid() | 1119 void LayoutGrid::placeItemsOnGrid() |
| 1120 { | 1120 { |
| 1121 if (!m_gridIsDirty) | 1121 if (!m_gridIsDirty) |
| 1122 return; | 1122 return; |
| 1123 | 1123 |
| 1124 ASSERT(m_gridItemCoordinate.isEmpty()); | 1124 ASSERT(m_gridItemCoordinate.isEmpty()); |
| 1125 | 1125 |
| 1126 populateExplicitGridAndOrderIterator(); | 1126 populateExplicitGridAndOrderIterator(); |
| 1127 | 1127 |
| 1128 // We clear the dirty bit here as the grid sizes have been updated. | 1128 // We clear the dirty bit here as the grid sizes have been updated. |
| 1129 m_gridIsDirty = false; | 1129 m_gridIsDirty = false; |
| 1130 | 1130 |
| 1131 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 1131 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
| 1132 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 1132 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
| 1133 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 1133 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
| 1134 if (child->isOutOfFlowPositioned()) | 1134 if (child->isOutOfFlowPositioned()) |
| 1135 continue; | 1135 continue; |
| 1136 | 1136 |
| 1137 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositio
nsFromStyle(*style(), *child, ForRows); | 1137 GridSpan rowPositions = GridResolvedPosition::resolveGridPositionsFromSt
yle(*style(), *child, ForRows); |
| 1138 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosi
tionsFromStyle(*style(), *child, ForColumns); | 1138 GridSpan columnPositions = GridResolvedPosition::resolveGridPositionsFro
mStyle(*style(), *child, ForColumns); |
| 1139 if (!rowPositions || !columnPositions) { | 1139 if (!rowPositions.isDefinite() || !columnPositions.isDefinite()) { |
| 1140 GridSpan* majorAxisPositions = (autoPlacementMajorAxisDirection() ==
ForColumns) ? columnPositions.get() : rowPositions.get(); | 1140 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() ==
ForColumns) ? columnPositions : rowPositions; |
| 1141 if (!majorAxisPositions) | 1141 if (!majorAxisPositions.isDefinite()) |
| 1142 autoMajorAxisAutoGridItems.append(child); | 1142 autoMajorAxisAutoGridItems.append(child); |
| 1143 else | 1143 else |
| 1144 specifiedMajorAxisAutoGridItems.append(child); | 1144 specifiedMajorAxisAutoGridItems.append(child); |
| 1145 continue; | 1145 continue; |
| 1146 } | 1146 } |
| 1147 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPosition
s)); | 1147 insertItemIntoGrid(*child, GridCoordinate(rowPositions, columnPositions)
); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); | 1150 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); |
| 1151 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); | 1151 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); |
| 1152 | 1152 |
| 1153 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 1153 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 1154 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 1154 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 1155 | 1155 |
| 1156 m_grid.shrinkToFit(); | 1156 m_grid.shrinkToFit(); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 void LayoutGrid::populateExplicitGridAndOrderIterator() | 1159 void LayoutGrid::populateExplicitGridAndOrderIterator() |
| 1160 { | 1160 { |
| 1161 OrderIteratorPopulator populator(m_orderIterator); | 1161 OrderIteratorPopulator populator(m_orderIterator); |
| 1162 | 1162 |
| 1163 size_t maximumRowIndex = std::max<size_t>(1, GridResolvedPosition::explicitG
ridRowCount(*style())); | 1163 size_t maximumRowIndex = std::max<size_t>(1, GridResolvedPosition::explicitG
ridRowCount(*style())); |
| 1164 size_t maximumColumnIndex = std::max<size_t>(1, GridResolvedPosition::explic
itGridColumnCount(*style())); | 1164 size_t maximumColumnIndex = std::max<size_t>(1, GridResolvedPosition::explic
itGridColumnCount(*style())); |
| 1165 | 1165 |
| 1166 ASSERT(m_gridItemsIndexesMap.isEmpty()); | 1166 ASSERT(m_gridItemsIndexesMap.isEmpty()); |
| 1167 size_t childIndex = 0; | 1167 size_t childIndex = 0; |
| 1168 for (LayoutBox* child = firstChildBox(); child; child = child->nextInFlowSib
lingBox()) { | 1168 for (LayoutBox* child = firstChildBox(); child; child = child->nextInFlowSib
lingBox()) { |
| 1169 if (child->isOutOfFlowPositioned()) | 1169 if (child->isOutOfFlowPositioned()) |
| 1170 continue; | 1170 continue; |
| 1171 | 1171 |
| 1172 populator.collectChild(child); | 1172 populator.collectChild(child); |
| 1173 m_gridItemsIndexesMap.set(child, childIndex++); | 1173 m_gridItemsIndexesMap.set(child, childIndex++); |
| 1174 | 1174 |
| 1175 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. | 1175 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. |
| 1176 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositio
nsFromStyle(*style(), *child, ForRows); | 1176 GridSpan rowPositions = GridResolvedPosition::resolveGridPositionsFromSt
yle(*style(), *child, ForRows); |
| 1177 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosi
tionsFromStyle(*style(), *child, ForColumns); | 1177 GridSpan columnPositions = GridResolvedPosition::resolveGridPositionsFro
mStyle(*style(), *child, ForColumns); |
| 1178 | 1178 |
| 1179 // |positions| is 0 if we need to run the auto-placement algorithm. | 1179 // |positions| is 0 if we need to run the auto-placement algorithm. |
| 1180 if (rowPositions) { | 1180 if (rowPositions.isDefinite()) { |
| 1181 maximumRowIndex = std::max<size_t>(maximumRowIndex, rowPositions->re
solvedFinalPosition.toInt()); | 1181 maximumRowIndex = std::max<size_t>(maximumRowIndex, rowPositions.res
olvedFinalPosition().toInt()); |
| 1182 } else { | 1182 } else { |
| 1183 // Grow the grid for items with a definite row span, getting the lar
gest such span. | 1183 // Grow the grid for items with a definite row span, getting the lar
gest such span. |
| 1184 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForRows, GridResolvedPosition(0)); | 1184 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForRows, GridResolvedPosition(0)); |
| 1185 maximumRowIndex = std::max<size_t>(maximumRowIndex, positions.resolv
edFinalPosition.toInt()); | 1185 maximumRowIndex = std::max<size_t>(maximumRowIndex, positions.resolv
edFinalPosition().toInt()); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 if (columnPositions) { | 1188 if (columnPositions.isDefinite()) { |
| 1189 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, columnPosi
tions->resolvedFinalPosition.toInt()); | 1189 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, columnPosi
tions.resolvedFinalPosition().toInt()); |
| 1190 } else { | 1190 } else { |
| 1191 // Grow the grid for items with a definite column span, getting the
largest such span. | 1191 // Grow the grid for items with a definite column span, getting the
largest such span. |
| 1192 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForColumns, GridResolvedPosition(0)); | 1192 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromA
utoPlacementPosition(*style(), *child, ForColumns, GridResolvedPosition(0)); |
| 1193 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions.
resolvedFinalPosition.toInt()); | 1193 maximumColumnIndex = std::max<size_t>(maximumColumnIndex, positions.
resolvedFinalPosition().toInt()); |
| 1194 } | 1194 } |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 m_grid.grow(maximumRowIndex); | 1197 m_grid.grow(maximumRowIndex); |
| 1198 for (auto& column : m_grid) | 1198 for (auto& column : m_grid) |
| 1199 column.grow(maximumColumnIndex); | 1199 column.grow(maximumColumnIndex); |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 PassOwnPtr<GridCoordinate> LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOu
tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection
, const GridSpan& specifiedPositions) const | 1202 PassOwnPtr<GridCoordinate> LayoutGrid::createEmptyGridAreaAtSpecifiedPositionsOu
tsideGrid(const LayoutBox& gridItem, GridTrackSizingDirection specifiedDirection
, const GridSpan& specifiedPositions) const |
| 1203 { | 1203 { |
| 1204 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ?
ForRows : ForColumns; | 1204 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ?
ForRows : ForColumns; |
| 1205 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn
Count() : gridRowCount(); | 1205 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumn
Count() : gridRowCount(); |
| 1206 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition
sFromAutoPlacementPosition(*style(), gridItem, crossDirection, GridResolvedPosit
ion(endOfCrossDirection)); | 1206 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPosition
sFromAutoPlacementPosition(*style(), gridItem, crossDirection, GridResolvedPosit
ion(endOfCrossDirection)); |
| 1207 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD
irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci
fiedPositions : crossDirectionPositions)); | 1207 return adoptPtr(new GridCoordinate(specifiedDirection == ForColumns ? crossD
irectionPositions : specifiedPositions, specifiedDirection == ForColumns ? speci
fiedPositions : crossDirectionPositions)); |
| 1208 } | 1208 } |
| 1209 | 1209 |
| 1210 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au
toGridItems) | 1210 void LayoutGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>& au
toGridItems) |
| 1211 { | 1211 { |
| 1212 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; | 1212 bool isForColumns = autoPlacementMajorAxisDirection() == ForColumns; |
| 1213 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 1213 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 1214 | 1214 |
| 1215 // Mapping between the major axis tracks (rows or columns) and the last auto
-placed item's position inserted on | 1215 // Mapping between the major axis tracks (rows or columns) and the last auto
-placed item's position inserted on |
| 1216 // that track. This is needed to implement "sparse" packing for items locked
to a given track. | 1216 // that track. This is needed to implement "sparse" packing for items locked
to a given track. |
| 1217 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo | 1217 // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo |
| 1218 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe
roKeyHashTraits<unsigned>> minorAxisCursors; | 1218 HashMap<unsigned, unsigned, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZe
roKeyHashTraits<unsigned>> minorAxisCursors; |
| 1219 | 1219 |
| 1220 for (const auto& autoGridItem : autoGridItems) { | 1220 for (const auto& autoGridItem : autoGridItems) { |
| 1221 OwnPtr<GridSpan> majorAxisPositions = GridResolvedPosition::resolveGridP
ositionsFromStyle(*style(), *autoGridItem, autoPlacementMajorAxisDirection()); | 1221 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositions
FromStyle(*style(), *autoGridItem, autoPlacementMajorAxisDirection()); |
| 1222 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti
on(), GridResolvedPosition(0)); | 1222 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), *autoGridItem, autoPlacementMinorAxisDirecti
on(), GridResolvedPosition(0)); |
| 1223 unsigned majorAxisInitialPosition = majorAxisPositions->resolvedInitialP
osition.toInt(); | 1223 unsigned majorAxisInitialPosition = majorAxisPositions.resolvedInitialPo
sition().toInt(); |
| 1224 | 1224 |
| 1225 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->resolvedInitialPosition.toInt(), isGridAutoFlowDense ? 0 : minorAxi
sCursors.get(majorAxisInitialPosition)); | 1225 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions.resolvedInitialPosition().toInt(), isGridAutoFlowDense ? 0 : minorAx
isCursors.get(majorAxisInitialPosition)); |
| 1226 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA
xisPositions->integerSpan(), minorAxisPositions.integerSpan()); | 1226 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorA
xisPositions.integerSpan(), minorAxisPositions.integerSpan()); |
| 1227 if (!emptyGridArea) | 1227 if (!emptyGridArea) |
| 1228 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*
autoGridItem, autoPlacementMajorAxisDirection(), *majorAxisPositions); | 1228 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*
autoGridItem, autoPlacementMajorAxisDirection(), majorAxisPositions); |
| 1229 insertItemIntoGrid(*autoGridItem, *emptyGridArea); | 1229 insertItemIntoGrid(*autoGridItem, *emptyGridArea); |
| 1230 | 1230 |
| 1231 if (!isGridAutoFlowDense) | 1231 if (!isGridAutoFlowDense) |
| 1232 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG
ridArea->rows.resolvedInitialPosition.toInt() : emptyGridArea->columns.resolvedI
nitialPosition.toInt()); | 1232 minorAxisCursors.set(majorAxisInitialPosition, isForColumns ? emptyG
ridArea->rows.resolvedInitialPosition().toInt() : emptyGridArea->columns.resolve
dInitialPosition().toInt()); |
| 1233 } | 1233 } |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 void LayoutGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri
dItems) | 1236 void LayoutGrid::placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>& autoGri
dItems) |
| 1237 { | 1237 { |
| 1238 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); | 1238 std::pair<size_t, size_t> autoPlacementCursor = std::make_pair(0, 0); |
| 1239 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); | 1239 bool isGridAutoFlowDense = style()->isGridAutoFlowAlgorithmDense(); |
| 1240 | 1240 |
| 1241 for (const auto& autoGridItem : autoGridItems) { | 1241 for (const auto& autoGridItem : autoGridItems) { |
| 1242 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); | 1242 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); |
| 1243 | 1243 |
| 1244 // If grid-auto-flow is dense, reset auto-placement cursor. | 1244 // If grid-auto-flow is dense, reset auto-placement cursor. |
| 1245 if (isGridAutoFlowDense) { | 1245 if (isGridAutoFlowDense) { |
| 1246 autoPlacementCursor.first = 0; | 1246 autoPlacementCursor.first = 0; |
| 1247 autoPlacementCursor.second = 0; | 1247 autoPlacementCursor.second = 0; |
| 1248 } | 1248 } |
| 1249 } | 1249 } |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 void LayoutGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz
e_t, size_t>& autoPlacementCursor) | 1252 void LayoutGrid::placeAutoMajorAxisItemOnGrid(LayoutBox& gridItem, std::pair<siz
e_t, size_t>& autoPlacementCursor) |
| 1253 { | 1253 { |
| 1254 OwnPtr<GridSpan> minorAxisPositions = GridResolvedPosition::resolveGridPosit
ionsFromStyle(*style(), gridItem, autoPlacementMinorAxisDirection()); | 1254 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom
Style(*style(), gridItem, autoPlacementMinorAxisDirection()); |
| 1255 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(*style(), gridIt
em, autoPlacementMajorAxisDirection())); | 1255 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(*style(), gridIt
em, autoPlacementMajorAxisDirection()).isDefinite()); |
| 1256 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom
AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), Gri
dResolvedPosition(0)); | 1256 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFrom
AutoPlacementPosition(*style(), gridItem, autoPlacementMajorAxisDirection(), Gri
dResolvedPosition(0)); |
| 1257 | 1257 |
| 1258 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum
ns) ? gridColumnCount() : gridRowCount(); | 1258 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColum
ns) ? gridColumnCount() : gridRowCount(); |
| 1259 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; | 1259 size_t majorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.second : autoPlacementCursor.first; |
| 1260 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; | 1260 size_t minorAxisAutoPlacementCursor = autoPlacementMajorAxisDirection() == F
orColumns ? autoPlacementCursor.first : autoPlacementCursor.second; |
| 1261 | 1261 |
| 1262 OwnPtr<GridCoordinate> emptyGridArea; | 1262 OwnPtr<GridCoordinate> emptyGridArea; |
| 1263 if (minorAxisPositions) { | 1263 if (minorAxisPositions.isDefinite()) { |
| 1264 // Move to the next track in major axis if initial position in minor axi
s is before auto-placement cursor. | 1264 // Move to the next track in major axis if initial position in minor axi
s is before auto-placement cursor. |
| 1265 if (minorAxisPositions->resolvedInitialPosition.toInt() < minorAxisAutoP
lacementCursor) | 1265 if (minorAxisPositions.resolvedInitialPosition().toInt() < minorAxisAuto
PlacementCursor) |
| 1266 majorAxisAutoPlacementCursor++; | 1266 majorAxisAutoPlacementCursor++; |
| 1267 | 1267 |
| 1268 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { | 1268 if (majorAxisAutoPlacementCursor < endOfMajorAxis) { |
| 1269 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), min
orAxisPositions->resolvedInitialPosition.toInt(), majorAxisAutoPlacementCursor); | 1269 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), min
orAxisPositions.resolvedInitialPosition().toInt(), majorAxisAutoPlacementCursor)
; |
| 1270 emptyGridArea = iterator.nextEmptyGridArea(minorAxisPositions->integ
erSpan(), majorAxisPositions.integerSpan()); | 1270 emptyGridArea = iterator.nextEmptyGridArea(minorAxisPositions.intege
rSpan(), majorAxisPositions.integerSpan()); |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 if (!emptyGridArea) | 1273 if (!emptyGridArea) |
| 1274 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), *minorAxisPositions); | 1274 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); |
| 1275 } else { | 1275 } else { |
| 1276 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), gridItem, autoPlacementMinorAxisDirection(),
GridResolvedPosition(0)); | 1276 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositions
FromAutoPlacementPosition(*style(), gridItem, autoPlacementMinorAxisDirection(),
GridResolvedPosition(0)); |
| 1277 | 1277 |
| 1278 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; majorAxisInde
x < endOfMajorAxis; ++majorAxisIndex) { | 1278 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; majorAxisInde
x < endOfMajorAxis; ++majorAxisIndex) { |
| 1279 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj
orAxisIndex, minorAxisAutoPlacementCursor); | 1279 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj
orAxisIndex, minorAxisAutoPlacementCursor); |
| 1280 emptyGridArea = iterator.nextEmptyGridArea(majorAxisPositions.intege
rSpan(), minorAxisPositions.integerSpan()); | 1280 emptyGridArea = iterator.nextEmptyGridArea(majorAxisPositions.intege
rSpan(), minorAxisPositions.integerSpan()); |
| 1281 | 1281 |
| 1282 if (emptyGridArea) { | 1282 if (emptyGridArea) { |
| 1283 // 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()). | 1283 // 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()). |
| 1284 GridResolvedPosition minorAxisFinalPositionIndex = autoPlacement
MinorAxisDirection() == ForColumns ? emptyGridArea->columns.resolvedFinalPositio
n : emptyGridArea->rows.resolvedFinalPosition; | 1284 GridResolvedPosition minorAxisFinalPositionIndex = autoPlacement
MinorAxisDirection() == ForColumns ? emptyGridArea->columns.resolvedFinalPositio
n() : emptyGridArea->rows.resolvedFinalPosition(); |
| 1285 const size_t endOfMinorAxis = autoPlacementMinorAxisDirection()
== ForColumns ? gridColumnCount() : gridRowCount(); | 1285 const size_t endOfMinorAxis = autoPlacementMinorAxisDirection()
== ForColumns ? gridColumnCount() : gridRowCount(); |
| 1286 if (minorAxisFinalPositionIndex.toInt() <= endOfMinorAxis) | 1286 if (minorAxisFinalPositionIndex.toInt() <= endOfMinorAxis) |
| 1287 break; | 1287 break; |
| 1288 | 1288 |
| 1289 // Discard empty grid area as it does not fit in the minor axis
direction. | 1289 // Discard empty grid area as it does not fit in the minor axis
direction. |
| 1290 // We don't need to create a new empty grid area yet as we might
find a valid one in the next iteration. | 1290 // We don't need to create a new empty grid area yet as we might
find a valid one in the next iteration. |
| 1291 emptyGridArea = nullptr; | 1291 emptyGridArea = nullptr; |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 // As we're moving to the next track in the major axis we should res
et the auto-placement cursor in the minor axis. | 1294 // As we're moving to the next track in the major axis we should res
et the auto-placement cursor in the minor axis. |
| 1295 minorAxisAutoPlacementCursor = 0; | 1295 minorAxisAutoPlacementCursor = 0; |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 if (!emptyGridArea) | 1298 if (!emptyGridArea) |
| 1299 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); | 1299 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g
ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 insertItemIntoGrid(gridItem, *emptyGridArea); | 1302 insertItemIntoGrid(gridItem, *emptyGridArea); |
| 1303 // Move auto-placement cursor to the new position. | 1303 // Move auto-placement cursor to the new position. |
| 1304 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition.toIn
t(); | 1304 autoPlacementCursor.first = emptyGridArea->rows.resolvedInitialPosition().to
Int(); |
| 1305 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition.
toInt(); | 1305 autoPlacementCursor.second = emptyGridArea->columns.resolvedInitialPosition(
).toInt(); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const | 1308 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const |
| 1309 { | 1309 { |
| 1310 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; | 1310 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; |
| 1311 } | 1311 } |
| 1312 | 1312 |
| 1313 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const | 1313 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const |
| 1314 { | 1314 { |
| 1315 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 1315 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 applyStretchAlignmentToChildIfNeeded(*child); | 1398 applyStretchAlignmentToChildIfNeeded(*child); |
| 1399 | 1399 |
| 1400 child->layoutIfNeeded(); | 1400 child->layoutIfNeeded(); |
| 1401 | 1401 |
| 1402 // We need pending layouts to be done in order to compute auto-margins p
roperly. | 1402 // We need pending layouts to be done in order to compute auto-margins p
roperly. |
| 1403 updateAutoMarginsInColumnAxisIfNeeded(*child); | 1403 updateAutoMarginsInColumnAxisIfNeeded(*child); |
| 1404 updateAutoMarginsInRowAxisIfNeeded(*child); | 1404 updateAutoMarginsInRowAxisIfNeeded(*child); |
| 1405 | 1405 |
| 1406 #if ENABLE(ASSERT) | 1406 #if ENABLE(ASSERT) |
| 1407 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1407 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
| 1408 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); | 1408 ASSERT(coordinate.columns.resolvedInitialPosition().toInt() < sizingData
.columnTracks.size()); |
| 1409 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); | 1409 ASSERT(coordinate.rows.resolvedInitialPosition().toInt() < sizingData.ro
wTracks.size()); |
| 1410 #endif | 1410 #endif |
| 1411 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1411 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
| 1412 | 1412 |
| 1413 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is | 1413 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is |
| 1414 // not visible | 1414 // not visible |
| 1415 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1415 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
| 1416 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) | 1416 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) |
| 1417 m_gridItemsOverflowingGridArea.append(child); | 1417 m_gridItemsOverflowingGridArea.append(child); |
| 1418 } | 1418 } |
| 1419 } | 1419 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 child->setExtraBlockOffset(rowOffset); | 1455 child->setExtraBlockOffset(rowOffset); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 LayoutBlock::layoutPositionedObjects(relayoutChildren, info); | 1458 LayoutBlock::layoutPositionedObjects(relayoutChildren, info); |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 void LayoutGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid
TrackSizingDirection direction, LayoutUnit& offset, LayoutUnit& breadth) | 1461 void LayoutGrid::offsetAndBreadthForPositionedChild(const LayoutBox& child, Grid
TrackSizingDirection direction, LayoutUnit& offset, LayoutUnit& breadth) |
| 1462 { | 1462 { |
| 1463 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode()); | 1463 ASSERT(child.isHorizontalWritingMode() == isHorizontalWritingMode()); |
| 1464 | 1464 |
| 1465 OwnPtr<GridSpan> positions = GridResolvedPosition::resolveGridPositionsFromS
tyle(*style(), child, direction); | 1465 GridSpan positions = GridResolvedPosition::resolveGridPositionsFromStyle(*st
yle(), child, direction); |
| 1466 if (!positions) { | 1466 if (!positions.isDefinite()) { |
| 1467 offset = LayoutUnit(); | 1467 offset = LayoutUnit(); |
| 1468 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic
alHeight(); | 1468 breadth = (direction == ForColumns) ? clientLogicalWidth() : clientLogic
alHeight(); |
| 1469 return; | 1469 return; |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 GridPosition startPosition = (direction == ForColumns) ? child.style()->grid
ColumnStart() : child.style()->gridRowStart(); | 1472 GridPosition startPosition = (direction == ForColumns) ? child.style()->grid
ColumnStart() : child.style()->gridRowStart(); |
| 1473 GridPosition endPosition = (direction == ForColumns) ? child.style()->gridCo
lumnEnd() : child.style()->gridRowEnd(); | 1473 GridPosition endPosition = (direction == ForColumns) ? child.style()->gridCo
lumnEnd() : child.style()->gridRowEnd(); |
| 1474 size_t lastTrackIndex = (direction == ForColumns ? gridColumnCount() : gridR
owCount()) - 1; | 1474 size_t lastTrackIndex = (direction == ForColumns ? gridColumnCount() : gridR
owCount()) - 1; |
| 1475 | 1475 |
| 1476 bool startIsAuto = startPosition.isAuto() | 1476 bool startIsAuto = startPosition.isAuto() |
| 1477 || (startPosition.isNamedGridArea() && !GridResolvedPosition::isValidNam
edLineOrArea(startPosition.namedGridLine(), styleRef(), GridResolvedPosition::in
itialPositionSide(direction))) | 1477 || (startPosition.isNamedGridArea() && !GridResolvedPosition::isValidNam
edLineOrArea(startPosition.namedGridLine(), styleRef(), GridResolvedPosition::in
itialPositionSide(direction))) |
| 1478 || (positions->resolvedInitialPosition.toInt() > lastTrackIndex); | 1478 || (positions.resolvedInitialPosition().toInt() > lastTrackIndex); |
| 1479 bool endIsAuto = endPosition.isAuto() | 1479 bool endIsAuto = endPosition.isAuto() |
| 1480 || (endPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamed
LineOrArea(endPosition.namedGridLine(), styleRef(), GridResolvedPosition::finalP
ositionSide(direction))) | 1480 || (endPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamed
LineOrArea(endPosition.namedGridLine(), styleRef(), GridResolvedPosition::finalP
ositionSide(direction))) |
| 1481 || (positions->resolvedFinalPosition.prev().toInt() > lastTrackIndex); | 1481 || (positions.resolvedFinalPosition().prev().toInt() > lastTrackIndex); |
| 1482 | 1482 |
| 1483 GridResolvedPosition firstPosition = GridResolvedPosition(0); | 1483 GridResolvedPosition firstPosition = GridResolvedPosition(0); |
| 1484 GridResolvedPosition initialPosition = startIsAuto ? firstPosition : positio
ns->resolvedInitialPosition; | 1484 GridResolvedPosition initialPosition = startIsAuto ? firstPosition : positio
ns.resolvedInitialPosition(); |
| 1485 GridResolvedPosition lastPosition = GridResolvedPosition(lastTrackIndex); | 1485 GridResolvedPosition lastPosition = GridResolvedPosition(lastTrackIndex); |
| 1486 GridResolvedPosition finalPosition = endIsAuto ? lastPosition : positions->r
esolvedFinalPosition.prev(); | 1486 GridResolvedPosition finalPosition = endIsAuto ? lastPosition : positions.re
solvedFinalPosition().prev(); |
| 1487 | 1487 |
| 1488 // Positioned children do not grow the grid, so we need to clamp the positio
ns to avoid ending up outside of it. | 1488 // Positioned children do not grow the grid, so we need to clamp the positio
ns to avoid ending up outside of it. |
| 1489 initialPosition = std::min<GridResolvedPosition>(initialPosition, lastPositi
on); | 1489 initialPosition = std::min<GridResolvedPosition>(initialPosition, lastPositi
on); |
| 1490 finalPosition = std::min<GridResolvedPosition>(finalPosition, lastPosition); | 1490 finalPosition = std::min<GridResolvedPosition>(finalPosition, lastPosition); |
| 1491 | 1491 |
| 1492 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ?
m_columnPositions[initialPosition.toInt()] : m_rowPositions[initialPosition.toI
nt()]; | 1492 LayoutUnit start = startIsAuto ? LayoutUnit() : (direction == ForColumns) ?
m_columnPositions[initialPosition.toInt()] : m_rowPositions[initialPosition.toI
nt()]; |
| 1493 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo
gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition.nex
t().toInt()] : m_rowPositions[finalPosition.next().toInt()]; | 1493 LayoutUnit end = endIsAuto ? (direction == ForColumns) ? logicalWidth() : lo
gicalHeight() : (direction == ForColumns) ? m_columnPositions[finalPosition.nex
t().toInt()] : m_rowPositions[finalPosition.next().toInt()]; |
| 1494 | 1494 |
| 1495 breadth = end - start; | 1495 breadth = end - start; |
| 1496 | 1496 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 return gridAreaBreadth; | 1540 return gridAreaBreadth; |
| 1541 } | 1541 } |
| 1542 | 1542 |
| 1543 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const | 1543 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const |
| 1544 { | 1544 { |
| 1545 // We need the cached value when available because Content Distribution alig
nment properties | 1545 // We need the cached value when available because Content Distribution alig
nment properties |
| 1546 // may have some influence in the final grid area breadth. | 1546 // may have some influence in the final grid area breadth. |
| 1547 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; | 1547 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; |
| 1548 const GridSpan& span = cachedGridSpan(child, direction); | 1548 const GridSpan& span = cachedGridSpan(child, direction); |
| 1549 const Vector<LayoutUnit>& linePositions = (direction == ForColumns) ? m_colu
mnPositions : m_rowPositions; | 1549 const Vector<LayoutUnit>& linePositions = (direction == ForColumns) ? m_colu
mnPositions : m_rowPositions; |
| 1550 LayoutUnit initialTrackPosition = linePositions[span.resolvedInitialPosition
.toInt()]; | 1550 LayoutUnit initialTrackPosition = linePositions[span.resolvedInitialPosition
().toInt()]; |
| 1551 LayoutUnit finalTrackPosition = linePositions[span.resolvedFinalPosition.pre
v().toInt()]; | 1551 LayoutUnit finalTrackPosition = linePositions[span.resolvedFinalPosition().p
rev().toInt()]; |
| 1552 // Track Positions vector stores the 'start' grid line of each track, so w h
ave to add last track's baseSize. | 1552 // Track Positions vector stores the 'start' grid line of each track, so w h
ave to add last track's baseSize. |
| 1553 return finalTrackPosition - initialTrackPosition + tracks[span.resolvedFinal
Position.prev().toInt()].baseSize(); | 1553 return finalTrackPosition - initialTrackPosition + tracks[span.resolvedFinal
Position().prev().toInt()].baseSize(); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 void LayoutGrid::populateGridPositions(GridSizingData& sizingData) | 1556 void LayoutGrid::populateGridPositions(GridSizingData& sizingData) |
| 1557 { | 1557 { |
| 1558 // Since we add alignment offsets and track gutters, grid lines are not alwa
ys adjacent. Hence we will have to | 1558 // Since we add alignment offsets and track gutters, grid lines are not alwa
ys adjacent. Hence we will have to |
| 1559 // assume from now on that we just store positions of the initial grid lines
of each track, | 1559 // assume from now on that we just store positions of the initial grid lines
of each track, |
| 1560 // except the last one, which is the only one considered as a final grid lin
e of a track. | 1560 // except the last one, which is the only one considered as a final grid lin
e of a track. |
| 1561 // FIXME: This will affect the computed style value of grid tracks size, sin
ce we are | 1561 // FIXME: This will affect the computed style value of grid tracks size, sin
ce we are |
| 1562 // using these positions to compute them. | 1562 // using these positions to compute them. |
| 1563 | 1563 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 | 1850 |
| 1851 static inline LayoutUnit offsetBetweenTracks(ContentDistributionType distributio
n, const Vector<LayoutUnit>& trackPositions, const LayoutUnit& childBreadth) | 1851 static inline LayoutUnit offsetBetweenTracks(ContentDistributionType distributio
n, const Vector<LayoutUnit>& trackPositions, const LayoutUnit& childBreadth) |
| 1852 { | 1852 { |
| 1853 return (distribution == ContentDistributionStretch || ContentDistributionStr
etch == ContentDistributionDefault) ? LayoutUnit() : trackPositions[1] - trackPo
sitions[0] - childBreadth; | 1853 return (distribution == ContentDistributionStretch || ContentDistributionStr
etch == ContentDistributionDefault) ? LayoutUnit() : trackPositions[1] - trackPo
sitions[0] - childBreadth; |
| 1854 | 1854 |
| 1855 } | 1855 } |
| 1856 | 1856 |
| 1857 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child) const | 1857 LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child) const |
| 1858 { | 1858 { |
| 1859 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); | 1859 const GridSpan& rowsSpan = cachedGridSpan(child, ForRows); |
| 1860 size_t childStartLine = rowsSpan.resolvedInitialPosition.toInt(); | 1860 size_t childStartLine = rowsSpan.resolvedInitialPosition().toInt(); |
| 1861 LayoutUnit startOfRow = m_rowPositions[childStartLine]; | 1861 LayoutUnit startOfRow = m_rowPositions[childStartLine]; |
| 1862 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); | 1862 LayoutUnit startPosition = startOfRow + marginBeforeForChild(child); |
| 1863 if (hasAutoMarginsInColumnAxis(child)) | 1863 if (hasAutoMarginsInColumnAxis(child)) |
| 1864 return startPosition; | 1864 return startPosition; |
| 1865 GridAxisPosition axisPosition = columnAxisPositionForChild(child); | 1865 GridAxisPosition axisPosition = columnAxisPositionForChild(child); |
| 1866 switch (axisPosition) { | 1866 switch (axisPosition) { |
| 1867 case GridAxisStart: | 1867 case GridAxisStart: |
| 1868 return startPosition; | 1868 return startPosition; |
| 1869 case GridAxisEnd: | 1869 case GridAxisEnd: |
| 1870 case GridAxisCenter: { | 1870 case GridAxisCenter: { |
| 1871 size_t childEndLine = rowsSpan.resolvedFinalPosition.toInt(); | 1871 size_t childEndLine = rowsSpan.resolvedFinalPosition().toInt(); |
| 1872 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 1872 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
| 1873 // m_rowPositions include gutters so we need to substract them to get th
e actual end position for a given | 1873 // m_rowPositions include gutters so we need to substract them to get th
e actual end position for a given |
| 1874 // row (this does not have to be done for the last track as there are no
more m_rowPositions after it) | 1874 // row (this does not have to be done for the last track as there are no
more m_rowPositions after it) |
| 1875 if (childEndLine < m_rowPositions.size() - 1) | 1875 if (childEndLine < m_rowPositions.size() - 1) |
| 1876 endOfRow -= guttersSize(ForRows, 2); | 1876 endOfRow -= guttersSize(ForRows, 2); |
| 1877 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); | 1877 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); |
| 1878 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s
ize() - 1) | 1878 if (childEndLine - childStartLine > 1 && childEndLine < m_rowPositions.s
ize() - 1) |
| 1879 endOfRow -= offsetBetweenTracks(styleRef().alignContentDistribution(
), m_rowPositions, childBreadth); | 1879 endOfRow -= offsetBetweenTracks(styleRef().alignContentDistribution(
), m_rowPositions, childBreadth); |
| 1880 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().alignSelfOverflowAlignment(), endOfRow - startOfRow, childBreadth); | 1880 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().alignSelfOverflowAlignment(), endOfRow - startOfRow, childBreadth); |
| 1881 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 1881 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| 1882 } | 1882 } |
| 1883 } | 1883 } |
| 1884 | 1884 |
| 1885 ASSERT_NOT_REACHED(); | 1885 ASSERT_NOT_REACHED(); |
| 1886 return 0; | 1886 return 0; |
| 1887 } | 1887 } |
| 1888 | 1888 |
| 1889 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child) const | 1889 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child) const |
| 1890 { | 1890 { |
| 1891 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); | 1891 const GridSpan& columnsSpan = cachedGridSpan(child, ForColumns); |
| 1892 size_t childStartLine = columnsSpan.resolvedInitialPosition.toInt(); | 1892 size_t childStartLine = columnsSpan.resolvedInitialPosition().toInt(); |
| 1893 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; | 1893 LayoutUnit startOfColumn = m_columnPositions[childStartLine]; |
| 1894 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); | 1894 LayoutUnit startPosition = startOfColumn + marginStartForChild(child); |
| 1895 if (hasAutoMarginsInRowAxis(child)) | 1895 if (hasAutoMarginsInRowAxis(child)) |
| 1896 return startPosition; | 1896 return startPosition; |
| 1897 GridAxisPosition axisPosition = rowAxisPositionForChild(child); | 1897 GridAxisPosition axisPosition = rowAxisPositionForChild(child); |
| 1898 switch (axisPosition) { | 1898 switch (axisPosition) { |
| 1899 case GridAxisStart: | 1899 case GridAxisStart: |
| 1900 return startPosition; | 1900 return startPosition; |
| 1901 case GridAxisEnd: | 1901 case GridAxisEnd: |
| 1902 case GridAxisCenter: { | 1902 case GridAxisCenter: { |
| 1903 size_t childEndLine = columnsSpan.resolvedFinalPosition.toInt(); | 1903 size_t childEndLine = columnsSpan.resolvedFinalPosition().toInt(); |
| 1904 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 1904 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
| 1905 // m_columnPositions include gutters so we need to substract them to get
the actual end position for a given | 1905 // m_columnPositions include gutters so we need to substract them to get
the actual end position for a given |
| 1906 // column (this does not have to be done for the last track as there are
no more m_columnPositions after it) | 1906 // column (this does not have to be done for the last track as there are
no more m_columnPositions after it) |
| 1907 if (childEndLine < m_columnPositions.size() - 1) | 1907 if (childEndLine < m_columnPositions.size() - 1) |
| 1908 endOfColumn -= guttersSize(ForRows, 2); | 1908 endOfColumn -= guttersSize(ForRows, 2); |
| 1909 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); | 1909 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); |
| 1910 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition
s.size() - 1) | 1910 if (childEndLine - childStartLine > 1 && childEndLine < m_columnPosition
s.size() - 1) |
| 1911 endOfColumn -= offsetBetweenTracks(styleRef().justifyContentDistribu
tion(), m_columnPositions, childBreadth); | 1911 endOfColumn -= offsetBetweenTracks(styleRef().justifyContentDistribu
tion(), m_columnPositions, childBreadth); |
| 1912 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); | 1912 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); |
| 1913 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 1913 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 | 2044 |
| 2045 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 2045 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); |
| 2046 } | 2046 } |
| 2047 | 2047 |
| 2048 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2048 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
| 2049 { | 2049 { |
| 2050 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2050 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2051 } | 2051 } |
| 2052 | 2052 |
| 2053 } // namespace blink | 2053 } // namespace blink |
| OLD | NEW |