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..792f8487f151d14fd509abf98f103ae2ca87c1dd 100644 |
| --- a/Source/core/rendering/RenderGrid.cpp |
| +++ b/Source/core/rendering/RenderGrid.cpp |
| @@ -1087,13 +1087,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 +1163,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 +1501,87 @@ LayoutUnit RenderGrid::rowPositionForChild(const RenderBox& child) const |
| return 0; |
| } |
| +LayoutUnit static contentDistributionOffset(LayoutUnit availableFreeSpace, ContentPosition& fallbackPosition, ContentDistributionType distribution, unsigned numberOfItems) |
|
Julien - ping for review
2014/11/13 01:37:24
Note that numberOfItems is not great as it could r
jfernandez
2014/11/13 12:22:35
Well, I tried to use the term defined in the Box A
Julien - ping for review
2014/11/13 16:43:31
numberOfTracks is a good name, even better numberO
jfernandez
2014/11/14 15:32:32
Done.
|
| +{ |
| + ASSERT(numberOfItems > 0); |
| + |
| + switch (distribution) { |
| + case ContentDistributionSpaceBetween: |
| + if (fallbackPosition == ContentPositionAuto) |
| + fallbackPosition = ContentPositionStart; |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionSpaceAround: |
| + if (fallbackPosition == ContentPositionAuto) |
| + fallbackPosition = ContentPositionCenter; |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionSpaceEvenly: |
| + if (fallbackPosition == ContentPositionAuto) |
| + fallbackPosition = ContentPositionCenter; |
| + // FIXME: for the time being, spec states that it will always fallback for Grids, but |
| + // discussion is ongoing. |
| + return -1; |
| + case ContentDistributionStretch: |
| + if (fallbackPosition == ContentPositionAuto) |
| + fallbackPosition = ContentPositionStart; |
| + // 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; |
| + } |
| + |
| + return -1; |
| +} |
| + |
| +LayoutUnit RenderGrid::contentPositionAndDistributionOffset(LayoutUnit availableFreeSpace, ContentPosition position, ContentDistributionType distribution, unsigned numberOfItems) const |
| +{ |
| + LayoutUnit offset = contentDistributionOffset(availableFreeSpace, position, distribution, numberOfItems); |
|
Julien - ping for review
2014/11/13 01:37:24
This function is stubbed so it's hard to see what
jfernandez
2014/11/13 12:22:35
Acknowledged.
|
| + 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; |
|
Julien - ping for review
2014/11/13 01:37:24
I think this should account for the children's siz
jfernandez
2014/11/13 12:22:35
I don't understand what you mean here; content ali
Julien - ping for review
2014/11/13 16:43:31
I didn't mean as we should change the grid items'
jfernandez
2014/11/14 15:32:32
I'm not sure whether you notice that availableSpac
Julien - ping for review
2014/11/18 16:14:36
I missed that. With that fact, the logic makes mor
jfernandez
2014/11/20 11:59:39
Done.
|
| + 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; |
| + default: |
|
Julien - ping for review
2014/11/13 01:37:24
We seems to be missing one case ContentPositionAut
jfernandez
2014/11/13 12:22:35
Auto value is resolved by the StyleAdjuster. It co
Julien - ping for review
2014/11/13 16:43:31
I don't think StyleAdjuster would work as the comp
jfernandez
2014/11/14 15:32:32
Acknowledged.
|
| + ASSERT_NOT_REACHED(); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox& child) const |
| { |
| return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)); |