Chromium Code Reviews| Index: Source/core/rendering/RenderGrid.cpp |
| diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp |
| index 83059ac6bcbe342ba9848fdeb3416ab3463c5ccd..73b05795bbbde42c7aa9bd6f7508d4601c54c4ae 100644 |
| --- a/Source/core/rendering/RenderGrid.cpp |
| +++ b/Source/core/rendering/RenderGrid.cpp |
| @@ -1106,6 +1106,7 @@ 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; |
| } |
| @@ -1168,19 +1169,123 @@ LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const |
| return 0; |
| } |
| -LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| +LayoutUnit RenderGrid::endOfRowForChild(const RenderBox* child) const |
| { |
| const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| - // 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()]; |
| + // The grid items should be inside the grid container's border box, that's why they need to be shifted. |
| LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| - // FIXME: This function should account for 'align-self'. |
| + 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 RenderGrid::startOfRowForChild(const RenderBox* child) const |
| +{ |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + |
| + 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; |
| } |
| +LayoutUnit RenderGrid::centeredRowPositionForChild(const RenderBox* child) const |
| +{ |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + |
| + // 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()]; |
| + |
| + // FIXME: This should account for the grid item's <overflow-position>. |
| + return startOfRow + std::max<LayoutUnit>(0, endOfRow - startOfRow - child->logicalHeight()) / 2; |
| +} |
| + |
| +static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const RenderStyle* childStyle) |
| +{ |
| + ItemPosition align = childStyle->alignSelf(); |
| + // The auto keyword computes to the computed value of align-items on the parent. |
| + if (align == ItemPositionAuto) |
| + align = (parentStyle->alignItems() == ItemPositionAuto) ? ItemPositionStretch : parentStyle->alignItems(); |
| + return align; |
| +} |
|
Julien - ping for review
2014/07/10 22:59:59
I assume this code is temporary as we talked about
jfernandez
2014/07/12 22:29:48
Yes, still have to reach an agreement on issue 363
|
| + |
| +LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| +{ |
| + bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHorizontalWritingMode(); |
| + ItemPosition alignSelf = resolveAlignment(style(), child->style()); |
| + |
| + switch (alignSelf) { |
| + case ItemPositionSelfStart: |
| + // If orthogonal writing-modes, this computes to 'Start'. |
| + // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
| + if (hasOrthogonalWritingMode) |
| + return startOfRowForChild(child); |
| + |
| + // self-start is based on the child's direction. That's why we need to check against the grid container's direction. |
|
Julien - ping for review
2014/07/10 22:59:59
s/direction/block axis direction/
direction has a
jfernandez
2014/07/12 22:29:48
Done.
|
| + if (child->style()->writingMode() != style()->writingMode()) |
| + return endOfRowForChild(child); |
| + |
| + return startOfRowForChild(child); |
| + case ItemPositionSelfEnd: |
| + // If orthogonal writing-modes, this computes to 'End'. |
| + // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
| + if (hasOrthogonalWritingMode) |
| + return endOfRowForChild(child); |
| + |
| + // self-end is based on the child's direction. That's why we need to check against the grid container's direction. |
|
Julien - ping for review
2014/07/10 22:59:59
Same comment.
jfernandez
2014/07/12 22:29:48
Done.
|
| + if (child->style()->writingMode() != style()->writingMode()) |
| + return startOfRowForChild(child); |
| + |
| + return endOfRowForChild(child); |
| + |
| + case ItemPositionLeft: |
| + // orthogonal modes make property and inline axes to be parallel, but in any case |
| + // this is always equivalent to 'Start'. |
| + // |
| + // self-align's axis is never parallel to the inline axis, except in orthogonal |
| + // writing-mode, so this is equivalent to 'Start’. |
| + return startOfRowForChild(child); |
| + |
| + case ItemPositionRight: |
| + // orthogonal modes make property and inline axes to be parallel. |
| + // FIXME: grid track sizing and positioning does not support orthogonal modes yet. |
| + if (hasOrthogonalWritingMode) |
| + return endOfRowForChild(child); |
| + |
| + // self-align's axis is never parallel to the inline axis, except in orthogonal |
| + // writing-mode, so this is equivalent to 'Start'. |
| + return startOfRowForChild(child); |
| + |
| + case ItemPositionCenter: |
| + return centeredRowPositionForChild(child); |
| + // Only used in flex layout, for other layout, it's equivalent to 'Start'. |
| + case ItemPositionFlexStart: |
| + case ItemPositionStart: |
| + return startOfRowForChild(child); |
| + // Only used in flex layout, for other layout, it's equivalent to 'End'. |
| + case ItemPositionFlexEnd: |
| + case ItemPositionEnd: |
| + return endOfRowForChild(child); |
| + case ItemPositionStretch: |
| + // FIXME: Implement the Stretch value. For now, we always start align the child. |
| + return startOfRowForChild(child); |
| + case ItemPositionBaseline: |
| + // FIXME: Implement the ItemPositionBaseline value. For now, we always start align the child. |
| + return startOfRowForChild(child); |
| + case ItemPositionAuto: |
| + break; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const |
| { |
| return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)); |