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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); | 499 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); |
500 } | 500 } |
501 } | 501 } |
502 } | 502 } |
503 | 503 |
504 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 504 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
505 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 505 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
506 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); | 506 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
507 | 507 |
508 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde
x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()
); | 508 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde
x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()
); |
| 509 availableLogicalSpace -= tracks[trackIndex].m_usedBreadth; |
509 } | 510 } |
| 511 |
| 512 // FIXME: Should ASSERT flexible tracks exhaust the availableLogicalSpace ?
(see issue 739613002). |
510 } | 513 } |
511 | 514 |
512 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const | 515 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const |
513 { | 516 { |
514 if (gridLength.isFlex()) | 517 if (gridLength.isFlex()) |
515 return 0; | 518 return 0; |
516 | 519 |
517 const Length& trackLength = gridLength.length(); | 520 const Length& trackLength = gridLength.length(); |
518 ASSERT(!trackLength.isAuto()); | 521 ASSERT(!trackLength.isAuto()); |
519 if (trackLength.isSpecified()) | 522 if (trackLength.isSpecified()) |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 m_gridItemCoordinate.clear(); | 1083 m_gridItemCoordinate.clear(); |
1081 m_gridIsDirty = true; | 1084 m_gridIsDirty = true; |
1082 m_gridItemsOverflowingGridArea.resize(0); | 1085 m_gridItemsOverflowingGridArea.resize(0); |
1083 m_gridItemsIndexesMap.clear(); | 1086 m_gridItemsIndexesMap.clear(); |
1084 } | 1087 } |
1085 | 1088 |
1086 void RenderGrid::layoutGridItems() | 1089 void RenderGrid::layoutGridItems() |
1087 { | 1090 { |
1088 placeItemsOnGrid(); | 1091 placeItemsOnGrid(); |
1089 | 1092 |
| 1093 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| 1094 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); |
1090 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 1095 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
1091 computeUsedBreadthOfGridTracks(ForColumns, sizingData); | 1096 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu
mns); |
1092 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); | 1097 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks
)); |
1093 computeUsedBreadthOfGridTracks(ForRows, sizingData); | 1098 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); |
1094 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); | 1099 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); |
1095 | 1100 |
1096 populateGridPositions(sizingData); | 1101 populateGridPositions(sizingData, availableSpaceForColumns, availableSpaceFo
rRows); |
1097 m_gridItemsOverflowingGridArea.resize(0); | 1102 m_gridItemsOverflowingGridArea.resize(0); |
1098 | 1103 |
1099 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 1104 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
1100 if (child->isOutOfFlowPositioned()) { | 1105 if (child->isOutOfFlowPositioned()) { |
1101 // FIXME: Absolute positioned grid items should have a special | 1106 // FIXME: Absolute positioned grid items should have a special |
1102 // behavior as described in the spec (crbug.com/273898): | 1107 // behavior as described in the spec (crbug.com/273898): |
1103 // http://www.w3.org/TR/css-grid-1/#abspos-items | 1108 // http://www.w3.org/TR/css-grid-1/#abspos-items |
1104 child->containingBlock()->insertPositionedObject(child); | 1109 child->containingBlock()->insertPositionedObject(child); |
1105 } | 1110 } |
1106 | 1111 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const | 1159 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const |
1155 { | 1160 { |
1156 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1161 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1157 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; | 1162 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; |
1158 LayoutUnit gridAreaBreadth = 0; | 1163 LayoutUnit gridAreaBreadth = 0; |
1159 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) | 1164 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.
end(); ++trackPosition) |
1160 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; | 1165 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; |
1161 return gridAreaBreadth; | 1166 return gridAreaBreadth; |
1162 } | 1167 } |
1163 | 1168 |
1164 void RenderGrid::populateGridPositions(const GridSizingData& sizingData) | 1169 void RenderGrid::populateGridPositions(const GridSizingData& sizingData, LayoutU
nit availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
1165 { | 1170 { |
1166 m_columnPositions.resize(sizingData.columnTracks.size() + 1); | 1171 unsigned numberOfColumnTracks = sizingData.columnTracks.size(); |
1167 m_columnPositions[0] = borderAndPaddingStart(); | 1172 LayoutUnit columnOffset = contentPositionAndDistributionOffset(availableSpac
eForColumns, style()->justifyContent(), style()->justifyContentDistribution(), n
umberOfColumnTracks); |
| 1173 |
| 1174 m_columnPositions.resize(numberOfColumnTracks + 1); |
| 1175 m_columnPositions[0] = borderAndPaddingStart() + columnOffset; |
1168 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) | 1176 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
1169 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; | 1177 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; |
1170 | 1178 |
1171 m_rowPositions.resize(sizingData.rowTracks.size() + 1); | 1179 m_rowPositions.resize(sizingData.rowTracks.size() + 1); |
1172 m_rowPositions[0] = borderAndPaddingBefore(); | 1180 m_rowPositions[0] = borderAndPaddingBefore(); |
1173 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1181 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) |
1174 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; | 1182 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; |
1175 } | 1183 } |
1176 | 1184 |
1177 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) | 1185 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 // FIXME: Implement the ItemPositionBaseline value. For now, we always s
tart align the child. | 1497 // FIXME: Implement the ItemPositionBaseline value. For now, we always s
tart align the child. |
1490 return startOfRowForChild(child); | 1498 return startOfRowForChild(child); |
1491 case ItemPositionAuto: | 1499 case ItemPositionAuto: |
1492 break; | 1500 break; |
1493 } | 1501 } |
1494 | 1502 |
1495 ASSERT_NOT_REACHED(); | 1503 ASSERT_NOT_REACHED(); |
1496 return 0; | 1504 return 0; |
1497 } | 1505 } |
1498 | 1506 |
| 1507 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp
e distribution) |
| 1508 { |
| 1509 switch (distribution) { |
| 1510 case ContentDistributionSpaceBetween: |
| 1511 return ContentPositionStart; |
| 1512 case ContentDistributionSpaceAround: |
| 1513 return ContentPositionCenter; |
| 1514 case ContentDistributionSpaceEvenly: |
| 1515 return ContentPositionCenter; |
| 1516 case ContentDistributionStretch: |
| 1517 return ContentPositionStart; |
| 1518 case ContentDistributionDefault: |
| 1519 return ContentPositionAuto; |
| 1520 } |
| 1521 |
| 1522 ASSERT_NOT_REACHED(); |
| 1523 return ContentPositionAuto; |
| 1524 } |
| 1525 |
| 1526 static inline LayoutUnit offsetToStartEdge(bool isLeftToRight, LayoutUnit availa
bleSpace) |
| 1527 { |
| 1528 return isLeftToRight ? LayoutUnit(0) : availableSpace; |
| 1529 } |
| 1530 |
| 1531 static inline LayoutUnit offsetToEndEdge(bool isLeftToRight, LayoutUnit availabl
eSpace) |
| 1532 { |
| 1533 return !isLeftToRight ? LayoutUnit(0) : availableSpace; |
| 1534 } |
| 1535 |
| 1536 LayoutUnit RenderGrid::contentPositionAndDistributionOffset(LayoutUnit available
FreeSpace, ContentPosition position, ContentDistributionType distribution, unsig
ned numberOfGridTracks) const |
| 1537 { |
| 1538 if (availableFreeSpace <= 0) |
| 1539 return 0; |
| 1540 |
| 1541 // FIXME: for the time being, spec states that it will always fallback for G
rids, but |
| 1542 // discussion is ongoing. |
| 1543 if (distribution != ContentDistributionDefault && position == ContentPositio
nAuto) |
| 1544 position = resolveContentDistributionFallback(distribution); |
| 1545 |
| 1546 // FIXME: still pending of implementing support for the <overflow-position>
keyword |
| 1547 // in justify-content and aling-content properties. |
| 1548 switch (position) { |
| 1549 case ContentPositionLeft: |
| 1550 // If the property's axis is not parallel with the inline axis, this is
equivalent to ‘start’. |
| 1551 if (!isHorizontalWritingMode()) |
| 1552 return offsetToStartEdge(style()->isLeftToRightDirection(), availabl
eFreeSpace); |
| 1553 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); |
| 1554 case ContentPositionRight: |
| 1555 // If the property's axis is not parallel with the inline axis, this is
equivalent to ‘start’. |
| 1556 if (!isHorizontalWritingMode()) |
| 1557 return offsetToStartEdge(style()->isLeftToRightDirection(), availabl
eFreeSpace); |
| 1558 return offsetToEndEdge(style()->isLeftToRightDirection(), availableFreeS
pace); |
| 1559 case ContentPositionCenter: |
| 1560 return availableFreeSpace / 2; |
| 1561 case ContentPositionFlexEnd: |
| 1562 // Only used in flex layout, for other layout, it's equivalent to 'End'. |
| 1563 case ContentPositionEnd: |
| 1564 return offsetToEndEdge(style()->isLeftToRightDirection(), availableFreeS
pace); |
| 1565 case ContentPositionFlexStart: |
| 1566 // Only used in flex layout, for other layout, it's equivalent to 'Start
'. |
| 1567 case ContentPositionStart: |
| 1568 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); |
| 1569 case ContentPositionBaseline: |
| 1570 case ContentPositionLastBaseline: |
| 1571 // FIXME: Implement the previous values. For now, we always start align. |
| 1572 // crbug.com/234191 |
| 1573 return offsetToStartEdge(style()->isLeftToRightDirection(), availableFre
eSpace); |
| 1574 case ContentPositionAuto: |
| 1575 break; |
| 1576 } |
| 1577 |
| 1578 ASSERT_NOT_REACHED(); |
| 1579 return 0; |
| 1580 } |
| 1581 |
1499 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const | 1582 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const |
1500 { | 1583 { |
1501 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); | 1584 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); |
1502 } | 1585 } |
1503 | 1586 |
1504 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 1587 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
1505 { | 1588 { |
1506 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1589 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
1507 } | 1590 } |
1508 | 1591 |
1509 const char* RenderGrid::renderName() const | 1592 const char* RenderGrid::renderName() const |
1510 { | 1593 { |
1511 if (isFloating()) | 1594 if (isFloating()) |
1512 return "RenderGrid (floating)"; | 1595 return "RenderGrid (floating)"; |
1513 if (isOutOfFlowPositioned()) | 1596 if (isOutOfFlowPositioned()) |
1514 return "RenderGrid (positioned)"; | 1597 return "RenderGrid (positioned)"; |
1515 if (isAnonymous()) | 1598 if (isAnonymous()) |
1516 return "RenderGrid (generated)"; | 1599 return "RenderGrid (generated)"; |
1517 if (isRelPositioned()) | 1600 if (isRelPositioned()) |
1518 return "RenderGrid (relative positioned)"; | 1601 return "RenderGrid (relative positioned)"; |
1519 return "RenderGrid"; | 1602 return "RenderGrid"; |
1520 } | 1603 } |
1521 | 1604 |
1522 } // namespace blink | 1605 } // namespace blink |
OLD | NEW |