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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 | 230 |
231 Vector<GridTrack> columnTracks; | 231 Vector<GridTrack> columnTracks; |
232 Vector<GridTrack> rowTracks; | 232 Vector<GridTrack> rowTracks; |
233 Vector<size_t> contentSizedTracksIndex; | 233 Vector<size_t> contentSizedTracksIndex; |
234 | 234 |
235 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. | 235 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. |
236 Vector<GridTrack*> filteredTracks; | 236 Vector<GridTrack*> filteredTracks; |
237 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 237 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
238 Vector<GridTrack*> growBeyondGrowthLimitsTracks; | 238 Vector<GridTrack*> growBeyondGrowthLimitsTracks; |
| 239 |
| 240 LayoutUnit rowsPositionOffset; |
| 241 LayoutUnit rowsDistributionOffset; |
| 242 LayoutUnit columnsPositionOffset; |
| 243 LayoutUnit columnsDistributionOffset; |
239 }; | 244 }; |
240 | 245 |
241 struct GridItemsSpanGroupRange { | 246 struct GridItemsSpanGroupRange { |
242 Vector<GridItemWithSpan>::iterator rangeStart; | 247 Vector<GridItemWithSpan>::iterator rangeStart; |
243 Vector<GridItemWithSpan>::iterator rangeEnd; | 248 Vector<GridItemWithSpan>::iterator rangeEnd; |
244 }; | 249 }; |
245 | 250 |
246 LayoutGrid::LayoutGrid(Element* element) | 251 LayoutGrid::LayoutGrid(Element* element) |
247 : LayoutBlock(element) | 252 : LayoutBlock(element) |
248 , m_gridIsDirty(true) | 253 , m_gridIsDirty(true) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 ASSERT(!track.growthLimitIsInfinite()); | 433 ASSERT(!track.growthLimitIsInfinite()); |
429 freeSpace -= track.baseSize(); | 434 freeSpace -= track.baseSize(); |
430 } | 435 } |
431 | 436 |
432 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->lo
gicalHeight().isAuto() : gridElementIsShrinkToFit(); | 437 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->lo
gicalHeight().isAuto() : gridElementIsShrinkToFit(); |
433 | 438 |
434 if (!hasUndefinedRemainingSpace && freeSpace <= 0) | 439 if (!hasUndefinedRemainingSpace && freeSpace <= 0) |
435 return; | 440 return; |
436 | 441 |
437 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro
wthLimit value until freeSpace is exhausted. | 442 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro
wthLimit value until freeSpace is exhausted. |
| 443 // Any 'auto-sized' (content based) track will be 'stretched' over their Max
Breadth if required |
| 444 // and there is space available, except if there are flexible track, which w
ill occupy the whole |
| 445 // available space. |
| 446 bool needToStretch = flexibleSizedTracksIndex.isEmpty() && !sizingData.conte
ntSizedTracksIndex.isEmpty() |
| 447 && ((direction == ForColumns && style()->justifyContentDistribution() ==
ContentDistributionStretch) |
| 448 || (direction == ForRows && style()->alignContentDistribution() == C
ontentDistributionStretch)); |
438 const size_t tracksSize = tracks.size(); | 449 const size_t tracksSize = tracks.size(); |
439 if (!hasUndefinedRemainingSpace) { | 450 if (!hasUndefinedRemainingSpace) { |
440 Vector<GridTrack*> tracksForDistribution(tracksSize); | 451 Vector<GridTrack*> tracksForDistribution(tracksSize); |
441 for (size_t i = 0; i < tracksSize; ++i) { | 452 for (size_t i = 0; i < tracksSize; ++i) { |
442 tracksForDistribution[i] = tracks.data() + i; | 453 tracksForDistribution[i] = tracks.data() + i; |
443 tracksForDistribution[i]->m_plannedIncrease = 0; | 454 tracksForDistribution[i]->m_plannedIncrease = 0; |
444 } | 455 } |
445 | 456 |
446 distributeSpaceToTracks(tracksForDistribution, nullptr, &GridTrack::base
Size, sizingData, freeSpace); | 457 Vector<GridTrack*> tracksToStretch(sizingData.contentSizedTracksIndex.si
ze()); |
| 458 if (needToStretch) { |
| 459 unsigned i = 0; |
| 460 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 461 tracksToStretch[i++] = tracks.data() + trackIndex; |
| 462 } |
| 463 } |
| 464 |
| 465 distributeSpaceToTracks(tracksForDistribution, needToStretch ? &tracksTo
Stretch : nullptr, &GridTrack::baseSize, sizingData, freeSpace); |
447 | 466 |
448 for (auto* track : tracksForDistribution) | 467 for (auto* track : tracksForDistribution) |
449 track->growBaseSize(track->m_plannedIncrease); | 468 track->growBaseSize(track->m_plannedIncrease); |
450 } else { | 469 } else { |
451 for (auto& track : tracks) | 470 for (auto& track : tracks) |
452 track.setBaseSize(track.growthLimit()); | 471 track.setBaseSize(track.growthLimit()); |
453 } | 472 } |
454 | 473 |
455 if (flexibleSizedTracksIndex.isEmpty()) | 474 if (flexibleSizedTracksIndex.isEmpty()) |
456 return; | 475 return; |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 placeItemsOnGrid(); | 1141 placeItemsOnGrid(); |
1123 | 1142 |
1124 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 1143 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
1125 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); | 1144 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); |
1126 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 1145 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
1127 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu
mns); | 1146 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu
mns); |
1128 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); | 1147 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); |
1129 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); | 1148 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); |
1130 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); | 1149 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); |
1131 | 1150 |
| 1151 computeContentPositionAndDistributionColumnOffset(availableSpaceForColumns,
sizingData); |
| 1152 computeContentPositionAndDistributionRowOffset(availableSpaceForRows, sizing
Data); |
| 1153 |
1132 populateGridPositions(sizingData); | 1154 populateGridPositions(sizingData); |
1133 m_gridItemsOverflowingGridArea.resize(0); | 1155 m_gridItemsOverflowingGridArea.resize(0); |
1134 | 1156 |
1135 LayoutUnit columnOffset = contentPositionAndDistributionColumnOffset(availab
leSpaceForColumns, style()->justifyContent(), style()->justifyContentDistributio
n(), style()->justifyContentOverflowAlignment(), m_columnPositions.size() - 1); | |
1136 LayoutUnit rowOffset = contentPositionAndDistributionRowOffset(availableSpac
eForRows, style()->alignContent(), style()->alignContentDistribution(), style()-
>alignContentOverflowAlignment(), m_rowPositions.size() - 1); | |
1137 LayoutSize contentPositionOffset(columnOffset, rowOffset); | |
1138 | |
1139 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 1157 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
1140 if (child->isOutOfFlowPositioned()) { | 1158 if (child->isOutOfFlowPositioned()) { |
1141 child->containingBlock()->insertPositionedObject(child); | 1159 child->containingBlock()->insertPositionedObject(child); |
1142 continue; | 1160 continue; |
1143 } | 1161 } |
1144 | 1162 |
1145 // Because the grid area cannot be styled, we don't need to adjust | 1163 // Because the grid area cannot be styled, we don't need to adjust |
1146 // the grid breadth to account for 'box-sizing'. | 1164 // the grid breadth to account for 'box-sizing'. |
1147 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve
rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica
lWidth() : LayoutUnit(); | 1165 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve
rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica
lWidth() : LayoutUnit(); |
1148 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv
errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi
calHeight() : LayoutUnit(); | 1166 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv
errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi
calHeight() : LayoutUnit(); |
(...skipping 13 matching lines...) Expand all Loading... |
1162 // determine the available space before stretching, are not set yet. | 1180 // determine the available space before stretching, are not set yet. |
1163 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont
entLogicalHeight); | 1181 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont
entLogicalHeight); |
1164 | 1182 |
1165 child->layoutIfNeeded(); | 1183 child->layoutIfNeeded(); |
1166 | 1184 |
1167 #if ENABLE(ASSERT) | 1185 #if ENABLE(ASSERT) |
1168 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1186 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
1169 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); | 1187 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); |
1170 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); | 1188 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); |
1171 #endif | 1189 #endif |
1172 child->setLogicalLocation(findChildLogicalPosition(*child, contentPositi
onOffset)); | 1190 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1173 | 1191 |
1174 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is | 1192 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is |
1175 // not visible | 1193 // not visible |
1176 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1194 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
1177 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) | 1195 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) |
1178 m_gridItemsOverflowingGridArea.append(child); | 1196 m_gridItemsOverflowingGridArea.append(child); |
1179 } | 1197 } |
1180 | 1198 |
1181 for (const auto& row : sizingData.rowTracks) | 1199 for (const auto& row : sizingData.rowTracks) |
1182 setLogicalHeight(logicalHeight() + row.baseSize()); | 1200 setLogicalHeight(logicalHeight() + row.baseSize()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const | 1294 GridCoordinate LayoutGrid::cachedGridCoordinate(const LayoutBox& gridItem) const |
1277 { | 1295 { |
1278 ASSERT(m_gridItemCoordinate.contains(&gridItem)); | 1296 ASSERT(m_gridItemCoordinate.contains(&gridItem)); |
1279 return m_gridItemCoordinate.get(&gridItem); | 1297 return m_gridItemCoordinate.get(&gridItem); |
1280 } | 1298 } |
1281 | 1299 |
1282 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const | 1300 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const |
1283 { | 1301 { |
1284 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1302 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1285 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; | 1303 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; |
| 1304 const Vector<LayoutUnit>& trackPositions = (direction == ForColumns) ? m_col
umnPositions : m_rowPositions; |
| 1305 if (span.resolvedFinalPosition.toInt() < trackPositions.size()) { |
| 1306 LayoutUnit startOftrack = trackPositions[span.resolvedInitialPosition.to
Int()]; |
| 1307 LayoutUnit endOfTrack = trackPositions[span.resolvedFinalPosition.toInt(
)]; |
| 1308 return endOfTrack - startOftrack + tracks[span.resolvedFinalPosition.toI
nt()].baseSize(); |
| 1309 } |
1286 LayoutUnit gridAreaBreadth = 0; | 1310 LayoutUnit gridAreaBreadth = 0; |
1287 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) | 1311 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) |
1288 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); | 1312 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); |
| 1313 |
1289 return gridAreaBreadth; | 1314 return gridAreaBreadth; |
1290 } | 1315 } |
1291 | 1316 |
1292 void LayoutGrid::populateGridPositions(const GridSizingData& sizingData) | 1317 void LayoutGrid::populateGridPositions(const GridSizingData& sizingData) |
1293 { | 1318 { |
1294 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); | 1319 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); |
1295 unsigned numberOfRowTracks = sizingData.rowTracks.size(); | 1320 unsigned numberOfRowTracks = sizingData.rowTracks.size(); |
1296 | 1321 |
1297 m_columnPositions.resize(numberOfColumnTracks + 1); | 1322 m_columnPositions.resize(numberOfColumnTracks + 1); |
1298 m_columnPositions[0] = borderAndPaddingStart(); | 1323 m_columnPositions[0] = borderAndPaddingStart() + sizingData.columnsPositionO
ffset; |
1299 for (unsigned i = 0; i < numberOfColumnTracks; ++i) | 1324 for (unsigned i = 0; i < numberOfColumnTracks; ++i) |
1300 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].baseSize(); | 1325 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnsDist
ributionOffset + sizingData.columnTracks[i].baseSize(); |
1301 | 1326 |
1302 m_rowPositions.resize(numberOfRowTracks + 1); | 1327 m_rowPositions.resize(numberOfRowTracks + 1); |
1303 m_rowPositions[0] = borderAndPaddingBefore(); | 1328 m_rowPositions[0] = borderAndPaddingBefore() + sizingData.rowsPositionOffset
; |
1304 for (unsigned i = 0; i < numberOfRowTracks; ++i) | 1329 for (unsigned i = 0; i < numberOfRowTracks; ++i) |
1305 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].base
Size(); | 1330 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowsDistributionO
ffset + sizingData.rowTracks[i].baseSize(); |
1306 } | 1331 } |
1307 | 1332 |
1308 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) | 1333 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) |
1309 { | 1334 { |
1310 LayoutUnit trackBreadth = endOfTrack - startOfTrack; | 1335 LayoutUnit trackBreadth = endOfTrack - startOfTrack; |
1311 LayoutUnit offset = trackBreadth - childBreadth; | 1336 LayoutUnit offset = trackBreadth - childBreadth; |
1312 | 1337 |
1313 // If overflow is 'safe', we have to make sure we don't overflow the 'start' | 1338 // If overflow is 'safe', we have to make sure we don't overflow the 'start' |
1314 // edge (potentially cause some data loss as the overflow is unreachable). | 1339 // edge (potentially cause some data loss as the overflow is unreachable). |
1315 if (overflow == OverflowAlignmentSafe) | 1340 if (overflow == OverflowAlignmentSafe) |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa
bleSpace) | 1682 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa
bleSpace) |
1658 { | 1683 { |
1659 return isLeftToRight ? LayoutUnit() : availableSpace; | 1684 return isLeftToRight ? LayoutUnit() : availableSpace; |
1660 } | 1685 } |
1661 | 1686 |
1662 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl
eSpace) | 1687 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl
eSpace) |
1663 { | 1688 { |
1664 return !isLeftToRight ? LayoutUnit() : availableSpace; | 1689 return !isLeftToRight ? LayoutUnit() : availableSpace; |
1665 } | 1690 } |
1666 | 1691 |
1667 LayoutUnit LayoutGrid::contentPositionAndDistributionColumnOffset(LayoutUnit ava
ilableFreeSpace, ContentPosition position, ContentDistributionType distribution,
OverflowAlignment overflow, unsigned numberOfGridTracks) const | 1692 |
| 1693 static bool contentDistributionOffset(LayoutUnit availableFreeSpace, ContentPosi
tion& fallbackPosition, ContentDistributionType distribution, unsigned numberOfG
ridTracks, LayoutUnit& positionOffset, LayoutUnit& distributionOffset) |
1668 { | 1694 { |
| 1695 if (distribution != ContentDistributionDefault && fallbackPosition == Conten
tPositionAuto) |
| 1696 fallbackPosition = resolveContentDistributionFallback(distribution); |
| 1697 |
| 1698 if (availableFreeSpace <= 0) |
| 1699 return false; |
| 1700 |
| 1701 switch (distribution) { |
| 1702 case ContentDistributionSpaceBetween: |
| 1703 if (numberOfGridTracks < 2) |
| 1704 return false; |
| 1705 distributionOffset = availableFreeSpace / (numberOfGridTracks - 1); |
| 1706 positionOffset = 0; |
| 1707 return true; |
| 1708 case ContentDistributionSpaceAround: |
| 1709 if (numberOfGridTracks < 1) |
| 1710 return false; |
| 1711 distributionOffset = availableFreeSpace / numberOfGridTracks; |
| 1712 positionOffset = distributionOffset / 2; |
| 1713 return true; |
| 1714 case ContentDistributionSpaceEvenly: |
| 1715 distributionOffset = availableFreeSpace / (numberOfGridTracks + 1); |
| 1716 positionOffset = distributionOffset; |
| 1717 return true; |
| 1718 case ContentDistributionStretch: |
| 1719 distributionOffset = 0; |
| 1720 positionOffset = 0; |
| 1721 return true; |
| 1722 case ContentDistributionDefault: |
| 1723 distributionOffset = 0; |
| 1724 positionOffset = 0; |
| 1725 return false; |
| 1726 } |
| 1727 |
| 1728 ASSERT_NOT_REACHED(); |
| 1729 return false; |
| 1730 } |
| 1731 |
| 1732 void LayoutGrid::computeContentPositionAndDistributionColumnOffset(LayoutUnit av
ailableFreeSpace, GridSizingData& sizingData) const |
| 1733 { |
| 1734 ContentPosition position = styleRef().justifyContent(); |
| 1735 ContentDistributionType distribution = styleRef().justifyContentDistribution
(); |
| 1736 // If <content-distribution> value can't be applied, 'position' will become
the associated |
| 1737 // <content-position> fallback value. |
| 1738 if (contentDistributionOffset(availableFreeSpace, position, distribution, si
zingData.columnTracks.size(), sizingData.columnsPositionOffset, sizingData.colum
nsDistributionOffset)) |
| 1739 return; |
| 1740 |
| 1741 OverflowAlignment overflow = styleRef().justifyContentOverflowAlignment(); |
1669 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) | 1742 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) |
1670 return 0; | 1743 return; |
1671 | |
1672 // FIXME: for the time being, spec states that it will always fallback for G
rids, but | |
1673 // discussion is ongoing. | |
1674 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) | |
1675 position = resolveContentDistributionFallback(distribution); | |
1676 | 1744 |
1677 switch (position) { | 1745 switch (position) { |
1678 case ContentPositionLeft: | 1746 case ContentPositionLeft: |
1679 return 0; | 1747 sizingData.columnsPositionOffset = 0; |
| 1748 return; |
1680 case ContentPositionRight: | 1749 case ContentPositionRight: |
1681 return availableFreeSpace; | 1750 sizingData.columnsPositionOffset = availableFreeSpace; |
| 1751 return; |
1682 case ContentPositionCenter: | 1752 case ContentPositionCenter: |
1683 return availableFreeSpace / 2; | 1753 sizingData.columnsPositionOffset = availableFreeSpace / 2; |
| 1754 return; |
1684 case ContentPositionFlexEnd: | 1755 case ContentPositionFlexEnd: |
1685 // Only used in flex layout, for other layout, it's equivalent to 'end'. | 1756 // Only used in flex layout, for other layout, it's equivalent to 'end'. |
1686 case ContentPositionEnd: | 1757 case ContentPositionEnd: |
1687 return offsetToEndEdge(style()->isLeftToRightDirection(), availableFreeS
pace); | 1758 sizingData.columnsPositionOffset = offsetToEndEdge(style()->isLeftToRigh
tDirection(), availableFreeSpace); |
| 1759 return; |
1688 case ContentPositionFlexStart: | 1760 case ContentPositionFlexStart: |
1689 // Only used in flex layout, for other layout, it's equivalent to 'start
'. | 1761 // Only used in flex layout, for other layout, it's equivalent to 'start
'. |
1690 case ContentPositionStart: | 1762 case ContentPositionStart: |
1691 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); | 1763 sizingData.columnsPositionOffset = offsetToStartEdge(style()->isLeftToRi
ghtDirection(), availableFreeSpace); |
| 1764 return; |
1692 case ContentPositionBaseline: | 1765 case ContentPositionBaseline: |
1693 case ContentPositionLastBaseline: | 1766 case ContentPositionLastBaseline: |
1694 // FIXME: Implement the previous values. For now, we always 'start' alig
n. | 1767 // FIXME: Implement the previous values. For now, we always 'start' alig
n. |
1695 // crbug.com/234191 | 1768 // crbug.com/234191 |
1696 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); | 1769 sizingData.columnsPositionOffset = offsetToStartEdge(style()->isLeftToRi
ghtDirection(), availableFreeSpace); |
| 1770 return; |
1697 case ContentPositionAuto: | 1771 case ContentPositionAuto: |
1698 break; | 1772 break; |
1699 } | 1773 } |
1700 | 1774 |
1701 ASSERT_NOT_REACHED(); | 1775 ASSERT_NOT_REACHED(); |
1702 return 0; | |
1703 } | 1776 } |
1704 | 1777 |
1705 LayoutUnit LayoutGrid::contentPositionAndDistributionRowOffset(LayoutUnit availa
bleFreeSpace, ContentPosition position, ContentDistributionType distribution, Ov
erflowAlignment overflow, unsigned numberOfGridTracks) const | 1778 void LayoutGrid::computeContentPositionAndDistributionRowOffset(LayoutUnit avail
ableFreeSpace, GridSizingData& sizingData) const |
1706 { | 1779 { |
| 1780 ContentPosition position = styleRef().alignContent(); |
| 1781 ContentDistributionType distribution = styleRef().alignContentDistribution()
; |
| 1782 // If <content-distribution> value can't be applied, 'position' will become
the associated |
| 1783 // <content-position> fallback value. |
| 1784 if (contentDistributionOffset(availableFreeSpace, position, distribution, si
zingData.rowTracks.size(), sizingData.rowsPositionOffset, sizingData.rowsDistrib
utionOffset)) |
| 1785 return; |
| 1786 |
| 1787 OverflowAlignment overflow = styleRef().alignContentOverflowAlignment(); |
1707 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) | 1788 if (overflow == OverflowAlignmentSafe && availableFreeSpace <= 0) |
1708 return 0; | 1789 return; |
1709 | |
1710 // FIXME: for the time being, spec states that it will always fallback for G
rids, but | |
1711 // discussion is ongoing. | |
1712 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) | |
1713 position = resolveContentDistributionFallback(distribution); | |
1714 | 1790 |
1715 switch (position) { | 1791 switch (position) { |
1716 case ContentPositionLeft: | 1792 case ContentPositionLeft: |
1717 // The align-content's axis is always orthogonal to the inline-axis. | 1793 // The align-content's axis is always orthogonal to the inline-axis. |
1718 return 0; | 1794 sizingData.rowsPositionOffset = 0; |
| 1795 return; |
1719 case ContentPositionRight: | 1796 case ContentPositionRight: |
1720 // The align-content's axis is always orthogonal to the inline-axis. | 1797 // The align-content's axis is always orthogonal to the inline-axis. |
1721 return 0; | 1798 sizingData.rowsPositionOffset = 0; |
| 1799 return; |
1722 case ContentPositionCenter: | 1800 case ContentPositionCenter: |
1723 return availableFreeSpace / 2; | 1801 sizingData.rowsPositionOffset = availableFreeSpace / 2; |
| 1802 return; |
1724 case ContentPositionFlexEnd: | 1803 case ContentPositionFlexEnd: |
1725 // Only used in flex layout, for other layout, it's equivalent to 'End'. | 1804 // Only used in flex layout, for other layout, it's equivalent to 'End'. |
1726 case ContentPositionEnd: | 1805 case ContentPositionEnd: |
1727 return availableFreeSpace; | 1806 sizingData.rowsPositionOffset = availableFreeSpace; |
| 1807 return; |
1728 case ContentPositionFlexStart: | 1808 case ContentPositionFlexStart: |
1729 // Only used in flex layout, for other layout, it's equivalent to 'Start
'. | 1809 // Only used in flex layout, for other layout, it's equivalent to 'Start
'. |
1730 case ContentPositionStart: | 1810 case ContentPositionStart: |
1731 return 0; | 1811 sizingData.rowsPositionOffset = 0; |
| 1812 return; |
1732 case ContentPositionBaseline: | 1813 case ContentPositionBaseline: |
1733 case ContentPositionLastBaseline: | 1814 case ContentPositionLastBaseline: |
1734 // FIXME: Implement the previous values. For now, we always start align. | 1815 // FIXME: Implement the previous values. For now, we always start align. |
1735 // crbug.com/234191 | 1816 // crbug.com/234191 |
1736 return 0; | 1817 sizingData.rowsPositionOffset = 0; |
| 1818 return; |
1737 case ContentPositionAuto: | 1819 case ContentPositionAuto: |
1738 break; | 1820 break; |
1739 } | 1821 } |
1740 | 1822 |
1741 ASSERT_NOT_REACHED(); | 1823 ASSERT_NOT_REACHED(); |
1742 return 0; | |
1743 } | 1824 } |
1744 | 1825 |
1745 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, LayoutS
ize contentAlignmentOffset) const | 1826 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz
ingData& sizingData) const |
1746 { | 1827 { |
1747 LayoutUnit columnPosition = columnPositionForChild(child); | 1828 LayoutUnit columnPosition = columnPositionForChild(child); |
1748 // We stored m_columnPositions's data ignoring the direction, hence we might
need now | 1829 // We stored m_columnPositions's data ignoring the direction, hence we might
need now |
1749 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. | 1830 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. |
1750 if (!style()->isLeftToRightDirection()) | 1831 if (!style()->isLeftToRightDirection()) |
1751 columnPosition = (m_columnPositions[m_columnPositions.size() - 1] + bord
erAndPaddingLogicalLeft()) - columnPosition - child.logicalWidth(); | 1832 columnPosition = (m_columnPositions[m_columnPositions.size() - 1] + bord
erAndPaddingLogicalLeft() + sizingData.columnsPositionOffset) - columnPosition -
sizingData.columnsDistributionOffset - child.logicalWidth(); |
1752 | 1833 |
1753 // The Content Alignment offset accounts for the RTL to LTR flip. | 1834 return LayoutPoint(columnPosition, rowPositionForChild(child)); |
1754 LayoutPoint childLocation(columnPosition, rowPositionForChild(child)); | |
1755 childLocation.move(contentAlignmentOffset); | |
1756 | |
1757 return childLocation; | |
1758 } | 1835 } |
1759 | 1836 |
1760 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 1837 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
1761 { | 1838 { |
1762 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1839 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
1763 } | 1840 } |
1764 | 1841 |
1765 const char* LayoutGrid::name() const | 1842 const char* LayoutGrid::name() const |
1766 { | 1843 { |
1767 if (isFloating()) | 1844 if (isFloating()) |
1768 return "LayoutGrid (floating)"; | 1845 return "LayoutGrid (floating)"; |
1769 if (isAnonymous()) | 1846 if (isAnonymous()) |
1770 return "LayoutGrid (anonymous)"; | 1847 return "LayoutGrid (anonymous)"; |
1771 if (isRelPositioned()) | 1848 if (isRelPositioned()) |
1772 return "LayoutGrid (relative positioned)"; | 1849 return "LayoutGrid (relative positioned)"; |
1773 return "LayoutGrid"; | 1850 return "LayoutGrid"; |
1774 } | 1851 } |
1775 | 1852 |
1776 } // namespace blink | 1853 } // namespace blink |
OLD | NEW |