| Index: Source/core/layout/LayoutGrid.cpp
|
| diff --git a/Source/core/layout/LayoutGrid.cpp b/Source/core/layout/LayoutGrid.cpp
|
| index b77a7c8c2ba439c6e4e151dbe4894a78af2c0341..02258933e72bcfa4c682fb2f0ddd617b3174a114 100644
|
| --- a/Source/core/layout/LayoutGrid.cpp
|
| +++ b/Source/core/layout/LayoutGrid.cpp
|
| @@ -1345,7 +1345,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();
|
|
|
| @@ -1552,11 +1552,6 @@ static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
|
| return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeight + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight);
|
| }
|
|
|
| -bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) const
|
| -{
|
| - return child.style()->logicalHeight().isAuto() && !child.style()->marginBeforeUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto();
|
| -}
|
| -
|
| // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to LayoutBox.
|
| bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const
|
| {
|
| @@ -1622,27 +1617,44 @@ 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)
|
| -{
|
| - if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) {
|
| - child.clearOverrideLogicalContentHeight();
|
| - return;
|
| +void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child)
|
| +{
|
| + // We clear both width and height override values because we will decide now whether they
|
| + // are allowed or not, evaluating the conditions which might have changed since the old
|
| + // values were set.
|
| + child.clearOverrideSize();
|
| +
|
| + bool isHorizontalMode = isHorizontalWritingMode();
|
| + bool hasAutoSizeInRowAxis = isHorizontalMode ? child.styleRef().width().isAuto() : child.styleRef().height().isAuto();
|
| + bool allowedToStretchChildAlongRowAxis = hasAutoSizeInRowAxis && !child.styleRef().marginStartUsing(style()).isAuto() && !child.styleRef().marginEndUsing(style()).isAuto();
|
| + if (!allowedToStretchChildAlongRowAxis || ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) {
|
| + bool hasAutoMinSizeInRowAxis = isHorizontalMode ? child.styleRef().minWidth().isAuto() : child.styleRef().minHeight().isAuto();
|
| + bool canShrinkToFitInRowAxisForChild = !hasAutoMinSizeInRowAxis || child.minPreferredLogicalWidth() <= child.overrideContainingBlockContentLogicalWidth();
|
| + // TODO(lajava): how to handle orthogonality in this case ?.
|
| + // TODO(lajava): grid track sizing and positioning do not support orthogonal modes yet.
|
| + if (hasAutoSizeInRowAxis && canShrinkToFitInRowAxisForChild) {
|
| + LayoutUnit childWidthToFitContent = std::max(std::min(child.maxPreferredLogicalWidth(), child.overrideContainingBlockContentLogicalWidth() - child.marginLogicalWidth()), child.minPreferredLogicalWidth());
|
| + LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMax(childWidthToFitContent, -1);
|
| + child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.borderAndPaddingLogicalWidth());
|
| + if (desiredLogicalWidth != child.logicalWidth())
|
| + 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())
|
| + bool hasAutoSizeInColumnAxis = isHorizontalMode ? child.styleRef().height().isAuto() : child.styleRef().width().isAuto();
|
| + bool allowedToStretchChildAlongColumnAxis = hasAutoSizeInColumnAxis && !child.styleRef().marginBeforeUsing(style()).isAuto() && !child.styleRef().marginAfterUsing(style()).isAuto();
|
| + if (allowedToStretchChildAlongColumnAxis && ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch) {
|
| + // TODO (lajava): If the child has orthogonal flow, then it already has an override height set, so use it.
|
| + // TODO (lajava): grid track sizing and positioning do not support orthogonal modes yet.
|
| + if (child.isHorizontalWritingMode() == isHorizontalMode) {
|
| + LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBeforeStretching(child.overrideContainingBlockContentLogicalHeight(), child);
|
| + LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(stretchedLogicalHeight, -1);
|
| child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.borderAndPaddingLogicalHeight());
|
| - if (childNeedsRelayout) {
|
| - child.setLogicalHeight(0);
|
| - child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
|
| + if (desiredLogicalHeight != child.logicalHeight()) {
|
| + // TODO (lajava): Can avoid laying out here in some cases. See https://webkit.org/b/87905.
|
| + child.setLogicalHeight(0);
|
| + child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
|
| + }
|
| }
|
| }
|
| }
|
|
|