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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 SubtreeLayoutScope layoutScope(*child); | 1268 SubtreeLayoutScope layoutScope(*child); |
1269 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1269 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
1270 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); | 1270 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); |
1271 | 1271 |
1272 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); | 1272 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); |
1273 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); | 1273 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); |
1274 | 1274 |
1275 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded | 1275 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded |
1276 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly | 1276 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly |
1277 // determine the available space before stretching, are not set yet. | 1277 // determine the available space before stretching, are not set yet. |
1278 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont
entLogicalHeight); | 1278 applyStretchAlignmentToChildIfNeeded(*child); |
1279 | 1279 |
1280 child->layoutIfNeeded(); | 1280 child->layoutIfNeeded(); |
1281 | 1281 |
1282 #if ENABLE(ASSERT) | 1282 #if ENABLE(ASSERT) |
1283 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1283 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
1284 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); | 1284 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); |
1285 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); | 1285 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); |
1286 #endif | 1286 #endif |
1287 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1287 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1288 | 1288 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 { | 1451 { |
1452 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); | 1452 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
1453 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 1453 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
1454 } | 1454 } |
1455 | 1455 |
1456 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
onst | 1456 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
onst |
1457 { | 1457 { |
1458 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo
reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | 1458 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo
reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); |
1459 } | 1459 } |
1460 | 1460 |
| 1461 bool LayoutGrid::allowedToStretchLogicalWidthForChild(const LayoutBox& child) co
nst |
| 1462 { |
| 1463 return child.style()->logicalWidth().isAuto() && !child.style()->marginStart
Using(style()).isAuto() && !child.style()->marginEndUsing(style()).isAuto(); |
| 1464 } |
| 1465 |
1461 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1466 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. |
1462 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const | 1467 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const |
1463 { | 1468 { |
1464 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi
onStretch) != ItemPositionStretch) | 1469 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi
onStretch) != ItemPositionStretch) |
1465 return false; | 1470 return false; |
1466 | 1471 |
1467 return isHorizontalWritingMode() && child.style()->height().isAuto(); | 1472 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
1468 } | 1473 } |
1469 | 1474 |
1470 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1475 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before | 1521 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before |
1517 // children are laid out, so we can't use the child cached values. Hence, we
need to | 1522 // children are laid out, so we can't use the child cached values. Hence, we
need to |
1518 // compute margins in order to determine the available height before stretch
ing. | 1523 // compute margins in order to determine the available height before stretch
ing. |
1519 if (childMarginLogicalHeight == 0) | 1524 if (childMarginLogicalHeight == 0) |
1520 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); | 1525 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); |
1521 | 1526 |
1522 return gridAreaBreadthForChild - childMarginLogicalHeight; | 1527 return gridAreaBreadthForChild - childMarginLogicalHeight; |
1523 } | 1528 } |
1524 | 1529 |
1525 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1530 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. |
1526 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn
it gridAreaBreadthForChild) | 1531 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
1527 { | 1532 { |
1528 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA
lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret
ch) { | 1533 child.clearOverrideSize(); |
1529 child.clearOverrideLogicalContentHeight(); | 1534 |
| 1535 if (!allowedToStretchLogicalWidthForChild(child) || ComputedStyle::resolveJu
stification(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionSt
retch) { |
| 1536 if (child.style()->logicalWidth().isAuto()) { |
| 1537 LayoutUnit childPreferredWidth = child.maxPreferredLogicalWidth(); |
| 1538 child.setOverrideLogicalContentWidth(childPreferredWidth - child.bor
derAndPaddingLogicalWidth()); |
| 1539 if (childPreferredWidth != child.logicalWidth()) |
| 1540 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1541 } |
| 1542 } |
| 1543 |
| 1544 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA
lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret
ch) |
1530 return; | 1545 return; |
1531 } | |
1532 | 1546 |
1533 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1547 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1534 // FIXME: If the child has orthogonal flow, then it already has an override
height set, so use it. | 1548 // FIXME: If the child has orthogonal flow, then it already has an override
height set, so use it. |
1535 // FIXME: grid track sizing and positioning do not support orthogonal modes
yet. | 1549 // FIXME: grid track sizing and positioning do not support orthogonal modes
yet. |
1536 if (!hasOrthogonalWritingMode) { | 1550 if (!hasOrthogonalWritingMode) { |
1537 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor
eStretching(gridAreaBreadthForChild, child); | 1551 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor
eStretching(child.overrideContainingBlockContentLogicalHeight(), child); |
1538 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s
tretchedLogicalHeight, -1); | 1552 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s
tretchedLogicalHeight, -1); |
1539 | 1553 |
1540 // FIXME: Can avoid laying out here in some cases. See https://webkit.or
g/b/87905. | 1554 // FIXME: Can avoid laying out here in some cases. See https://webkit.or
g/b/87905. |
1541 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); | 1555 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); |
1542 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) | 1556 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) |
1543 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b
orderAndPaddingLogicalHeight()); | 1557 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b
orderAndPaddingLogicalHeight()); |
1544 if (childNeedsRelayout) { | 1558 if (childNeedsRelayout) { |
1545 child.setLogicalHeight(0); | 1559 child.setLogicalHeight(0); |
1546 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1560 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
1547 } | 1561 } |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 | 1869 |
1856 return LayoutPoint(columnPosition, rowPositionForChild(child)); | 1870 return LayoutPoint(columnPosition, rowPositionForChild(child)); |
1857 } | 1871 } |
1858 | 1872 |
1859 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 1873 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
1860 { | 1874 { |
1861 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1875 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
1862 } | 1876 } |
1863 | 1877 |
1864 } // namespace blink | 1878 } // namespace blink |
OLD | NEW |