Chromium Code Reviews| Index: Source/core/rendering/RenderGrid.cpp |
| diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp |
| index 36fb8e077ab2fdc938b484214339807b3d9f0225..12ddedcebc410af9d11a4c841912321fb9da65a4 100644 |
| --- a/Source/core/rendering/RenderGrid.cpp |
| +++ b/Source/core/rendering/RenderGrid.cpp |
| @@ -880,7 +880,12 @@ void RenderGrid::layoutGridItems() |
| // now, just size as if we were a regular child. |
| child->layoutIfNeeded(); |
| - child->setLogicalLocation(findChildLogicalPosition(child, sizingData)); |
| +#ifndef NDEBUG |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.size()); |
| + ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); |
| +#endif |
| + child->setLogicalLocation(findChildLogicalPosition(child)); |
| // For correctness, we disable some painting optimizations if we have a child overflowing its grid area. |
| m_gridItemOverflowGridArea = child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
| @@ -1083,14 +1088,120 @@ void RenderGrid::populateGridPositions(const GridSizingData& sizingData) |
| m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_usedBreadth; |
| } |
| -LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const GridSizingData& sizingData) |
| +LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderBox* child) const |
| +{ |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPositionIndex]; |
| + // The grid items should be inside the grid container's border box, that's why they need to be shifted. |
| + LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| + |
| + if (style()->isLeftToRightDirection()) |
| + return columnPosition; |
| + |
| + LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionIndex + 1]; |
| + // FIXME: This should account for the grid item's <overflow-position>. |
| + return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()); |
| +} |
| + |
| +LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox* child) const |
|
ojan
2014/01/28 21:38:05
Am I just misreading the code or is the exactly th
ojan
2014/01/28 23:13:07
Oh, I missed the !. You could avoid the code dupli
Julien - ping for review
2014/01/29 00:11:56
That's a good catch. I think it makes more sense t
|
| +{ |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPositionIndex]; |
| + // The grid items should be inside the grid container's border box, that's why they need to be shifted. |
| + LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| + |
| + if (!style()->isLeftToRightDirection()) |
| + return columnPosition; |
| + |
| + LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionIndex + 1]; |
| + // FIXME: This should account for the grid item's <overflow-position>. |
| + return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()); |
| +} |
| + |
| +LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) const |
| +{ |
| + const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| + LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPositionIndex]; |
| + LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionIndex + 1]; |
| + LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| + return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn - child->logicalWidth()) / 2; |
| +} |
| + |
| +LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const |
| +{ |
| + ItemPosition childJustifySelf = child->style()->justifySelf(); |
| + switch (childJustifySelf) { |
| + case ItemPositionSelfStart: |
| + // self-start is based on the child's direction. That's why we need to check against the grid container's direction. |
| + if (child->style()->direction() != style()->direction()) |
| + return columnPositionAlignedWithGridContainerEnd(child); |
| + |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + case ItemPositionSelfEnd: |
| + // self-end is based on the child's direction. That's why we need to check against the grid container's direction. |
| + if (child->style()->direction() != style()->direction()) |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + return columnPositionAlignedWithGridContainerEnd(child); |
| + |
| + case ItemPositionFlexStart: |
| + case ItemPositionFlexEnd: |
| + // Only used in flex layout, for other layout, it's equivalent to 'start'. |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + case ItemPositionLeft: |
| + // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. |
| + if (!isHorizontalWritingMode()) |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + if (style()->isLeftToRightDirection()) |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + return columnPositionAlignedWithGridContainerEnd(child); |
| + case ItemPositionRight: |
| + // If the property's axis is not parallel with the inline axis, this is equivalent to ‘start’. |
| + if (!isHorizontalWritingMode()) |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + if (style()->isLeftToRightDirection()) |
| + return columnPositionAlignedWithGridContainerEnd(child); |
| + |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + |
| + case ItemPositionCenter: |
| + return centeredColumnPositionForChild(child); |
| + case ItemPositionStart: |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + case ItemPositionEnd: |
| + return columnPositionAlignedWithGridContainerEnd(child); |
| + |
| + case ItemPositionAuto: |
| + case ItemPositionStretch: |
| + case ItemPositionBaseline: |
| + // FIXME: Implement the previous values. For now, we just return 'start'. |
| + return columnPositionAlignedWithGridContainerStart(child); |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| +LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| { |
| const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| - ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks.size()); |
| - ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size()); |
| // The grid items should be inside the grid container's border box, that's why they need to be shifted. |
| - return LayoutPoint(m_columnPositions[coordinate.columns.initialPositionIndex] + marginStartForChild(child), m_rowPositions[coordinate.rows.initialPositionIndex] + marginBeforeForChild(child)); |
| + LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex]; |
| + LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| + |
| + // FIXME: This function should account for 'align-self'. |
| + |
| + return rowPosition; |
| +} |
| + |
| +LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const |
| +{ |
| + return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)); |
| } |
| static GridSpan dirtiedGridAreas(const Vector<LayoutUnit>& coordinates, LayoutUnit start, LayoutUnit end) |