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(); | |
| 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(*child, ForColumns, sizingData.columnTracks); | 1065 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(*child, ForColumns, sizingData.columnTracks); |
| 1064 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(*child, ForRows, sizingData.rowTracks); | 1066 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(*child, ForRows, sizingData.rowTracks); |
| 1065 | 1067 |
| 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 |
|
Julien - ping for review
2014/10/21 00:43:12
Let's narrow this FIXME as part of this change to
jfernandez
2014/10/22 09:31:37
Done.
| |
| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1239 case ItemPositionCenter: | 1243 case ItemPositionCenter: |
| 1240 return centeredColumnPositionForChild(child); | 1244 return centeredColumnPositionForChild(child); |
| 1241 case ItemPositionStart: | 1245 case ItemPositionStart: |
| 1242 return columnPositionAlignedWithGridContainerStart(child); | 1246 return columnPositionAlignedWithGridContainerStart(child); |
| 1243 case ItemPositionEnd: | 1247 case ItemPositionEnd: |
| 1244 return columnPositionAlignedWithGridContainerEnd(child); | 1248 return columnPositionAlignedWithGridContainerEnd(child); |
| 1245 | 1249 |
| 1246 case ItemPositionAuto: | 1250 case ItemPositionAuto: |
| 1247 break; | 1251 break; |
| 1248 case ItemPositionStretch: | 1252 case ItemPositionStretch: |
| 1253 return startOfColumnForChild(child); | |
| 1249 case ItemPositionBaseline: | 1254 case ItemPositionBaseline: |
| 1250 case ItemPositionLastBaseline: | 1255 case ItemPositionLastBaseline: |
| 1251 // FIXME: Implement the previous values. For now, we always start align the child. | 1256 // FIXME: Implement the previous values. For now, we always start align the child. |
| 1252 return startOfColumnForChild(child); | 1257 return startOfColumnForChild(child); |
| 1253 } | 1258 } |
| 1254 | 1259 |
| 1255 ASSERT_NOT_REACHED(); | 1260 ASSERT_NOT_REACHED(); |
| 1256 return 0; | 1261 return 0; |
| 1257 } | 1262 } |
| 1258 | 1263 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1296 // FIXME: We should move this logic to the StyleAdjuster or the StyleBuilder. | 1301 // FIXME: We should move this logic to the StyleAdjuster or the StyleBuilder. |
| 1297 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende rStyle* childStyle) | 1302 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende rStyle* childStyle) |
| 1298 { | 1303 { |
| 1299 ItemPosition align = childStyle->alignSelf(); | 1304 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". | 1305 // The auto keyword computes to the parent's align-items computed value, or to "stretch", if not set or "auto". |
| 1301 if (align == ItemPositionAuto) | 1306 if (align == ItemPositionAuto) |
| 1302 align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionSt retch : parentStyle->alignItems(); | 1307 align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionSt retch : parentStyle->alignItems(); |
| 1303 return align; | 1308 return align; |
| 1304 } | 1309 } |
| 1305 | 1310 |
| 1311 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(RenderBox & child) | |
| 1312 { | |
| 1313 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight(); | |
| 1314 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | |
| 1315 } | |
| 1316 | |
| 1317 bool RenderGrid::needToStretchChildLogicalHeight(RenderBox& child) const | |
|
Julien - ping for review
2014/10/21 00:43:12
const RenderBox& child for most of the functions.
jfernandez
2014/10/22 09:31:37
Done.
| |
| 1318 { | |
| 1319 if (resolveAlignment(style(), child.style()) != ItemPositionStretch) | |
|
Julien - ping for review
2014/10/21 00:43:12
resolveAlignment is now on RenderStyle so it seems
jfernandez
2014/10/22 09:31:37
I'll send a new patch, rebased, to include this ch
| |
| 1320 return false; | |
| 1321 | |
| 1322 return isHorizontalWritingMode() && child.style()->height().isAuto(); | |
| 1323 } | |
| 1324 | |
| 1325 LayoutUnit RenderGrid::childIntrinsicHeight(RenderBox& child) const | |
| 1326 { | |
| 1327 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child )) | |
| 1328 return constrainedChildIntrinsicContentLogicalHeight(child); | |
| 1329 return child.height(); | |
| 1330 } | |
| 1331 | |
| 1332 LayoutUnit RenderGrid::childIntrinsicWidth(RenderBox& child) const | |
| 1333 { | |
| 1334 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil d)) | |
| 1335 return constrainedChildIntrinsicContentLogicalHeight(child); | |
| 1336 return child.width(); | |
| 1337 } | |
| 1338 | |
| 1339 LayoutUnit RenderGrid::intrinsicExtentForChild(RenderBox& child) const | |
|
Julien - ping for review
2014/10/21 00:43:12
We usually don't use Extent in the code. Instead l
jfernandez
2014/10/22 09:31:37
Done.
| |
| 1340 { | |
| 1341 return isHorizontalWritingMode() ? childIntrinsicHeight(child) : childIntrin sicWidth(child); | |
| 1342 } | |
| 1343 | |
| 1344 LayoutUnit RenderGrid::marginExtentForChild(RenderBox& child) const | |
| 1345 { | |
| 1346 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth( ); | |
|
Julien - ping for review
2014/10/21 00:43:12
It really seems like that this should be on Render
jfernandez
2014/10/22 09:31:37
Agree, but perhaps in a different patch ? Otherwis
| |
| 1347 } | |
| 1348 | |
| 1349 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni t gridAreaBreadthForChild, RenderBox& child) const | |
| 1350 { | |
| 1351 ASSERT(!child.isOutOfFlowPositioned()); | |
| 1352 LayoutUnit childExtent = marginExtentForChild(child) + intrinsicExtentForChi ld(child); | |
| 1353 return gridAreaBreadthForChild - childExtent; | |
| 1354 } | |
| 1355 | |
| 1356 void RenderGrid::applyStretchAlignmentToChildIfNeeded(RenderBox& child, LayoutUn it gridAreaBreadthForChild) | |
| 1357 { | |
| 1358 if (resolveAlignment(style(), child.style()) != ItemPositionStretch) | |
| 1359 return; | |
| 1360 | |
| 1361 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | |
| 1362 if (child.style()->logicalHeight().isAuto()) { | |
| 1363 // FIXME: If the child has orthogonal flow, then it already has an overr ide height set, so use it. | |
| 1364 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | |
| 1365 if (!hasOrthogonalWritingMode) { | |
| 1366 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight( child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei ght(); | |
|
Julien - ping for review
2014/10/21 00:43:12
It's bad smell that needToStretchChildLogicalHeigh
jfernandez
2014/10/22 09:31:37
I've got the code from the flexbox implementation,
| |
| 1367 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab leAlignmentSpaceForChildBeforeStretching(gridAreaBreadthForChild, child); | |
| 1368 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica lHeight()); | |
| 1369 LayoutUnit desiredLogicalContentHeight = desiredLogicalHeight - chil d.borderAndPaddingLogicalHeight(); | |
| 1370 | |
| 1371 // FIXME: Can avoid laying out here in some cases. See https://webki t.org/b/87905. | |
| 1372 if (desiredLogicalHeight != child.logicalHeight() || !child.hasOverr ideHeight() || desiredLogicalContentHeight != child.overrideLogicalContentHeight ()) { | |
| 1373 child.setOverrideLogicalContentHeight(desiredLogicalContentHeigh t); | |
| 1374 child.setLogicalHeight(0); | |
| 1375 child.forceChildLayout(); | |
| 1376 } | |
| 1377 } | |
| 1378 } | |
| 1379 } | |
| 1380 | |
| 1306 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const | 1381 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
| 1307 { | 1382 { |
| 1308 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1383 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
| 1309 ItemPosition alignSelf = resolveAlignment(style(), child.style()); | 1384 ItemPosition alignSelf = resolveAlignment(style(), child.style()); |
| 1310 | 1385 |
| 1311 switch (alignSelf) { | 1386 switch (alignSelf) { |
| 1312 case ItemPositionSelfStart: | 1387 case ItemPositionSelfStart: |
| 1313 // If orthogonal writing-modes, this computes to 'Start'. | 1388 // If orthogonal writing-modes, this computes to 'Start'. |
| 1314 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. | 1389 // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
| 1315 if (hasOrthogonalWritingMode) | 1390 if (hasOrthogonalWritingMode) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 return centeredRowPositionForChild(child); | 1429 return centeredRowPositionForChild(child); |
| 1355 // Only used in flex layout, for other layout, it's equivalent to 'Start '. | 1430 // Only used in flex layout, for other layout, it's equivalent to 'Start '. |
| 1356 case ItemPositionFlexStart: | 1431 case ItemPositionFlexStart: |
| 1357 case ItemPositionStart: | 1432 case ItemPositionStart: |
| 1358 return startOfRowForChild(child); | 1433 return startOfRowForChild(child); |
| 1359 // Only used in flex layout, for other layout, it's equivalent to 'End'. | 1434 // Only used in flex layout, for other layout, it's equivalent to 'End'. |
| 1360 case ItemPositionFlexEnd: | 1435 case ItemPositionFlexEnd: |
| 1361 case ItemPositionEnd: | 1436 case ItemPositionEnd: |
| 1362 return endOfRowForChild(child); | 1437 return endOfRowForChild(child); |
| 1363 case ItemPositionStretch: | 1438 case ItemPositionStretch: |
| 1364 // FIXME: Implement the Stretch value. For now, we always start align th e child. | |
| 1365 return startOfRowForChild(child); | 1439 return startOfRowForChild(child); |
| 1366 case ItemPositionBaseline: | 1440 case ItemPositionBaseline: |
| 1367 case ItemPositionLastBaseline: | 1441 case ItemPositionLastBaseline: |
| 1368 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. | 1442 // FIXME: Implement the ItemPositionBaseline value. For now, we always s tart align the child. |
| 1369 return startOfRowForChild(child); | 1443 return startOfRowForChild(child); |
| 1370 case ItemPositionAuto: | 1444 case ItemPositionAuto: |
| 1371 break; | 1445 break; |
| 1372 } | 1446 } |
| 1373 | 1447 |
| 1374 ASSERT_NOT_REACHED(); | 1448 ASSERT_NOT_REACHED(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1392 if (isOutOfFlowPositioned()) | 1466 if (isOutOfFlowPositioned()) |
| 1393 return "RenderGrid (positioned)"; | 1467 return "RenderGrid (positioned)"; |
| 1394 if (isAnonymous()) | 1468 if (isAnonymous()) |
| 1395 return "RenderGrid (generated)"; | 1469 return "RenderGrid (generated)"; |
| 1396 if (isRelPositioned()) | 1470 if (isRelPositioned()) |
| 1397 return "RenderGrid (relative positioned)"; | 1471 return "RenderGrid (relative positioned)"; |
| 1398 return "RenderGrid"; | 1472 return "RenderGrid"; |
| 1399 } | 1473 } |
| 1400 | 1474 |
| 1401 } // namespace blink | 1475 } // namespace blink |
| OLD | NEW |