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

Unified Diff: Source/core/rendering/RenderGrid.cpp

Issue 614263005: [CSS Grid Layout] overflow-position keyword for align and justify properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Default overflow can't be resolved in the adjuster. Created 6 years, 2 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
« no previous file with comments | « LayoutTests/fast/css-grid-layout/grid-align-justify-overflow-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderGrid.cpp
diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp
index 8ad2d787df8d70497a998b80100fb615d471e3d6..30130b977b7b6cf8fb96c6c7fbd5c9d5139bcff7 100644
--- a/Source/core/rendering/RenderGrid.cpp
+++ b/Source/core/rendering/RenderGrid.cpp
@@ -1166,12 +1166,27 @@ void RenderGrid::populateGridPositions(const GridSizingData& sizingData)
m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_usedBreadth;
}
+static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, LayoutUnit startOfTrack, LayoutUnit endOfTrack, LayoutUnit childBreadth)
+{
+ LayoutUnit trackBreadth = endOfTrack - startOfTrack;
+ LayoutUnit offset = trackBreadth - childBreadth;
+
+ // If overflow is 'safe', we have to make sure we don't overflow the 'start'
+ // edge (potentially cause some data loss as the overflow is unreachable).
+ if (overflow == OverflowAlignmentSafe)
+ offset = std::max<LayoutUnit>(0, offset);
+
+ // If we overflow our alignment container and overflow is 'true' (default), we
+ // ignore the overflow and just return the value regardless (which may cause data
+ // loss as we overflow the 'start' edge).
+ return offset;
+}
+
LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox& child) const
{
const GridCoordinate& coordinate = cachedGridCoordinate(child);
LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInitialPosition.toInt()];
// The grid items should be inside the grid container's border box, that's why they need to be shifted.
- // FIXME: This should account for the grid item's <overflow-position>.
return startOfColumn + marginStartForChild(&child);
}
@@ -1183,8 +1198,9 @@ LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox& child) const
LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child);
LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalPosition.next().toInt()];
- // FIXME: This should account for the grid item's <overflow-position>.
- return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositions[coordinate.columns.resolvedInitialPosition.toInt()] - child.logicalWidth());
+ LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.style()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logicalWidth());
+
+ return columnPosition + offsetFromColumnPosition;
}
LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderBox& child) const
@@ -1209,8 +1225,9 @@ LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox& child) co
LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.resolvedInitialPosition.toInt()];
LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalPosition.next().toInt()];
LayoutUnit columnPosition = startOfColumn + marginStartForChild(&child);
- // FIXME: This should account for the grid item's <overflow-position>.
- return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child.logicalWidth()) / 2;
+ LayoutUnit offsetFromColumnPosition = computeOverflowAlignmentOffset(child.style()->justifySelfOverflowAlignment(), startOfColumn, endOfColumn, child.logicalWidth());
+
+ return columnPosition + offsetFromColumnPosition / 2;
}
static ItemPosition resolveJustification(const RenderStyle* parentStyle, const RenderStyle* childStyle)
@@ -1218,7 +1235,6 @@ static ItemPosition resolveJustification(const RenderStyle* parentStyle, const R
ItemPosition justify = childStyle->justifySelf();
if (justify == ItemPositionAuto)
justify = (parentStyle->justifyItems() == ItemPositionAuto) ? ItemPositionStretch : parentStyle->justifyItems();
-
return justify;
}
@@ -1305,8 +1321,9 @@ LayoutUnit RenderGrid::endOfRowForChild(const RenderBox& child) const
LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child);
LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.next().toInt()];
- // FIXME: This should account for the grid item's <overflow-position>.
- return rowPosition + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.logicalHeight());
+ LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.style()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight());
+
+ return rowPosition + offsetFromRowPosition;
}
LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const
@@ -1315,7 +1332,6 @@ LayoutUnit RenderGrid::startOfRowForChild(const RenderBox& child) const
LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPosition.toInt()];
// The grid items should be inside the grid container's border box, that's why they need to be shifted.
- // FIXME: This should account for the grid item's <overflow-position>.
LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child);
return rowPosition;
@@ -1328,17 +1344,17 @@ LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox& child) const
// The grid items should be inside the grid container's border box, that's why they need to be shifted.
LayoutUnit startOfRow = m_rowPositions[coordinate.rows.resolvedInitialPosition.toInt()] + marginBeforeForChild(&child);
LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.next().toInt()];
+ LayoutUnit rowPosition = startOfRow + marginBeforeForChild(&child);
+ LayoutUnit offsetFromRowPosition = computeOverflowAlignmentOffset(child.style()->alignSelfOverflowAlignment(), startOfRow, endOfRow, child.logicalHeight());
- // FIXME: This should account for the grid item's <overflow-position>.
- return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child.logicalHeight()) / 2;
+ return rowPosition + offsetFromRowPosition / 2;
}
LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const
{
bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizontalWritingMode();
- ItemPosition alignSelf = RenderStyle::resolveAlignment(style(), child.style());
- switch (alignSelf) {
+ switch (RenderStyle::resolveAlignment(style(), child.style())) {
case ItemPositionSelfStart:
// If orthogonal writing-modes, this computes to 'Start'.
// FIXME: grid track sizing and positioning does not support orthogonal modes yet.
« no previous file with comments | « LayoutTests/fast/css-grid-layout/grid-align-justify-overflow-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698