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