Chromium Code Reviews| Index: Source/core/rendering/RenderGrid.cpp |
| diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp |
| index 11474d6b9153b483983e0f05f4bbff8f4b23fdc0..662b7447d14e76c57681c05c3e3698a7e57f1b8f 100644 |
| --- a/Source/core/rendering/RenderGrid.cpp |
| +++ b/Source/core/rendering/RenderGrid.cpp |
| @@ -507,6 +507,9 @@ void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi |
| tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackIndex].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()); |
| } |
| + |
| + // Flexible tracks will exhaust the availableLogicalSpace. |
|
Julien - ping for review
2014/11/18 16:14:36
You're making one assumption here, which is that o
jfernandez
2014/11/20 11:59:39
Acknowledged.
|
| + availableLogicalSpace = 0; |
| } |
| LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection direction, const GridLength& gridLength) const |
| @@ -1087,13 +1090,15 @@ void RenderGrid::layoutGridItems() |
| { |
| placeItemsOnGrid(); |
| + LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| + LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorderPadding); |
| GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| - computeUsedBreadthOfGridTracks(ForColumns, sizingData); |
| + computeUsedBreadthOfGridTracks(ForColumns, sizingData, availableSpaceForColumns); |
| ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData.columnTracks)); |
| - computeUsedBreadthOfGridTracks(ForRows, sizingData); |
| + computeUsedBreadthOfGridTracks(ForRows, sizingData, availableSpaceForRows); |
| ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData.rowTracks)); |
| - populateGridPositions(sizingData); |
| + populateGridPositions(sizingData, availableSpaceForColumns, availableSpaceForRows); |
| m_gridItemsOverflowingGridArea.resize(0); |
| for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) { |
| @@ -1161,10 +1166,13 @@ LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrack |
| return gridAreaBreadth; |
| } |
| -void RenderGrid::populateGridPositions(const GridSizingData& sizingData) |
| +void RenderGrid::populateGridPositions(const GridSizingData& sizingData, LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
| { |
| - m_columnPositions.resize(sizingData.columnTracks.size() + 1); |
| - m_columnPositions[0] = borderAndPaddingStart(); |
| + unsigned numberOfColumnTracks = sizingData.columnTracks.size(); |
| + LayoutUnit columnOffset = contentPositionAndDistributionOffset(availableSpaceForColumns, style()->justifyContent(), style()->justifyContentDistribution(), numberOfColumnTracks); |
| + |
| + m_columnPositions.resize(numberOfColumnTracks + 1); |
| + m_columnPositions[0] = borderAndPaddingStart() + columnOffset; |
| for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
| m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTracks[i].m_usedBreadth; |
| @@ -1496,6 +1504,105 @@ LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
| return 0; |
| } |
| +ContentPosition static resolveContentDistributionFallback(ContentDistributionType distribution) |
| +{ |
| + switch (distribution) { |
| + case ContentDistributionSpaceBetween: |
| + return ContentPositionStart; |
| + case ContentDistributionSpaceAround: |
| + return ContentPositionCenter; |
| + case ContentDistributionSpaceEvenly: |
| + return ContentPositionCenter; |
| + case ContentDistributionStretch: |
| + return ContentPositionStart; |
| + case ContentDistributionDefault: |
| + return ContentPositionAuto; |
| + default: |
|
Julien - ping for review
2014/11/18 16:14:36
Why do we need a default? Your reflex should be to
jfernandez
2014/11/20 11:59:39
My idea of the default option in these cases was t
|
| + ASSERT_NOT_REACHED(); |
| + } |
| + |
| + return ContentPositionAuto; |
| +} |
| + |
| +LayoutUnit static contentDistributionOffset(LayoutUnit availableFreeSpace, ContentPosition& fallbackPosition, ContentDistributionType distribution, unsigned numberOfGridTracks) |
| +{ |
| + ASSERT(numberOfGridTracks > 0); |
| + |
| + if (fallbackPosition == ContentPositionAuto) |
| + fallbackPosition = resolveContentDistributionFallback(distribution); |
| + |
| + switch (distribution) { |
| + case ContentDistributionSpaceBetween: |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionSpaceAround: |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionSpaceEvenly: |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionStretch: |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionDefault: |
| + return -1; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + |
| + return -1; |
| +} |
|
Julien - ping for review
2014/11/18 16:14:36
This function is really artificial as I pointed ou
jfernandez
2014/11/20 11:59:39
Acknowledged.
|
| + |
| +LayoutUnit RenderGrid::contentPositionAndDistributionOffset(LayoutUnit availableFreeSpace, ContentPosition position, ContentDistributionType distribution, unsigned numberOfGridTracks) const |
| +{ |
| + if (availableFreeSpace <= 0) |
| + return 0; |
| + |
| + LayoutUnit offset = contentDistributionOffset(availableFreeSpace, position, distribution, numberOfGridTracks); |
| + if (offset >= 0) |
| + return offset; |
| + |
| + switch (position) { |
| + case ContentPositionLeft: |
| + // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. |
| + if (!isHorizontalWritingMode()) |
| + return 0; |
| + if (style()->isLeftToRightDirection()) |
| + return 0; |
| + return availableFreeSpace; |
| + case ContentPositionRight: |
| + // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. |
| + if (!isHorizontalWritingMode()) |
| + return 0; |
| + if (style()->isLeftToRightDirection()) |
| + return availableFreeSpace; |
| + return 0; |
| + case ContentPositionCenter: |
| + return availableFreeSpace / 2; |
| + case ContentPositionFlexEnd: |
| + // Only used in flex layout, for other layout, it's equivalent to 'End'. |
| + case ContentPositionEnd: |
| + return availableFreeSpace; |
| + case ContentPositionFlexStart: |
| + // Only used in flex layout, for other layout, it's equivalent to 'Start'. |
| + case ContentPositionStart: |
| + return 0; |
| + case ContentPositionBaseline: |
| + case ContentPositionLastBaseline: |
| + // FIXME: Implement the previous values. For now, we always start align. |
| + return 0; |
| + case ContentPositionAuto: |
| + default: |
|
Julien - ping for review
2014/11/18 16:14:36
I have not seen an explanation for keeping the 'de
jfernandez
2014/11/20 11:59:39
Done.
|
| + ASSERT_NOT_REACHED(); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const |
| { |
| return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)); |