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

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

Issue 1309513008: [css-grid] Implement grid gutters (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing v3 Created 5 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
Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
index ea88af2bb3a676f3f5f48e4f8fc7b7d10fbe8d93..3cae92bd15f0e1e9e0def01f20520db397f440d7 100644
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
@@ -348,6 +348,17 @@ void LayoutGrid::layoutBlock(bool relayoutChildren)
clearNeedsLayout();
}
+LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t span) const
+{
+ ASSERT(span >= 1);
+
+ if (span == 1)
+ return 0;
+
+ const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap() : styleRef().gridRowGap();
+ return valueForLength(trackGap, 0) * (span - 1);
+}
+
void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
{
const_cast<LayoutGrid*>(this)->placeItemsOnGrid();
@@ -364,6 +375,10 @@ void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
maxLogicalWidth += maxTrackBreadth;
}
+ LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTracks.size());
+ minLogicalWidth += totalGuttersSize;
+ maxLogicalWidth += totalGuttersSize;
+
LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth();
minLogicalWidth += scrollbarWidth;
maxLogicalWidth += scrollbarWidth;
@@ -937,6 +952,8 @@ void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
if (sizingData.filteredTracks.isEmpty())
continue;
+ spanningTracksSize += guttersSize(direction, itemSpan.integerSpan());
+
LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phase, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTracksSize;
extraSpace = std::max<LayoutUnit>(extraSpace, 0);
auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimitsTracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimitsTracks;
@@ -1292,6 +1309,11 @@ void LayoutGrid::layoutGridItems()
LayoutUnit availableSpaceForColumns = availableLogicalWidth();
LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorderPadding);
+
+ // Remove space consumed by gutters from the available logical space.
+ availableSpaceForColumns -= guttersSize(ForColumns, gridColumnCount());
+ availableSpaceForRows -= guttersSize(ForRows, gridRowCount());
+
GridSizingData sizingData(gridColumnCount(), gridRowCount());
computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColumns);
ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks));
@@ -1350,10 +1372,12 @@ void LayoutGrid::layoutGridItems()
m_gridItemsOverflowingGridArea.append(child);
}
+ LayoutUnit height = borderAndPaddingLogicalHeight() + scrollbarLogicalHeight();
for (const auto& row : sizingData.rowTracks)
- setLogicalHeight(logicalHeight() + row.baseSize());
+ height += row.baseSize();
+
+ height += guttersSize(ForRows, sizingData.rowTracks.size());
- LayoutUnit height = logicalHeight() + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight();
if (hasLineIfEmpty())
height = std::max(height, minimumLogicalHeightForEmptyLine());
@@ -1466,6 +1490,9 @@ LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
LayoutUnit gridAreaBreadth = 0;
for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span.end(); ++trackPosition)
gridAreaBreadth += tracks[trackPosition.toInt()].baseSize();
+
+ gridAreaBreadth += guttersSize(direction, span.integerSpan());
+
return gridAreaBreadth;
}
@@ -1485,7 +1512,7 @@ LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
void LayoutGrid::populateGridPositions(GridSizingData& sizingData, LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows)
{
- // Since we add alignment offsets, grid lines are not always adjacent. Hence we will have to
+ // Since we add alignment offsets and track gutters, grid lines are not always adjacent. Hence we will have to
// assume from now on that we just store positions of the initial grid lines of each track,
// except the last one, which is the only one considered as a final grid line of a track.
// FIXME: This will affect the computed style value of grid tracks size, since we are
@@ -1496,10 +1523,11 @@ void LayoutGrid::populateGridPositions(GridSizingData& sizingData, LayoutUnit av
unsigned lastLine = numberOfLines - 1;
unsigned nextToLastLine = numberOfLines - 2;
ContentAlignmentData offset = computeContentPositionAndDistributionOffset(ForColumns, availableSpaceForColumns, numberOfTracks);
+ LayoutUnit trackGap = guttersSize(ForColumns, 2);
m_columnPositions.resize(numberOfLines);
m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset;
for (unsigned i = 0; i < lastLine; ++i)
- m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOffset + sizingData.columnTracks[i].baseSize();
+ m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOffset + sizingData.columnTracks[i].baseSize() + trackGap;
m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData.columnTracks[nextToLastLine].baseSize();
numberOfTracks = sizingData.rowTracks.size();
@@ -1507,10 +1535,11 @@ void LayoutGrid::populateGridPositions(GridSizingData& sizingData, LayoutUnit av
lastLine = numberOfLines - 1;
nextToLastLine = numberOfLines - 2;
offset = computeContentPositionAndDistributionOffset(ForRows, availableSpaceForRows, numberOfTracks);
+ trackGap = guttersSize(ForRows, 2);
m_rowPositions.resize(numberOfLines);
m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset;
for (unsigned i = 0; i < lastLine; ++i)
- m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset + sizingData.rowTracks[i].baseSize();
+ m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset + sizingData.rowTracks[i].baseSize() + trackGap;
m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTracks[nextToLastLine].baseSize();
}
@@ -1806,7 +1835,12 @@ LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child) const
return startPosition;
case GridAxisEnd:
case GridAxisCenter: {
- LayoutUnit endOfRow = m_rowPositions[coordinate.rows.resolvedFinalPosition.next().toInt()];
+ size_t childEndLine = coordinate.rows.resolvedFinalPosition.next().toInt();
+ LayoutUnit endOfRow = m_rowPositions[childEndLine];
+ // m_rowPositions include gutters so we need to substract them to get the actual end position for a given
+ // row (this does not have to be done for the last track as there are no more m_rowPositions after it)
+ if (childEndLine < m_rowPositions.size() - 1)
+ endOfRow -= guttersSize(ForRows, 2);
LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.styleRef().alignSelfOverflowAlignment(), endOfRow - startOfRow, child.logicalHeight() + child.marginLogicalHeight());
return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2);
}
@@ -1829,7 +1863,12 @@ LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child) const
return startPosition;
case GridAxisEnd:
case GridAxisCenter: {
- LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.resolvedFinalPosition.next().toInt()];
+ size_t childEndLine = coordinate.columns.resolvedFinalPosition.next().toInt();
+ LayoutUnit endOfColumn = m_columnPositions[childEndLine];
+ // m_columnPositions include gutters so we need to substract them to get the actual end position for a given
+ // column (this does not have to be done for the last track as there are no more m_columnPositions after it)
+ if (childEndLine < m_columnPositions.size() - 1)
+ endOfColumn -= guttersSize(ForRows, 2);
LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, child.logicalWidth() + child.marginLogicalWidth());
return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2);
}

Powered by Google App Engine
This is Rietveld 408576698