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

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

Issue 637033003: [CSS Grid Layout] Fix positioned grid children position and size (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Minor fix in a comment Created 6 years, 2 months 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
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 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 1033
1034 void RenderGrid::dirtyGrid() 1034 void RenderGrid::dirtyGrid()
1035 { 1035 {
1036 m_grid.resize(0); 1036 m_grid.resize(0);
1037 m_gridItemCoordinate.clear(); 1037 m_gridItemCoordinate.clear();
1038 m_gridIsDirty = true; 1038 m_gridIsDirty = true;
1039 m_gridItemsOverflowingGridArea.resize(0); 1039 m_gridItemsOverflowingGridArea.resize(0);
1040 m_gridItemsIndexesMap.clear(); 1040 m_gridItemsIndexesMap.clear();
1041 } 1041 }
1042 1042
1043 bool RenderGrid::isAbsolutelyPositionedGridItemWithContainingBlockThis(const Ren derBox& child) const
Julien - ping for review 2014/11/11 17:27:35 That's better in my book (feel free to adapt / dis
1044 {
1045 return (child.style()->position() == AbsolutePosition) && (child.containingB lock() == this);
Julien - ping for review 2014/11/11 17:27:35 The parentheses are not required and we don't put
1046 }
1047
1043 void RenderGrid::layoutGridItems() 1048 void RenderGrid::layoutGridItems()
1044 { 1049 {
1045 placeItemsOnGrid(); 1050 placeItemsOnGrid();
1046 1051
1047 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 1052 GridSizingData sizingData(gridColumnCount(), gridRowCount());
1048 computeUsedBreadthOfGridTracks(ForColumns, sizingData); 1053 computeUsedBreadthOfGridTracks(ForColumns, sizingData);
1049 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks )); 1054 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks ));
1050 computeUsedBreadthOfGridTracks(ForRows, sizingData); 1055 computeUsedBreadthOfGridTracks(ForRows, sizingData);
1051 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); 1056 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks));
1052 1057
1053 populateGridPositions(sizingData); 1058 populateGridPositions(sizingData);
1054 m_gridItemsOverflowingGridArea.resize(0); 1059 m_gridItemsOverflowingGridArea.resize(0);
1055 1060
1056 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 1061 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
1057 if (child->isOutOfFlowPositioned()) {
1058 // FIXME: Absolute positioned grid items should have a special
1059 // behavior as described in the spec (crbug.com/273898):
1060 // http://www.w3.org/TR/css-grid-1/#abspos-items
1061 child->containingBlock()->insertPositionedObject(child);
1062 }
1063
1064 // Because the grid area cannot be styled, we don't need to adjust 1062 // Because the grid area cannot be styled, we don't need to adjust
1065 // the grid breadth to account for 'box-sizing'. 1063 // the grid breadth to account for 'box-sizing'.
1066 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); 1064 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit();
1067 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); 1065 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit();
1068 1066
1069 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(*child, ForColumns, sizingData.columnTracks); 1067 LayoutUnit columnExtraOffset = 0;
1070 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(*child, ForRows, sizingData.rowTracks); 1068 LayoutUnit rowExtraOffset = 0;
1069 LayoutUnit overrideContainingBlockContentLogicalWidth;
1070 LayoutUnit overrideContainingBlockContentLogicalHeight;
1071
1072 if (isAbsolutelyPositionedGridItemWithContainingBlockThis(*child)) {
Julien - ping for review 2014/11/11 17:27:35 I think the logic is off actually. RenderBlock ig
Manuel Rego 2014/11/12 13:36:34 I'm just focusing in this comment right now, as I'
Julien - ping for review 2014/11/12 19:16:57 That's a good question and something the specifica
Manuel Rego 2014/11/18 14:24:06 The title of the section was talking about grid it
1073 overrideContainingBlockContentLogicalWidth = gridAreaBreadthForAbsol utelyPositionedChild(*child, ForColumns, sizingData.columnTracks, columnExtraOff set);
1074 overrideContainingBlockContentLogicalHeight = gridAreaBreadthForAbso lutelyPositionedChild(*child, ForRows, sizingData.rowTracks, rowExtraOffset);
1075 } else {
1076 overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChild (*child, ForColumns, sizingData.columnTracks);
1077 overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChil d(*child, ForRows, sizingData.rowTracks);
1078 }
1079
1080 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth);
1081 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight);
1082
1083 if (child->isOutOfFlowPositioned()) {
1084 child->containingBlock()->insertPositionedObject(child);
1085
1086 if (isAbsolutelyPositionedGridItemWithContainingBlockThis(*child)) {
1087 bool containerHasHorizontalWritingMode = isHorizontalWritingMode ();
1088 LayoutPoint position = LayoutPoint(startOfColumnForChild(*child) , startOfRowForChild(*child));
1089
1090 RenderLayer* childLayer = child->layer();
1091 // Set the layer position taking into account the extra size
1092 // increased in RenderGrid::gridAreaBreadthForChild() due to the
1093 // positioned items particularities.
1094 childLayer->setStaticInlinePosition(containerHasHorizontalWritin gMode ? position.x() - columnExtraOffset : position.y() - rowExtraOffset);
1095 childLayer->setStaticBlockPosition(containerHasHorizontalWriting Mode ? position.y() - rowExtraOffset : position.x() - columnExtraOffset);
1096 }
1097
1098 continue;
1099 }
1071 1100
1072 SubtreeLayoutScope layoutScope(*child); 1101 SubtreeLayoutScope layoutScope(*child);
1073 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) 1102 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight()))
1074 layoutScope.setNeedsLayout(child); 1103 layoutScope.setNeedsLayout(child);
1075 1104
1076 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth);
1077 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight);
1078
1079 // FIXME: Grid items should stretch to fill their cells. Once we 1105 // FIXME: Grid items should stretch to fill their cells. Once we
1080 // implement grid-{column,row}-align, we can also shrink to fit. For 1106 // implement grid-{column,row}-align, we can also shrink to fit. For
1081 // now, just size as if we were a regular child. 1107 // now, just size as if we were a regular child.
1082 child->layoutIfNeeded(); 1108 child->layoutIfNeeded();
1083 1109
1084 #if ENABLE(ASSERT) 1110 #if ENABLE(ASSERT)
1085 const GridCoordinate& coordinate = cachedGridCoordinate(*child); 1111 const GridCoordinate& coordinate = cachedGridCoordinate(*child);
1086 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); 1112 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size());
1087 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); 1113 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size());
1088 #endif 1114 #endif
(...skipping 13 matching lines...) Expand all
1102 1128
1103 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight()); 1129 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight());
1104 } 1130 }
1105 1131
1106 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox& gridItem) const 1132 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox& gridItem) const
1107 { 1133 {
1108 ASSERT(m_gridItemCoordinate.contains(&gridItem)); 1134 ASSERT(m_gridItemCoordinate.contains(&gridItem));
1109 return m_gridItemCoordinate.get(&gridItem); 1135 return m_gridItemCoordinate.get(&gridItem);
1110 } 1136 }
1111 1137
1138 static LayoutUnit computeGridAreaBreadth(const GridSpan& span, const Vector<Grid Track>& tracks, LayoutUnit* extraInitialOffset = 0, bool startIsAuto = false, Gr idResolvedPosition* originalInitialPosition = 0)
1139 {
1140 LayoutUnit gridAreaBreadth = 0;
1141 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) {
1142 LayoutUnit trackBreadth = tracks[trackPosition.toInt()].m_usedBreadth;
1143 gridAreaBreadth += trackBreadth;
1144 if (extraInitialOffset && startIsAuto && trackPosition < *originalInitia lPosition)
1145 *extraInitialOffset += trackBreadth;
1146 }
1147 return gridAreaBreadth;
1148 }
1149
1112 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const 1150 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const
1113 { 1151 {
1114 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1152 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1115 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; 1153 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows;
1154 return computeGridAreaBreadth(span, tracks);
1155 }
1156
1157 LayoutUnit RenderGrid::gridAreaBreadthForAbsolutelyPositionedChild(const RenderB ox& child, GridTrackSizingDirection direction, const Vector<GridTrack>& tracks, LayoutUnit& extraInitialOffset) const
1158 {
1159 ASSERT(isAbsolutelyPositionedGridItemWithContainingBlockThis(child));
1160
1116 LayoutUnit gridAreaBreadth = 0; 1161 LayoutUnit gridAreaBreadth = 0;
1117 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) 1162 bool startIsAuto = false;
1118 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; 1163 bool endIsAuto = false;
1164 // For absolutely positioned items the containing block corresponds to the
1165 // padding edges of the grid. So, we need to increase the breadth if the
1166 // positions are auto.
1167 if (direction == ForColumns) {
1168 if (child.style()->gridColumnStart().isAuto()) {
1169 startIsAuto = true;
1170 gridAreaBreadth += paddingLeft();
1171 extraInitialOffset += paddingLeft();
1172 }
1173 if (child.style()->gridColumnEnd().isAuto()) {
1174 endIsAuto = true;
1175 gridAreaBreadth += paddingRight();
1176 }
1177 } else {
1178 if (child.style()->gridRowStart().isAuto()) {
1179 startIsAuto = true;
1180 gridAreaBreadth += paddingTop();
1181 extraInitialOffset += paddingTop();
1182 }
1183 if (child.style()->gridRowEnd().isAuto()) {
1184 endIsAuto = true;
1185 gridAreaBreadth += paddingBottom();
1186 }
1187 }
1188
1189 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1190 GridResolvedPosition initialPosition = (direction == ForColumns) ? coordinat e.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPosition;
1191 GridResolvedPosition originalInitialPosition = initialPosition;
1192 GridResolvedPosition finalPosition = (direction == ForColumns) ? coordinate. columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition;
1193
1194 if (startIsAuto)
1195 initialPosition = GridResolvedPosition(0);
1196 if (endIsAuto)
1197 finalPosition = GridResolvedPosition((direction == ForColumns ? gridColu mnCount() : gridRowCount()) - 1);
1198
1199 gridAreaBreadth += computeGridAreaBreadth(GridSpan(initialPosition, finalPos ition), tracks, &extraInitialOffset, startIsAuto, &originalInitialPosition);
1119 return gridAreaBreadth; 1200 return gridAreaBreadth;
1120 } 1201 }
1121 1202
1122 void RenderGrid::populateGridPositions(const GridSizingData& sizingData) 1203 void RenderGrid::populateGridPositions(const GridSizingData& sizingData)
1123 { 1204 {
1124 m_columnPositions.resize(sizingData.columnTracks.size() + 1); 1205 m_columnPositions.resize(sizingData.columnTracks.size() + 1);
1125 m_columnPositions[0] = borderAndPaddingStart(); 1206 m_columnPositions[0] = borderAndPaddingStart();
1126 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) 1207 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i)
1127 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack s[i].m_usedBreadth; 1208 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack s[i].m_usedBreadth;
1128 1209
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 if (isOutOfFlowPositioned()) 1469 if (isOutOfFlowPositioned())
1389 return "RenderGrid (positioned)"; 1470 return "RenderGrid (positioned)";
1390 if (isAnonymous()) 1471 if (isAnonymous())
1391 return "RenderGrid (generated)"; 1472 return "RenderGrid (generated)";
1392 if (isRelPositioned()) 1473 if (isRelPositioned())
1393 return "RenderGrid (relative positioned)"; 1474 return "RenderGrid (relative positioned)";
1394 return "RenderGrid"; 1475 return "RenderGrid";
1395 } 1476 }
1396 1477
1397 } // namespace blink 1478 } // namespace blink
OLDNEW
« Source/core/rendering/RenderBox.cpp ('K') | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698