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 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 SubtreeLayoutScope layoutScope(*child); | 1338 SubtreeLayoutScope layoutScope(*child); |
1339 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1339 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
1340 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); | 1340 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); |
1341 | 1341 |
1342 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); | 1342 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); |
1343 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); | 1343 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); |
1344 | 1344 |
1345 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded | 1345 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded |
1346 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly | 1346 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly |
1347 // determine the available space before stretching, are not set yet. | 1347 // determine the available space before stretching, are not set yet. |
1348 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont
entLogicalHeight); | 1348 applyStretchAlignmentToChildIfNeeded(*child); |
1349 | 1349 |
1350 child->layoutIfNeeded(); | 1350 child->layoutIfNeeded(); |
1351 | 1351 |
1352 #if ENABLE(ASSERT) | 1352 #if ENABLE(ASSERT) |
1353 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1353 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
1354 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); | 1354 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c
olumnTracks.size()); |
1355 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); | 1355 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT
racks.size()); |
1356 #endif | 1356 #endif |
1357 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1357 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1358 | 1358 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 ASSERT_NOT_REACHED(); | 1545 ASSERT_NOT_REACHED(); |
1546 return 0; | 1546 return 0; |
1547 } | 1547 } |
1548 | 1548 |
1549 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) | 1549 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) |
1550 { | 1550 { |
1551 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); | 1551 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
1552 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 1552 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
1553 } | 1553 } |
1554 | 1554 |
1555 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
onst | |
1556 { | |
1557 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo
reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | |
1558 } | |
1559 | |
1560 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1555 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. |
1561 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const | 1556 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const |
1562 { | 1557 { |
1563 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi
onStretch) != ItemPositionStretch) | 1558 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi
onStretch) != ItemPositionStretch) |
1564 return false; | 1559 return false; |
1565 | 1560 |
1566 return isHorizontalWritingMode() && child.style()->height().isAuto(); | 1561 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
1567 } | 1562 } |
1568 | 1563 |
1569 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1564 // 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... |
1615 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before | 1610 // Because we want to avoid multiple layouts, stretching logic might be perf
ormed before |
1616 // children are laid out, so we can't use the child cached values. Hence, we
need to | 1611 // children are laid out, so we can't use the child cached values. Hence, we
need to |
1617 // compute margins in order to determine the available height before stretch
ing. | 1612 // compute margins in order to determine the available height before stretch
ing. |
1618 if (childMarginLogicalHeight == 0) | 1613 if (childMarginLogicalHeight == 0) |
1619 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); | 1614 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); |
1620 | 1615 |
1621 return gridAreaBreadthForChild - childMarginLogicalHeight; | 1616 return gridAreaBreadthForChild - childMarginLogicalHeight; |
1622 } | 1617 } |
1623 | 1618 |
1624 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. | 1619 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La
youtBox. |
1625 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn
it gridAreaBreadthForChild) | 1620 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
1626 { | 1621 { |
1627 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA
lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret
ch) { | 1622 // We clear both width and height override values because we will decide now
whether they |
1628 child.clearOverrideLogicalContentHeight(); | 1623 // are allowed or not, evaluating the conditions which might have changed si
nce the old |
1629 return; | 1624 // values were set. |
| 1625 child.clearOverrideSize(); |
| 1626 |
| 1627 bool isHorizontalMode = isHorizontalWritingMode(); |
| 1628 bool hasAutoSizeInRowAxis = isHorizontalMode ? child.styleRef().width().isAu
to() : child.styleRef().height().isAuto(); |
| 1629 bool allowedToStretchChildAlongRowAxis = hasAutoSizeInRowAxis && !child.styl
eRef().marginStartUsing(style()).isAuto() && !child.styleRef().marginEndUsing(st
yle()).isAuto(); |
| 1630 if (!allowedToStretchChildAlongRowAxis || ComputedStyle::resolveJustificatio
n(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { |
| 1631 bool hasAutoMinSizeInRowAxis = isHorizontalMode ? child.styleRef().minWi
dth().isAuto() : child.styleRef().minHeight().isAuto(); |
| 1632 bool canShrinkToFitInRowAxisForChild = !hasAutoMinSizeInRowAxis || child
.minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth(
); |
| 1633 // TODO(lajava): how to handle orthogonality in this case ?. |
| 1634 // TODO(lajava): grid track sizing and positioning do not support orthog
onal modes yet. |
| 1635 if (hasAutoSizeInRowAxis && canShrinkToFitInRowAxisForChild) { |
| 1636 LayoutUnit childWidthToFitContent = std::max(std::min(child.maxPrefe
rredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - child.
marginLogicalWidth()), child.minPreferredLogicalWidth()); |
| 1637 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMa
x(childWidthToFitContent, -1); |
| 1638 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.bor
derAndPaddingLogicalWidth()); |
| 1639 if (desiredLogicalWidth != child.logicalWidth()) |
| 1640 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1641 } |
1630 } | 1642 } |
1631 | 1643 |
1632 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1644 bool hasAutoSizeInColumnAxis = isHorizontalMode ? child.styleRef().height().
isAuto() : child.styleRef().width().isAuto(); |
1633 // FIXME: If the child has orthogonal flow, then it already has an override
height set, so use it. | 1645 bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !chil
d.styleRef().marginBeforeUsing(style()).isAuto() && !child.styleRef().marginAfte
rUsing(style()).isAuto(); |
1634 // FIXME: grid track sizing and positioning do not support orthogonal modes
yet. | 1646 if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment(
styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch) { |
1635 if (!hasOrthogonalWritingMode) { | 1647 // TODO (lajava): If the child has orthogonal flow, then it already has
an override height set, so use it. |
1636 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor
eStretching(gridAreaBreadthForChild, child); | 1648 // TODO (lajava): grid track sizing and positioning do not support ortho
gonal modes yet. |
1637 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s
tretchedLogicalHeight, -1); | 1649 if (child.isHorizontalWritingMode() == isHorizontalMode) { |
1638 | 1650 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildB
eforeStretching(child.overrideContainingBlockContentLogicalHeight(), child); |
1639 // FIXME: Can avoid laying out here in some cases. See https://webkit.or
g/b/87905. | 1651 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, -1); |
1640 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); | |
1641 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) | |
1642 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b
orderAndPaddingLogicalHeight()); | 1652 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b
orderAndPaddingLogicalHeight()); |
1643 if (childNeedsRelayout) { | 1653 if (desiredLogicalHeight != child.logicalHeight()) { |
1644 child.setLogicalHeight(0); | 1654 // TODO (lajava): Can avoid laying out here in some cases. See h
ttps://webkit.org/b/87905. |
1645 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1655 child.setLogicalHeight(0); |
| 1656 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1657 } |
1646 } | 1658 } |
1647 } | 1659 } |
1648 } | 1660 } |
1649 | 1661 |
1650 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
const | 1662 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
const |
1651 { | 1663 { |
1652 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); | 1664 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon
talWritingMode(); |
1653 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi
ngMode(); | 1665 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi
ngMode(); |
1654 | 1666 |
1655 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo
sitionStretch)) { | 1667 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo
sitionStretch)) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 | 1919 |
1908 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 1920 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); |
1909 } | 1921 } |
1910 | 1922 |
1911 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 1923 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
1912 { | 1924 { |
1913 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1925 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
1914 } | 1926 } |
1915 | 1927 |
1916 } // namespace blink | 1928 } // namespace blink |
OLD | NEW |