Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: Source/core/rendering/RenderGrid.cpp

Issue 706903003: [CSS Grid Layout] Partial implementation of justify-content for Grid. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed unneeded childPosition variable. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 m_gridItemCoordinate.clear(); 1080 m_gridItemCoordinate.clear();
1081 m_gridIsDirty = true; 1081 m_gridIsDirty = true;
1082 m_gridItemsOverflowingGridArea.resize(0); 1082 m_gridItemsOverflowingGridArea.resize(0);
1083 m_gridItemsIndexesMap.clear(); 1083 m_gridItemsIndexesMap.clear();
1084 } 1084 }
1085 1085
1086 void RenderGrid::layoutGridItems() 1086 void RenderGrid::layoutGridItems()
1087 { 1087 {
1088 placeItemsOnGrid(); 1088 placeItemsOnGrid();
1089 1089
1090 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
1091 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde rPadding);
1090 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 1092 GridSizingData sizingData(gridColumnCount(), gridRowCount());
1091 computeUsedBreadthOfGridTracks(ForColumns, sizingData); 1093 computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColu mns);
1092 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks )); 1094 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks ));
1093 computeUsedBreadthOfGridTracks(ForRows, sizingData); 1095 computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows);
1094 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); 1096 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks));
1095 1097
1096 populateGridPositions(sizingData); 1098 populateGridPositions(sizingData, availableSpaceForColumns, availableSpaceFo rRows);
1097 m_gridItemsOverflowingGridArea.resize(0); 1099 m_gridItemsOverflowingGridArea.resize(0);
1098 1100
1099 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 1101 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
1100 if (child->isOutOfFlowPositioned()) { 1102 if (child->isOutOfFlowPositioned()) {
1101 // FIXME: Absolute positioned grid items should have a special 1103 // FIXME: Absolute positioned grid items should have a special
1102 // behavior as described in the spec (crbug.com/273898): 1104 // behavior as described in the spec (crbug.com/273898):
1103 // http://www.w3.org/TR/css-grid-1/#abspos-items 1105 // http://www.w3.org/TR/css-grid-1/#abspos-items
1104 child->containingBlock()->insertPositionedObject(child); 1106 child->containingBlock()->insertPositionedObject(child);
1105 } 1107 }
1106 1108
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const 1156 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const
1155 { 1157 {
1156 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1158 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1157 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; 1159 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows;
1158 LayoutUnit gridAreaBreadth = 0; 1160 LayoutUnit gridAreaBreadth = 0;
1159 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) 1161 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition)
1160 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; 1162 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth;
1161 return gridAreaBreadth; 1163 return gridAreaBreadth;
1162 } 1164 }
1163 1165
1164 void RenderGrid::populateGridPositions(const GridSizingData& sizingData) 1166 void RenderGrid::populateGridPositions(const GridSizingData& sizingData, LayoutU nit availableSpaceForColumns, LayoutUnit availableSpaceForRows)
1165 { 1167 {
1166 m_columnPositions.resize(sizingData.columnTracks.size() + 1); 1168 unsigned numberOfColumnTracks = sizingData.columnTracks.size();
1167 m_columnPositions[0] = borderAndPaddingStart(); 1169 LayoutUnit columnOffset = contentPositionAndDistributionOffset(availableSpac eForColumns, style()->justifyContent(), style()->justifyContentDistribution(), n umberOfColumnTracks);
1170
1171 m_columnPositions.resize(numberOfColumnTracks + 1);
1172 m_columnPositions[0] = borderAndPaddingStart() + columnOffset;
1168 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) 1173 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; 1174 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack s[i].m_usedBreadth;
1170 1175
1171 m_rowPositions.resize(sizingData.rowTracks.size() + 1); 1176 m_rowPositions.resize(sizingData.rowTracks.size() + 1);
1172 m_rowPositions[0] = borderAndPaddingBefore(); 1177 m_rowPositions[0] = borderAndPaddingBefore();
1173 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) 1178 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; 1179 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us edBreadth;
1175 } 1180 }
1176 1181
1177 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth) 1182 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth)
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. 1494 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child.
1490 return startOfRowForChild(child); 1495 return startOfRowForChild(child);
1491 case ItemPositionAuto: 1496 case ItemPositionAuto:
1492 break; 1497 break;
1493 } 1498 }
1494 1499
1495 ASSERT_NOT_REACHED(); 1500 ASSERT_NOT_REACHED();
1496 return 0; 1501 return 0;
1497 } 1502 }
1498 1503
1504 LayoutUnit static contentDistributionOffset(LayoutUnit availableFreeSpace, Conte ntPosition& fallbackPosition, ContentDistributionType distribution, unsigned num berOfItems)
Julien - ping for review 2014/11/13 01:37:24 Note that numberOfItems is not great as it could r
jfernandez 2014/11/13 12:22:35 Well, I tried to use the term defined in the Box A
Julien - ping for review 2014/11/13 16:43:31 numberOfTracks is a good name, even better numberO
jfernandez 2014/11/14 15:32:32 Done.
1505 {
1506 ASSERT(numberOfItems > 0);
1507
1508 switch (distribution) {
1509 case ContentDistributionSpaceBetween:
1510 if (fallbackPosition == ContentPositionAuto)
1511 fallbackPosition = ContentPositionStart;
1512 // FIXME: for the time being, spec states that it will always fallback f or Grids, but
1513 // discussion is ongoing.
1514 return -1;
1515 case ContentDistributionSpaceAround:
1516 if (fallbackPosition == ContentPositionAuto)
1517 fallbackPosition = ContentPositionCenter;
1518 // FIXME: for the time being, spec states that it will always fallback f or Grids, but
1519 // discussion is ongoing.
1520 return -1;
1521 case ContentDistributionSpaceEvenly:
1522 if (fallbackPosition == ContentPositionAuto)
1523 fallbackPosition = ContentPositionCenter;
1524 // FIXME: for the time being, spec states that it will always fallback f or Grids, but
1525 // discussion is ongoing.
1526 return -1;
1527 case ContentDistributionStretch:
1528 if (fallbackPosition == ContentPositionAuto)
1529 fallbackPosition = ContentPositionStart;
1530 // FIXME: for the time being, spec states that it will always fallback f or Grids, but
1531 // discussion is ongoing.
1532 return -1;
1533 case ContentDistributionDefault:
1534 return -1;
1535 default:
1536 ASSERT_NOT_REACHED();
1537 return -1;
1538 }
1539
1540 return -1;
1541 }
1542
1543 LayoutUnit RenderGrid::contentPositionAndDistributionOffset(LayoutUnit available FreeSpace, ContentPosition position, ContentDistributionType distribution, unsig ned numberOfItems) const
1544 {
1545 LayoutUnit offset = contentDistributionOffset(availableFreeSpace, position, distribution, numberOfItems);
Julien - ping for review 2014/11/13 01:37:24 This function is stubbed so it's hard to see what
jfernandez 2014/11/13 12:22:35 Acknowledged.
1546 if (offset >= 0)
1547 return offset;
1548
1549 switch (position) {
1550 case ContentPositionLeft:
1551 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1552 if (!isHorizontalWritingMode())
1553 return 0;
1554 if (style()->isLeftToRightDirection())
1555 return 0;
1556 return availableFreeSpace;
Julien - ping for review 2014/11/13 01:37:24 I think this should account for the children's siz
jfernandez 2014/11/13 12:22:35 I don't understand what you mean here; content ali
Julien - ping for review 2014/11/13 16:43:31 I didn't mean as we should change the grid items'
jfernandez 2014/11/14 15:32:32 I'm not sure whether you notice that availableSpac
Julien - ping for review 2014/11/18 16:14:36 I missed that. With that fact, the logic makes mor
jfernandez 2014/11/20 11:59:39 Done.
1557 case ContentPositionRight:
1558 // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’.
1559 if (!isHorizontalWritingMode())
1560 return 0;
1561 if (style()->isLeftToRightDirection())
1562 return availableFreeSpace;
1563 return 0;
1564 case ContentPositionCenter:
1565 return availableFreeSpace / 2;
1566 case ContentPositionFlexEnd:
1567 // Only used in flex layout, for other layout, it's equivalent to 'End'.
1568 case ContentPositionEnd:
1569 return availableFreeSpace;
1570 case ContentPositionFlexStart:
1571 // Only used in flex layout, for other layout, it's equivalent to 'Start '.
1572 case ContentPositionStart:
1573 return 0;
1574 case ContentPositionBaseline:
1575 case ContentPositionLastBaseline:
1576 // FIXME: Implement the previous values. For now, we always start align.
1577 return 0;
1578 default:
Julien - ping for review 2014/11/13 01:37:24 We seems to be missing one case ContentPositionAut
jfernandez 2014/11/13 12:22:35 Auto value is resolved by the StyleAdjuster. It co
Julien - ping for review 2014/11/13 16:43:31 I don't think StyleAdjuster would work as the comp
jfernandez 2014/11/14 15:32:32 Acknowledged.
1579 ASSERT_NOT_REACHED();
1580 }
1581
1582 return 0;
1583 }
1584
1499 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const 1585 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const
1500 { 1586 {
1501 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child) ); 1587 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child) );
1502 } 1588 }
1503 1589
1504 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set) 1590 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set)
1505 { 1591 {
1506 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1592 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1507 } 1593 }
1508 1594
1509 const char* RenderGrid::renderName() const 1595 const char* RenderGrid::renderName() const
1510 { 1596 {
1511 if (isFloating()) 1597 if (isFloating())
1512 return "RenderGrid (floating)"; 1598 return "RenderGrid (floating)";
1513 if (isOutOfFlowPositioned()) 1599 if (isOutOfFlowPositioned())
1514 return "RenderGrid (positioned)"; 1600 return "RenderGrid (positioned)";
1515 if (isAnonymous()) 1601 if (isAnonymous())
1516 return "RenderGrid (generated)"; 1602 return "RenderGrid (generated)";
1517 if (isRelPositioned()) 1603 if (isRelPositioned())
1518 return "RenderGrid (relative positioned)"; 1604 return "RenderGrid (relative positioned)";
1519 return "RenderGrid"; 1605 return "RenderGrid";
1520 } 1606 }
1521 1607
1522 } // namespace blink 1608 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698