Chromium Code Reviews| Index: Source/core/layout/LayoutGrid.cpp |
| diff --git a/Source/core/layout/LayoutGrid.cpp b/Source/core/layout/LayoutGrid.cpp |
| index bbc127fec4d4b4a5055d2b86284633e04ea4c9ea..7f5e967b8a477e50dcd3d0d519e9e55aa41aff6f 100644 |
| --- a/Source/core/layout/LayoutGrid.cpp |
| +++ b/Source/core/layout/LayoutGrid.cpp |
| @@ -1275,7 +1275,7 @@ void LayoutGrid::layoutGridItems() |
| // Stretching logic might force a child layout, so we need to run it before the layoutIfNeeded |
| // call to avoid unnecessary relayouts. This might imply that child margins, needed to correctly |
| // determine the available space before stretching, are not set yet. |
| - applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockContentLogicalHeight); |
| + applyStretchAlignmentToChildIfNeeded(*child); |
| child->layoutIfNeeded(); |
| @@ -1453,9 +1453,34 @@ static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay |
| return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeight + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
| } |
| -bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) const |
| +bool LayoutGrid::canShrinkToFitInRowAxisForChild(const LayoutBox& child) const |
| { |
| - return child.style()->logicalHeight().isAuto() && !child.style()->marginBeforeUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); |
| + return !hasAutoMinSizeInRowAxis(child) || child.minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth(); |
| +} |
| + |
| +bool LayoutGrid::hasAutoMinSizeInRowAxis(const LayoutBox& child) const |
| +{ |
| + return isHorizontalWritingMode() ? style()->minWidth().isAuto() : child.style()->minHeight().isAuto(); |
| +} |
| + |
| +bool LayoutGrid::hasAutoSizeInColumnAxisForChild(const LayoutBox& child) const |
| +{ |
| + return isHorizontalWritingMode() ? child.style()->height().isAuto() : child.style()->width().isAuto(); |
| +} |
| + |
| +bool LayoutGrid::hasAutoSizeInRowAxisForChild(const LayoutBox& child) const |
| +{ |
| + return isHorizontalWritingMode() ? child.style()->width().isAuto() : child.style()->height().isAuto(); |
| +} |
| + |
| +bool LayoutGrid::allowedToStretchChildAlongColumnAxis(const LayoutBox& child) const |
| +{ |
| + return hasAutoSizeInColumnAxisForChild(child) && !child.style()->marginBeforeUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); |
| +} |
| + |
| +bool LayoutGrid::allowedToStretchChildAlongRowAxis(const LayoutBox& child) const |
| +{ |
| + return hasAutoSizeInRowAxisForChild(child) && !child.style()->marginStartUsing(style()).isAuto() && !child.style()->marginEndUsing(style()).isAuto(); |
| } |
| // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to LayoutBox. |
| @@ -1523,27 +1548,39 @@ LayoutUnit LayoutGrid::availableAlignmentSpaceForChildBeforeStretching(LayoutUni |
| } |
| // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to LayoutBox. |
| -void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUnit gridAreaBreadthForChild) |
| +void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
| { |
| - if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { |
| - child.clearOverrideLogicalContentHeight(); |
| - return; |
| + child.clearOverrideSize(); |
| + |
| + if (!allowedToStretchChildAlongRowAxis(child) || ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { |
| + // FIXME: how to handle orthogonality in this case ?. |
|
Manuel Rego
2015/07/16 10:45:05
Nit: Use the new agreement TODO(nick)
https://www
jfernandez
2015/07/16 11:06:03
Done.
|
| + // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| + if (hasAutoSizeInRowAxisForChild(child) && canShrinkToFitInRowAxisForChild(child)) { |
| + LayoutUnit childWidthToFit = std::min(child.maxPreferredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - child.marginLogicalWidth()); |
| + LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMax(childWidthToFit, -1); |
| + bool childNeedsRelayout = desiredLogicalWidth != child.logicalWidth(); |
| + child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.borderAndPaddingLogicalWidth()); |
| + if (childNeedsRelayout) { |
| + child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| + } |
| + } |
| } |
| - bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizontalWritingMode(); |
| - // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - if (!hasOrthogonalWritingMode) { |
| - LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(gridAreaBreadthForChild, child); |
| - LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, -1); |
| - |
| - // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905. |
| - bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); |
| - if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight()) |
| + if (allowedToStretchChildAlongColumnAxis(child) && ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch) { |
| + bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizontalWritingMode(); |
| + // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. |
| + // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| + if (!hasOrthogonalWritingMode) { |
| + LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(child.overrideContainingBlockContentLogicalHeight(), child); |
| + LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, -1); |
| + |
| + // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905. |
| + bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); |
| child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borderAndPaddingLogicalHeight()); |
| - if (childNeedsRelayout) { |
| - child.setLogicalHeight(0); |
| - child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| + if (childNeedsRelayout) { |
| + child.setLogicalHeight(0); |
| + child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| + } |
| } |
| } |
| } |