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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 } | 617 } |
618 | 618 |
619 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack>
& columnTracks) | 619 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack>
& columnTracks) |
620 { | 620 { |
621 SubtreeLayoutScope layoutScope(child); | 621 SubtreeLayoutScope layoutScope(child); |
622 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); | 622 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); |
623 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); | 623 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); |
624 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock
ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) | 624 if (child.style()->logicalHeight().isPercent() || oldOverrideContainingBlock
ContentLogicalWidth != overrideContainingBlockContentLogicalWidth) |
625 layoutScope.setNeedsLayout(&child); | 625 layoutScope.setNeedsLayout(&child); |
626 | 626 |
| 627 child.clearOverrideLogicalContentHeight(); |
| 628 |
627 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC
ontentLogicalWidth); | 629 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC
ontentLogicalWidth); |
628 // If |child| has a percentage logical height, we shouldn't let it override
its intrinsic height, which is | 630 // If |child| has a percentage logical height, we shouldn't let it override
its intrinsic height, which is |
629 // what we are interested in here. Thus we need to set the override logical
height to -1 (no possible resolution). | 631 // what we are interested in here. Thus we need to set the override logical
height to -1 (no possible resolution). |
630 child.setOverrideContainingBlockContentLogicalHeight(-1); | 632 child.setOverrideContainingBlockContentLogicalHeight(-1); |
631 child.layoutIfNeeded(); | 633 child.layoutIfNeeded(); |
632 return child.logicalHeight() + child.marginLogicalHeight(); | 634 return child.logicalHeight() + child.marginLogicalHeight(); |
633 } | 635 } |
634 | 636 |
635 LayoutUnit RenderGrid::minContentForChild(RenderBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) | 637 LayoutUnit RenderGrid::minContentForChild(RenderBox& child, GridTrackSizingDirec
tion direction, Vector<GridTrack>& columnTracks) |
636 { | 638 { |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF
orChild(*child, ForColumns, sizingData.columnTracks); | 1112 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF
orChild(*child, ForColumns, sizingData.columnTracks); |
1111 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth
ForChild(*child, ForRows, sizingData.rowTracks); | 1113 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth
ForChild(*child, ForRows, sizingData.rowTracks); |
1112 | 1114 |
1113 SubtreeLayoutScope layoutScope(*child); | 1115 SubtreeLayoutScope layoutScope(*child); |
1114 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1116 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
1115 layoutScope.setNeedsLayout(child); | 1117 layoutScope.setNeedsLayout(child); |
1116 | 1118 |
1117 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); | 1119 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); |
1118 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); | 1120 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); |
1119 | 1121 |
1120 // FIXME: Grid items should stretch to fill their cells. Once we | 1122 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont
entLogicalHeight); |
1121 // implement grid-{column,row}-align, we can also shrink to fit. For | 1123 |
1122 // now, just size as if we were a regular child. | |
1123 child->layoutIfNeeded(); | 1124 child->layoutIfNeeded(); |
1124 | 1125 |
1125 #if ENABLE(ASSERT) | 1126 #if ENABLE(ASSERT) |
1126 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1127 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
1127 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); | 1128 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); |
1128 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); | 1129 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); |
1129 #endif | 1130 #endif |
1130 child->setLogicalLocation(findChildLogicalPosition(*child)); | 1131 child->setLogicalLocation(findChildLogicalPosition(*child)); |
1131 | 1132 |
1132 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is | 1133 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 { | 1231 { |
1231 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1232 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
1232 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; | 1233 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInit
ialPosition.toInt()]; |
1233 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; | 1234 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalP
osition.next().toInt()]; |
1234 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); | 1235 LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child); |
1235 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth()); | 1236 LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.s
tyle()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logica
lWidth()); |
1236 | 1237 |
1237 return columnPosition + offsetFromColumnPosition / 2; | 1238 return columnPosition + offsetFromColumnPosition / 2; |
1238 } | 1239 } |
1239 | 1240 |
1240 static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R
enderStyle* childStyle) | |
1241 { | |
1242 ItemPosition justify = childStyle->justifySelf(); | |
1243 if (justify == ItemPositionAuto) | |
1244 justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositi
onStretch : parentStyle->justifyItems(); | |
1245 return justify; | |
1246 } | |
1247 | |
1248 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const | 1241 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox& child) const |
1249 { | 1242 { |
1250 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1243 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1251 | 1244 |
1252 switch (resolveJustification(style(), child.style())) { | 1245 switch (RenderStyle::resolveJustification(style(), child.style(), ItemPositi
onStretch)) { |
1253 case ItemPositionSelfStart: | 1246 case ItemPositionSelfStart: |
1254 // For orthogonal writing-modes, this computes to 'start' | 1247 // For orthogonal writing-modes, this computes to 'start' |
1255 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 1248 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. |
1256 if (hasOrthogonalWritingMode) | 1249 if (hasOrthogonalWritingMode) |
1257 return columnPositionAlignedWithGridContainerStart(child); | 1250 return columnPositionAlignedWithGridContainerStart(child); |
1258 | 1251 |
1259 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. | 1252 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. |
1260 if (child.style()->direction() != style()->direction()) | 1253 if (child.style()->direction() != style()->direction()) |
1261 return columnPositionAlignedWithGridContainerEnd(child); | 1254 return columnPositionAlignedWithGridContainerEnd(child); |
1262 | 1255 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 case ItemPositionCenter: | 1295 case ItemPositionCenter: |
1303 return centeredColumnPositionForChild(child); | 1296 return centeredColumnPositionForChild(child); |
1304 case ItemPositionStart: | 1297 case ItemPositionStart: |
1305 return columnPositionAlignedWithGridContainerStart(child); | 1298 return columnPositionAlignedWithGridContainerStart(child); |
1306 case ItemPositionEnd: | 1299 case ItemPositionEnd: |
1307 return columnPositionAlignedWithGridContainerEnd(child); | 1300 return columnPositionAlignedWithGridContainerEnd(child); |
1308 | 1301 |
1309 case ItemPositionAuto: | 1302 case ItemPositionAuto: |
1310 break; | 1303 break; |
1311 case ItemPositionStretch: | 1304 case ItemPositionStretch: |
| 1305 return startOfColumnForChild(child); |
1312 case ItemPositionBaseline: | 1306 case ItemPositionBaseline: |
1313 case ItemPositionLastBaseline: | 1307 case ItemPositionLastBaseline: |
1314 // FIXME: Implement the previous values. For now, we always start align
the child. | 1308 // FIXME: Implement the previous values. For now, we always start align
the child. |
1315 return startOfColumnForChild(child); | 1309 return startOfColumnForChild(child); |
1316 } | 1310 } |
1317 | 1311 |
1318 ASSERT_NOT_REACHED(); | 1312 ASSERT_NOT_REACHED(); |
1319 return 0; | 1313 return 0; |
1320 } | 1314 } |
1321 | 1315 |
(...skipping 28 matching lines...) Expand all Loading... |
1350 | 1344 |
1351 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1345 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
1352 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()] + marginBeforeForChild(&child); | 1346 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPositi
on.toInt()] + marginBeforeForChild(&child); |
1353 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; | 1347 LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.n
ext().toInt()]; |
1354 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); | 1348 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child); |
1355 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight()); | 1349 LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.styl
e()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight()); |
1356 | 1350 |
1357 return rowPosition + offsetFromRowPosition / 2; | 1351 return rowPosition + offsetFromRowPosition / 2; |
1358 } | 1352 } |
1359 | 1353 |
| 1354 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Ren
derBox& child) |
| 1355 { |
| 1356 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
| 1357 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
| 1358 } |
| 1359 |
| 1360 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1361 bool RenderGrid::needToStretchChildLogicalHeight(const RenderBox& child) const |
| 1362 { |
| 1363 if (RenderStyle::resolveAlignment(style(), child.style(), ItemPositionStretc
h) != ItemPositionStretch) |
| 1364 return false; |
| 1365 |
| 1366 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
| 1367 } |
| 1368 |
| 1369 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1370 LayoutUnit RenderGrid::childIntrinsicHeight(const RenderBox& child) const |
| 1371 { |
| 1372 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) |
| 1373 return constrainedChildIntrinsicContentLogicalHeight(child); |
| 1374 return child.height(); |
| 1375 } |
| 1376 |
| 1377 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1378 LayoutUnit RenderGrid::childIntrinsicWidth(const RenderBox& child) const |
| 1379 { |
| 1380 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) |
| 1381 return constrainedChildIntrinsicContentLogicalHeight(child); |
| 1382 return child.width(); |
| 1383 } |
| 1384 |
| 1385 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1386 LayoutUnit RenderGrid::intrinsicLogicalHeightForChild(const RenderBox& child) co
nst |
| 1387 { |
| 1388 return isHorizontalWritingMode() ? childIntrinsicHeight(child) : childIntrin
sicWidth(child); |
| 1389 } |
| 1390 |
| 1391 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1392 LayoutUnit RenderGrid::marginLogicalHeightForChild(const RenderBox& child) const |
| 1393 { |
| 1394 return isHorizontalWritingMode() ? child.marginHeight() : child.marginWidth(
); |
| 1395 } |
| 1396 |
| 1397 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1398 LayoutUnit RenderGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni
t gridAreaBreadthForChild, const RenderBox& child) const |
| 1399 { |
| 1400 LayoutUnit childLogicalHeight = marginLogicalHeightForChild(child) + intrins
icLogicalHeightForChild(child); |
| 1401 return gridAreaBreadthForChild - childLogicalHeight; |
| 1402 } |
| 1403 |
| 1404 // FIXME: This logic is shared by RenderFlexibleBox, so it should be moved to Re
nderBox. |
| 1405 void RenderGrid::applyStretchAlignmentToChildIfNeeded(RenderBox& child, LayoutUn
it gridAreaBreadthForChild) |
| 1406 { |
| 1407 if (RenderStyle::resolveAlignment(style(), child.style(), ItemPositionStretc
h) != ItemPositionStretch) |
| 1408 return; |
| 1409 |
| 1410 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
| 1411 if (child.style()->logicalHeight().isAuto()) { |
| 1412 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. |
| 1413 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. |
| 1414 if (!hasOrthogonalWritingMode) { |
| 1415 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(
child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei
ght(); |
| 1416 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab
leAlignmentSpaceForChildBeforeStretching(gridAreaBreadthForChild, child); |
| 1417 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica
lHeight()); |
| 1418 LayoutUnit desiredLogicalContentHeight = desiredLogicalHeight - chil
d.borderAndPaddingLogicalHeight(); |
| 1419 |
| 1420 // FIXME: Can avoid laying out here in some cases. See https://webki
t.org/b/87905. |
| 1421 if (desiredLogicalHeight != child.logicalHeight() || !child.hasOverr
ideHeight() || desiredLogicalContentHeight != child.overrideLogicalContentHeight
()) { |
| 1422 child.setOverrideLogicalContentHeight(desiredLogicalContentHeigh
t); |
| 1423 child.setLogicalHeight(0); |
| 1424 child.forceChildLayout(); |
| 1425 } |
| 1426 } |
| 1427 } |
| 1428 } |
| 1429 |
1360 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const | 1430 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
1361 { | 1431 { |
1362 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1432 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1363 | 1433 switch (RenderStyle::resolveAlignment(style(), child.style(), ItemPositionSt
retch)) { |
1364 switch (RenderStyle::resolveAlignment(style(), child.style())) { | |
1365 case ItemPositionSelfStart: | 1434 case ItemPositionSelfStart: |
1366 // If orthogonal writing-modes, this computes to 'Start'. | 1435 // If orthogonal writing-modes, this computes to 'Start'. |
1367 // FIXME: grid track sizing and positioning does not support orthogonal
modes yet. | 1436 // FIXME: grid track sizing and positioning does not support orthogonal
modes yet. |
1368 if (hasOrthogonalWritingMode) | 1437 if (hasOrthogonalWritingMode) |
1369 return startOfRowForChild(child); | 1438 return startOfRowForChild(child); |
1370 | 1439 |
1371 // self-start is based on the child's block axis direction. That's why w
e need to check against the grid container's block flow. | 1440 // self-start is based on the child's block axis direction. That's why w
e need to check against the grid container's block flow. |
1372 if (child.style()->writingMode() != style()->writingMode()) | 1441 if (child.style()->writingMode() != style()->writingMode()) |
1373 return endOfRowForChild(child); | 1442 return endOfRowForChild(child); |
1374 | 1443 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 return centeredRowPositionForChild(child); | 1476 return centeredRowPositionForChild(child); |
1408 // Only used in flex layout, for other layout, it's equivalent to 'Start
'. | 1477 // Only used in flex layout, for other layout, it's equivalent to 'Start
'. |
1409 case ItemPositionFlexStart: | 1478 case ItemPositionFlexStart: |
1410 case ItemPositionStart: | 1479 case ItemPositionStart: |
1411 return startOfRowForChild(child); | 1480 return startOfRowForChild(child); |
1412 // Only used in flex layout, for other layout, it's equivalent to 'End'. | 1481 // Only used in flex layout, for other layout, it's equivalent to 'End'. |
1413 case ItemPositionFlexEnd: | 1482 case ItemPositionFlexEnd: |
1414 case ItemPositionEnd: | 1483 case ItemPositionEnd: |
1415 return endOfRowForChild(child); | 1484 return endOfRowForChild(child); |
1416 case ItemPositionStretch: | 1485 case ItemPositionStretch: |
1417 // FIXME: Implement the Stretch value. For now, we always start align th
e child. | |
1418 return startOfRowForChild(child); | 1486 return startOfRowForChild(child); |
1419 case ItemPositionBaseline: | 1487 case ItemPositionBaseline: |
1420 case ItemPositionLastBaseline: | 1488 case ItemPositionLastBaseline: |
1421 // FIXME: Implement the ItemPositionBaseline value. For now, we always s
tart align the child. | 1489 // FIXME: Implement the ItemPositionBaseline value. For now, we always s
tart align the child. |
1422 return startOfRowForChild(child); | 1490 return startOfRowForChild(child); |
1423 case ItemPositionAuto: | 1491 case ItemPositionAuto: |
1424 break; | 1492 break; |
1425 } | 1493 } |
1426 | 1494 |
1427 ASSERT_NOT_REACHED(); | 1495 ASSERT_NOT_REACHED(); |
(...skipping 17 matching lines...) Expand all Loading... |
1445 if (isOutOfFlowPositioned()) | 1513 if (isOutOfFlowPositioned()) |
1446 return "RenderGrid (positioned)"; | 1514 return "RenderGrid (positioned)"; |
1447 if (isAnonymous()) | 1515 if (isAnonymous()) |
1448 return "RenderGrid (generated)"; | 1516 return "RenderGrid (generated)"; |
1449 if (isRelPositioned()) | 1517 if (isRelPositioned()) |
1450 return "RenderGrid (relative positioned)"; | 1518 return "RenderGrid (relative positioned)"; |
1451 return "RenderGrid"; | 1519 return "RenderGrid"; |
1452 } | 1520 } |
1453 | 1521 |
1454 } // namespace blink | 1522 } // namespace blink |
OLD | NEW |