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 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 SubtreeLayoutScope layoutScope(*child); | 1361 SubtreeLayoutScope layoutScope(*child); |
| 1362 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1362 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
| 1363 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); | 1363 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); |
| 1364 | 1364 |
| 1365 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 1365 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
| 1366 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 1366 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
| 1367 | 1367 |
| 1368 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded | 1368 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded |
| 1369 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly | 1369 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly |
| 1370 // determine the available space before stretching, are not set yet. | 1370 // determine the available space before stretching, are not set yet. |
| 1371 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont entLogicalHeight); | 1371 applyStretchAlignmentToChildIfNeeded(*child); |
| 1372 | 1372 |
| 1373 child->layoutIfNeeded(); | 1373 child->layoutIfNeeded(); |
| 1374 | 1374 |
| 1375 #if ENABLE(ASSERT) | 1375 #if ENABLE(ASSERT) |
| 1376 const GridCoordinate& coordinate = cachedGridCoordinate(*child); | 1376 const GridCoordinate& coordinate = cachedGridCoordinate(*child); |
| 1377 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); | 1377 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); |
| 1378 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); | 1378 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); |
| 1379 #endif | 1379 #endif |
| 1380 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1380 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
| 1381 | 1381 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1561 ASSERT_NOT_REACHED(); | 1561 ASSERT_NOT_REACHED(); |
| 1562 return 0; | 1562 return 0; |
| 1563 } | 1563 } |
| 1564 | 1564 |
| 1565 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child) | 1565 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child) |
| 1566 { | 1566 { |
| 1567 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight(); | 1567 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight(); |
| 1568 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 1568 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c onst | |
| 1572 { | |
| 1573 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | |
| 1574 } | |
| 1575 | |
| 1576 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. | 1571 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. |
| 1577 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const | 1572 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const |
| 1578 { | 1573 { |
| 1579 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch) | 1574 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch) |
| 1580 return false; | 1575 return false; |
| 1581 | 1576 |
| 1582 return isHorizontalWritingMode() && child.style()->height().isAuto(); | 1577 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
| 1583 } | 1578 } |
| 1584 | 1579 |
| 1585 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. | 1580 // 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... | |
| 1631 // Because we want to avoid multiple layouts, stretching logic might be perf ormed before | 1626 // Because we want to avoid multiple layouts, stretching logic might be perf ormed before |
| 1632 // children are laid out, so we can't use the child cached values. Hence, we need to | 1627 // children are laid out, so we can't use the child cached values. Hence, we need to |
| 1633 // compute margins in order to determine the available height before stretch ing. | 1628 // compute margins in order to determine the available height before stretch ing. |
| 1634 if (childMarginLogicalHeight == 0) | 1629 if (childMarginLogicalHeight == 0) |
| 1635 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); | 1630 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); |
| 1636 | 1631 |
| 1637 return gridAreaBreadthForChild - childMarginLogicalHeight; | 1632 return gridAreaBreadthForChild - childMarginLogicalHeight; |
| 1638 } | 1633 } |
| 1639 | 1634 |
| 1640 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. | 1635 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. |
| 1641 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn it gridAreaBreadthForChild) | 1636 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
| 1642 { | 1637 { |
| 1643 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret ch) { | 1638 // We clear botth width and height override values because we will decide no w whether they |
|
svillar
2015/07/30 10:11:27
Nit botth -> both
jfernandez
2015/07/31 22:25:42
Done.
| |
| 1644 child.clearOverrideLogicalContentHeight(); | 1639 // are allowed or not, evaluating the conditions which might have changed si nce the old |
| 1645 return; | 1640 // values were set. |
| 1641 child.clearOverrideSize(); | |
| 1642 | |
| 1643 bool isHorizontalMode = isHorizontalWritingMode(); | |
| 1644 bool hasAutoSizeInRowAxis = isHorizontalMode ? child.style()->width().isAuto () : child.style()->height().isAuto(); | |
|
svillar
2015/07/30 10:11:27
Nit: hasAutoSizeInRowAxisForChild to match your fu
| |
| 1645 bool allowedToStretchChildAlongRowAxis = hasAutoSizeInRowAxis && !child.styl e()->marginStartUsing(style()).isAuto() && !child.style()->marginEndUsing(style( )).isAuto(); | |
| 1646 if (!allowedToStretchChildAlongRowAxis || ComputedStyle::resolveJustificatio n(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { | |
| 1647 bool hasAutoMinSizeInRowAxis = isHorizontalMode ? child.style()->minWidt h().isAuto() : child.style()->minHeight().isAuto(); | |
| 1648 bool canShrinkToFitInRowAxisForChild = !hasAutoMinSizeInRowAxis || child .minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth( ); | |
|
svillar
2015/07/30 10:11:27
As a general comment, perhaps we should use styleR
jfernandez
2015/07/31 22:25:42
Good idea.
| |
| 1649 // TODO(lajava): how to handle orthogonality in this case ?. | |
| 1650 // TODO(lajava): grid track sizing and positioning do not support orthog onal modes yet. | |
| 1651 if (hasAutoSizeInRowAxis && canShrinkToFitInRowAxisForChild) { | |
| 1652 LayoutUnit childWidthToFitContent = std::max(std::min(child.maxPrefe rredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - child. marginLogicalWidth()), child.minPreferredLogicalWidth()); | |
| 1653 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMa x(childWidthToFitContent, -1); | |
| 1654 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.bor derAndPaddingLogicalWidth()); | |
| 1655 if (desiredLogicalWidth != child.logicalWidth()) | |
| 1656 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | |
| 1657 } | |
| 1646 } | 1658 } |
| 1647 | 1659 |
| 1648 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1660 bool hasAutoSizeInColumnAxis = isHorizontalMode ? child.style()->height().is Auto() : child.style()->width().isAuto(); |
| 1649 // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. | 1661 bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !chil d.style()->marginBeforeUsing(style()).isAuto() && !child.style()->marginAfterUsi ng(style()).isAuto(); |
| 1650 // FIXME: grid track sizing and positioning do not support orthogonal modes yet. | 1662 if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment( styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch) { |
| 1651 if (!hasOrthogonalWritingMode) { | 1663 // TODO (lajava): If the child has orthogonal flow, then it already has an override height set, so use it. |
| 1652 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor eStretching(gridAreaBreadthForChild, child); | 1664 // TODO (lajava): grid track sizing and positioning do not support ortho gonal modes yet. |
| 1665 if (child.isHorizontalWritingMode() != isHorizontalMode) | |
| 1666 return; | |
|
svillar
2015/07/30 10:11:27
Sorry for the back and forth but I agree that perh
jfernandez
2015/07/31 22:25:42
Acknowledged.
| |
| 1667 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor eStretching(child.overrideContainingBlockContentLogicalHeight(), child); | |
| 1653 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s tretchedLogicalHeight, -1); | 1668 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s tretchedLogicalHeight, -1); |
| 1654 | 1669 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borde rAndPaddingLogicalHeight()); |
| 1655 // FIXME: Can avoid laying out here in some cases. See https://webkit.or g/b/87905. | 1670 if (desiredLogicalHeight != child.logicalHeight()) { |
| 1656 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); | 1671 // TODO (lajava): Can avoid laying out here in some cases. See https ://webkit.org/b/87905. |
| 1657 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) | |
| 1658 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b orderAndPaddingLogicalHeight()); | |
| 1659 if (childNeedsRelayout) { | |
| 1660 child.setLogicalHeight(0); | 1672 child.setLogicalHeight(0); |
| 1661 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1673 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1662 } | 1674 } |
| 1663 } | 1675 } |
| 1664 } | 1676 } |
| 1665 | 1677 |
| 1666 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const | 1678 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const |
| 1667 { | 1679 { |
| 1668 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1680 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
| 1669 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode(); | 1681 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode(); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1923 | 1935 |
| 1924 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 1936 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); |
| 1925 } | 1937 } |
| 1926 | 1938 |
| 1927 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) | 1939 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) |
| 1928 { | 1940 { |
| 1929 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1941 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 1930 } | 1942 } |
| 1931 | 1943 |
| 1932 } // namespace blink | 1944 } // namespace blink |
| OLD | NEW |