Index: Source/core/layout/LayoutGrid.cpp |
diff --git a/Source/core/layout/LayoutGrid.cpp b/Source/core/layout/LayoutGrid.cpp |
index bbc127fec4d4b4a5055d2b86284633e04ea4c9ea..a8a928d7173f648d46693679fbe4d72e522607a9 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(); |
Manuel Rego
2015/07/23 09:41:26
Hey, missing child.style() in the first call!
jfernandez
2015/07/23 11:01:04
Done.
|
+} |
+ |
+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) |
-{ |
- if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { |
- child.clearOverrideLogicalContentHeight(); |
- return; |
+void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child) |
+{ |
+ child.clearOverrideSize(); |
+ |
+ if (!allowedToStretchChildAlongRowAxis(child) || ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) { |
+ // TODO(lajava): how to handle orthogonality in this case ?. |
+ // TODO(lajava): 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()); |
Manuel Rego
2015/07/23 09:41:26
Sorry but I've realized that the bug I reported fo
jfernandez
2015/07/23 11:01:04
Acknowledged.
|
+ 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); |
+ } |
} |
} |
} |