Chromium Code Reviews| 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); | 609 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); |
| 610 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); | 610 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); |
| 611 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent) : oldMaxTrackBreadth); | 611 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent) : oldMaxTrackBreadth); |
| 612 } | 612 } |
| 613 | 613 |
| 614 return trackSize; | 614 return trackSize; |
| 615 } | 615 } |
| 616 | 616 |
| 617 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack> & columnTracks) | 617 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack> & columnTracks) |
| 618 { | 618 { |
| 619 child.clearOverrideLogicalContentHeight(); | |
|
Julien - ping for review
2014/10/08 15:21:47
I don't understand the need for this as we do the
jfernandez
2014/10/12 22:40:27
Well, if I understood it correctly, OverrideContai
Julien - ping for review
2014/10/21 00:43:12
You're right, I misread. RenderGrid needs to prete
jfernandez
2014/10/22 09:31:37
Done.
| |
| 620 | |
| 619 SubtreeLayoutScope layoutScope(child); | 621 SubtreeLayoutScope layoutScope(child); |
| 620 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit(); | 622 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit(); |
| 621 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); | 623 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); |
| 622 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) | 624 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) |
| 623 layoutScope.setNeedsLayout(&child); | 625 layoutScope.setNeedsLayout(&child); |
| 624 | 626 |
| 625 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth); | 627 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth); |
| 626 // If |child| has a percentage logical height, we shouldn't let it override its intrinsic height, which is | 628 // If |child| has a percentage logical height, we shouldn't let it override its intrinsic height, which is |
| 627 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). | 629 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). |
| 628 child.setOverrideContainingBlockContentLogicalHeight(-1); | 630 child.setOverrideContainingBlockContentLogicalHeight(-1); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 SubtreeLayoutScope layoutScope(*child); | 1068 SubtreeLayoutScope layoutScope(*child); |
| 1067 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1069 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
| 1068 layoutScope.setNeedsLayout(child); | 1070 layoutScope.setNeedsLayout(child); |
| 1069 | 1071 |
| 1070 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 1072 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
| 1071 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 1073 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
| 1072 | 1074 |
| 1073 // FIXME: Grid items should stretch to fill their cells. Once we | 1075 // FIXME: Grid items should stretch to fill their cells. Once we |
| 1074 // implement grid-{column,row}-align, we can also shrink to fit. For | 1076 // implement grid-{column,row}-align, we can also shrink to fit. For |
| 1075 // now, just size as if we were a regular child. | 1077 // now, just size as if we were a regular child. |
| 1078 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont entLogicalHeight); | |
| 1079 | |
| 1076 child->layoutIfNeeded(); | 1080 child->layoutIfNeeded(); |
| 1077 | 1081 |
| 1078 #if ENABLE(ASSERT) | 1082 #if ENABLE(ASSERT) |
| 1079 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1083 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
| 1080 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); | 1084 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); |
| 1081 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); | 1085 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); |
| 1082 #endif | 1086 #endif |
| 1083 child->setLogicalLocation(findChildLogicalPosition(*child)); | 1087 child->setLogicalLocation(findChildLogicalPosition(*child)); |
| 1084 | 1088 |
| 1085 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is | 1089 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1096 | 1100 |
| 1097 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight()); | 1101 setLogicalHeight(logicalHeight() + borderAndPaddingLogicalHeight()); |
| 1098 } | 1102 } |
| 1099 | 1103 |
| 1100 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox& gridItem) const | 1104 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox& gridItem) const |
| 1101 { | 1105 { |
| 1102 ASSERT(m_gridItemCoordinate.contains(&gridItem)); | 1106 ASSERT(m_gridItemCoordinate.contains(&gridItem)); |
| 1103 return m_gridItemCoordinate.get(&gridItem); | 1107 return m_gridItemCoordinate.get(&gridItem); |
| 1104 } | 1108 } |
| 1105 | 1109 |
| 1110 // FIXME: We should move this logic to the StyleAdjuster or the StyleBuilder. | |
| 1111 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende rStyle* childStyle) | |
| 1112 { | |
| 1113 ItemPosition align = childStyle->alignSelf(); | |
| 1114 // The auto keyword computes to the parent's align-items computed value, or to "stretch", if not set or "auto". | |
| 1115 if (align == ItemPositionAuto) | |
| 1116 align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionSt retch : parentStyle->alignItems(); | |
| 1117 return align; | |
| 1118 } | |
| 1119 | |
| 1120 void RenderGrid::applyStretchAlignmentToChildIfNeeded(RenderBox& child, LayoutUn it overrideLogicalContentHeight) | |
| 1121 { | |
| 1122 if (child.style()->logicalHeight().isAuto() && resolveAlignment(style(), chi ld.style()) == ItemPositionStretch) | |
| 1123 child.setOverrideLogicalContentHeight(overrideLogicalContentHeight); | |
|
Julien - ping for review
2014/10/08 15:21:47
This is good for a first pass but it's not totally
jfernandez
2014/10/12 22:40:27
Acknowledged.
| |
| 1124 } | |
| 1125 | |
| 1106 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const | 1126 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const |
| 1107 { | 1127 { |
| 1108 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1128 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1109 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; | 1129 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor dinate.rows; |
| 1110 LayoutUnit gridAreaBreadth = 0; | 1130 LayoutUnit gridAreaBreadth = 0; |
| 1111 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) | 1131 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) |
| 1112 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; | 1132 gridAreaBreadth += tracks[trackPosition.toInt()].m_usedBreadth; |
| 1113 return gridAreaBreadth; | 1133 return gridAreaBreadth; |
| 1114 } | 1134 } |
| 1115 | 1135 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1239 case ItemPositionCenter: | 1259 case ItemPositionCenter: |
| 1240 return centeredColumnPositionForChild(child); | 1260 return centeredColumnPositionForChild(child); |
| 1241 case ItemPositionStart: | 1261 case ItemPositionStart: |
| 1242 return columnPositionAlignedWithGridContainerStart(child); | 1262 return columnPositionAlignedWithGridContainerStart(child); |
| 1243 case ItemPositionEnd: | 1263 case ItemPositionEnd: |
| 1244 return columnPositionAlignedWithGridContainerEnd(child); | 1264 return columnPositionAlignedWithGridContainerEnd(child); |
| 1245 | 1265 |
| 1246 case ItemPositionAuto: | 1266 case ItemPositionAuto: |
| 1247 break; | 1267 break; |
| 1248 case ItemPositionStretch: | 1268 case ItemPositionStretch: |
| 1269 return startOfColumnForChild(child); | |
| 1249 case ItemPositionBaseline: | 1270 case ItemPositionBaseline: |
| 1250 case ItemPositionLastBaseline: | 1271 case ItemPositionLastBaseline: |
| 1251 // FIXME: Implement the previous values. For now, we always start align the child. | 1272 // FIXME: Implement the previous values. For now, we always start align the child. |
| 1252 return startOfColumnForChild(child); | 1273 return startOfColumnForChild(child); |
| 1253 } | 1274 } |
| 1254 | 1275 |
| 1255 ASSERT_NOT_REACHED(); | 1276 ASSERT_NOT_REACHED(); |
| 1256 return 0; | 1277 return 0; |
| 1257 } | 1278 } |
| 1258 | 1279 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1286 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1307 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1287 | 1308 |
| 1288 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. | 1309 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. |
| 1289 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()] + marginBeforeForChild(&child); | 1310 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi on.toInt()] + marginBeforeForChild(&child); |
| 1290 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; | 1311 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n ext().toInt()]; |
| 1291 | 1312 |
| 1292 // FIXME: This should account for the grid item's <overflow-position>. | 1313 // FIXME: This should account for the grid item's <overflow-position>. |
| 1293 return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.lo gicalHeight()) / 2; | 1314 return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.lo gicalHeight()) / 2; |
| 1294 } | 1315 } |
| 1295 | 1316 |
| 1296 // FIXME: We should move this logic to the StyleAdjuster or the StyleBuilder. | |
| 1297 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende rStyle* childStyle) | |
| 1298 { | |
| 1299 ItemPosition align = childStyle->alignSelf(); | |
| 1300 // The auto keyword computes to the parent's align-items computed value, or to "stretch", if not set or "auto". | |
| 1301 if (align == ItemPositionAuto) | |
| 1302 align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionSt retch : parentStyle->alignItems(); | |
| 1303 return align; | |
| 1304 } | |
| 1305 | |
|
Julien - ping for review
2014/10/08 15:21:47
Instead of moving this code, can we just move appl
| |
| 1306 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const | 1317 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
| 1307 { | 1318 { |
| 1308 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1319 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
| 1309 ItemPosition alignSelf = resolveAlignment(style(), child.style()); | 1320 ItemPosition alignSelf = resolveAlignment(style(), child.style()); |
| 1310 | 1321 |
| 1311 switch (alignSelf) { | 1322 switch (alignSelf) { |
| 1312 case ItemPositionSelfStart: | 1323 case ItemPositionSelfStart: |
| 1313 // If orthogonal writing-modes, this computes to 'Start'. | 1324 // If orthogonal writing-modes, this computes to 'Start'. |
| 1314 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | 1325 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
| 1315 if (hasOrthogonalWritingMode) | 1326 if (hasOrthogonalWritingMode) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 return centeredRowPositionForChild(child); | 1365 return centeredRowPositionForChild(child); |
| 1355 // Only used in flex layout, for other layout, it's equivalent to 'Start '. | 1366 // Only used in flex layout, for other layout, it's equivalent to 'Start '. |
| 1356 case ItemPositionFlexStart: | 1367 case ItemPositionFlexStart: |
| 1357 case ItemPositionStart: | 1368 case ItemPositionStart: |
| 1358 return startOfRowForChild(child); | 1369 return startOfRowForChild(child); |
| 1359 // Only used in flex layout, for other layout, it's equivalent to 'End'. | 1370 // Only used in flex layout, for other layout, it's equivalent to 'End'. |
| 1360 case ItemPositionFlexEnd: | 1371 case ItemPositionFlexEnd: |
| 1361 case ItemPositionEnd: | 1372 case ItemPositionEnd: |
| 1362 return endOfRowForChild(child); | 1373 return endOfRowForChild(child); |
| 1363 case ItemPositionStretch: | 1374 case ItemPositionStretch: |
| 1364 // FIXME: Implement the Stretch value. For now, we always start align th e child. | |
| 1365 return startOfRowForChild(child); | 1375 return startOfRowForChild(child); |
| 1366 case ItemPositionBaseline: | 1376 case ItemPositionBaseline: |
| 1367 case ItemPositionLastBaseline: | 1377 case ItemPositionLastBaseline: |
| 1368 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. | 1378 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. |
| 1369 return startOfRowForChild(child); | 1379 return startOfRowForChild(child); |
| 1370 case ItemPositionAuto: | 1380 case ItemPositionAuto: |
| 1371 break; | 1381 break; |
| 1372 } | 1382 } |
| 1373 | 1383 |
| 1374 ASSERT_NOT_REACHED(); | 1384 ASSERT_NOT_REACHED(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1392 if (isOutOfFlowPositioned()) | 1402 if (isOutOfFlowPositioned()) |
| 1393 return "RenderGrid (positioned)"; | 1403 return "RenderGrid (positioned)"; |
| 1394 if (isAnonymous()) | 1404 if (isAnonymous()) |
| 1395 return "RenderGrid (generated)"; | 1405 return "RenderGrid (generated)"; |
| 1396 if (isRelPositioned()) | 1406 if (isRelPositioned()) |
| 1397 return "RenderGrid (relative positioned)"; | 1407 return "RenderGrid (relative positioned)"; |
| 1398 return "RenderGrid"; | 1408 return "RenderGrid"; |
| 1399 } | 1409 } |
| 1400 | 1410 |
| 1401 } // namespace blink | 1411 } // namespace blink |
| OLD | NEW |