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 | 1571 bool LayoutGrid::canShrinkToFitInRowAxisForChild(const LayoutBox& child) const |
| 1572 { | 1572 { |
| 1573 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | 1573 return !hasAutoMinSizeInRowAxis(child) || child.minPreferredLogicalWidth() < = child.overrideContainingBlockContentLogicalWidth(); |
| 1574 } | |
| 1575 | |
| 1576 bool LayoutGrid::hasAutoMinSizeInRowAxis(const LayoutBox& child) const | |
| 1577 { | |
| 1578 return isHorizontalWritingMode() ? child.style()->minWidth().isAuto() : chil d.style()->minHeight().isAuto(); | |
| 1579 } | |
|
svillar
2015/07/28 15:14:08
Let's not add a oneliner new function for a code t
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1580 | |
| 1581 bool LayoutGrid::hasAutoSizeInColumnAxisForChild(const LayoutBox& child) const | |
| 1582 { | |
| 1583 return isHorizontalWritingMode() ? child.style()->height().isAuto() : child. style()->width().isAuto(); | |
| 1584 } | |
|
svillar
2015/07/28 15:14:08
Ditto.
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1585 | |
| 1586 bool LayoutGrid::hasAutoSizeInRowAxisForChild(const LayoutBox& child) const | |
| 1587 { | |
| 1588 return isHorizontalWritingMode() ? child.style()->width().isAuto() : child.s tyle()->height().isAuto(); | |
| 1589 } | |
| 1590 | |
| 1591 bool LayoutGrid::allowedToStretchChildAlongColumnAxis(const LayoutBox& child) co nst | |
| 1592 { | |
| 1593 return hasAutoSizeInColumnAxisForChild(child) && !child.style()->marginBefor eUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); | |
| 1594 } | |
|
svillar
2015/07/28 15:14:08
Ditto.
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1595 | |
| 1596 bool LayoutGrid::allowedToStretchChildAlongRowAxis(const LayoutBox& child) const | |
| 1597 { | |
| 1598 return hasAutoSizeInRowAxisForChild(child) && !child.style()->marginStartUsi ng(style()).isAuto() && !child.style()->marginEndUsing(style()).isAuto(); | |
| 1574 } | 1599 } |
|
svillar
2015/07/28 15:14:08
Ditto.
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1575 | 1600 |
| 1576 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. | 1601 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. |
| 1577 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const | 1602 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const |
| 1578 { | 1603 { |
| 1579 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch) | 1604 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch) |
| 1580 return false; | 1605 return false; |
| 1581 | 1606 |
| 1582 return isHorizontalWritingMode() && child.style()->height().isAuto(); | 1607 return isHorizontalWritingMode() && child.style()->height().isAuto(); |
| 1583 } | 1608 } |
| 1584 | 1609 |
| (...skipping 46 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 | 1656 // 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 | 1657 // 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. | 1658 // compute margins in order to determine the available height before stretch ing. |
| 1634 if (childMarginLogicalHeight == 0) | 1659 if (childMarginLogicalHeight == 0) |
| 1635 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); | 1660 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); |
| 1636 | 1661 |
| 1637 return gridAreaBreadthForChild - childMarginLogicalHeight; | 1662 return gridAreaBreadthForChild - childMarginLogicalHeight; |
| 1638 } | 1663 } |
| 1639 | 1664 |
| 1640 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. | 1665 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. |
| 1641 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn it gridAreaBreadthForChild) | 1666 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
| 1642 { | 1667 { |
| 1643 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret ch) { | 1668 child.clearOverrideSize(); |
|
svillar
2015/07/28 15:14:08
I think we need a comment here explaining why we u
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1644 child.clearOverrideLogicalContentHeight(); | 1669 |
| 1645 return; | 1670 if (!allowedToStretchChildAlongRowAxis(child) || ComputedStyle::resolveJusti fication(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret ch) { |
| 1671 // TODO(lajava): how to handle orthogonality in this case ?. | |
| 1672 // TODO(lajava): grid track sizing and positioning do not support orthog onal modes yet. | |
| 1673 if (hasAutoSizeInRowAxisForChild(child) && canShrinkToFitInRowAxisForChi ld(child)) { | |
| 1674 LayoutUnit childWidthToFit = std::max(std::min(child.maxPreferredLog icalWidth(), child.overrideContainingBlockContentLogicalWidth() - child.marginL ogicalWidth()), child.minPreferredLogicalWidth()); | |
|
svillar
2015/07/28 15:14:07
Not a big fan of the variable name. Don't we have
jfernandez
2015/07/28 21:31:50
Well, this value is computed to fulfill the follow
svillar
2015/07/29 08:18:05
What about childFitContentWidth? Just to be cohere
| |
| 1675 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMa x(childWidthToFit, -1); | |
| 1676 bool childNeedsRelayout = desiredLogicalWidth != child.logicalWidth( ); | |
| 1677 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.bor derAndPaddingLogicalWidth()); | |
| 1678 if (childNeedsRelayout) { | |
| 1679 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | |
| 1680 } | |
|
svillar
2015/07/28 15:14:08
Remove braces.
Also you don't need the childNeeds
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1681 } | |
| 1646 } | 1682 } |
| 1647 | 1683 |
| 1648 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1684 if (allowedToStretchChildAlongColumnAxis(child) && ComputedStyle::resolveAli gnment(styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch ) { |
| 1649 // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. | 1685 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHor izontalWritingMode(); |
| 1650 // FIXME: grid track sizing and positioning do not support orthogonal modes yet. | 1686 // FIXME: If the child has orthogonal flow, then it already has an overr ide height set, so use it. |
|
svillar
2015/07/28 15:14:08
Use TODO()
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1651 if (!hasOrthogonalWritingMode) { | 1687 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. |
|
svillar
2015/07/28 15:14:08
Ditto.
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1652 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor eStretching(gridAreaBreadthForChild, child); | 1688 if (!hasOrthogonalWritingMode) { |
|
svillar
2015/07/28 15:34:14
Now that I think about this perhaps we should just
jfernandez
2015/07/28 21:31:50
I kind of agree; however, there is TODO specifical
svillar
2015/07/29 08:18:05
OK, let's keep it as you say then
| |
| 1653 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s tretchedLogicalHeight, -1); | 1689 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildB eforeStretching(child.overrideContainingBlockContentLogicalHeight(), child); |
| 1690 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM ax(stretchedLogicalHeight, -1); | |
| 1654 | 1691 |
| 1655 // FIXME: Can avoid laying out here in some cases. See https://webkit.or g/b/87905. | 1692 // FIXME: Can avoid laying out here in some cases. See https://webki t.org/b/87905. |
| 1656 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); | 1693 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeigh t(); |
| 1657 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) | |
| 1658 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b orderAndPaddingLogicalHeight()); | 1694 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b orderAndPaddingLogicalHeight()); |
| 1659 if (childNeedsRelayout) { | 1695 if (childNeedsRelayout) { |
|
svillar
2015/07/28 15:14:08
Same comment about childNeedsRelayout.
jfernandez
2015/07/28 21:31:50
Done.
| |
| 1660 child.setLogicalHeight(0); | 1696 child.setLogicalHeight(0); |
| 1661 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1697 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1698 } | |
| 1662 } | 1699 } |
| 1663 } | 1700 } |
| 1664 } | 1701 } |
| 1665 | 1702 |
| 1666 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const | 1703 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const |
| 1667 { | 1704 { |
| 1668 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); | 1705 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); |
| 1669 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode(); | 1706 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode(); |
| 1670 | 1707 |
| 1671 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { | 1708 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1923 | 1960 |
| 1924 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); | 1961 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); |
| 1925 } | 1962 } |
| 1926 | 1963 |
| 1927 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) | 1964 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) |
| 1928 { | 1965 { |
| 1929 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1966 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 1930 } | 1967 } |
| 1931 | 1968 |
| 1932 } // namespace blink | 1969 } // namespace blink |
| OLD | NEW |