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