Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1477)

Unified Diff: Source/core/layout/LayoutGrid.cpp

Issue 1228983003: [CSS Grid Layout] Do not stretch always grid items with auto width (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/layout/LayoutGrid.cpp
diff --git a/Source/core/layout/LayoutGrid.cpp b/Source/core/layout/LayoutGrid.cpp
index bbc127fec4d4b4a5055d2b86284633e04ea4c9ea..363e7f0a95f8b97aa67c686c04cea3e0f3f3a804 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();
@@ -1458,6 +1458,11 @@ bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c
return child.style()->logicalHeight().isAuto() && !child.style()->marginBeforeUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto();
}
+bool LayoutGrid::allowedToStretchLogicalWidthForChild(const LayoutBox& child) const
+{
+ return child.style()->logicalWidth().isAuto() && !child.style()->marginStartUsing(style()).isAuto() && !child.style()->marginEndUsing(style()).isAuto();
+}
+
// FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to LayoutBox.
bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const
{
@@ -1523,18 +1528,27 @@ 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 (!allowedToStretchLogicalWidthForChild(child) || ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch) {
+ if (child.style()->logicalWidth().isAuto()) {
+ LayoutUnit childPreferredWidth = child.maxPreferredLogicalWidth();
+ child.setOverrideLogicalContentWidth(childPreferredWidth - child.borderAndPaddingLogicalWidth());
+ if (childPreferredWidth != child.logicalWidth())
+ child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
+ }
}
+ if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStretch)
+ return;
+
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 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.

Powered by Google App Engine
This is Rietveld 408576698