Chromium Code Reviews| 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 6d8864e4a0d6d97a786ebe9bb66b5cfebf6bd4b9..de0a3753c1a469a9aa59ab8cbe98686c26edac9e 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| @@ -1670,6 +1670,18 @@ void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection |
| availableSpace = LayoutUnit(); |
| } |
| +bool LayoutGrid::childOverflowingContainingBlockHeight(const LayoutBox& child) const |
| +{ |
| + LayoutUnit containingBlockContentHeight = child.hasOverrideContainingBlockHeight() ? child.overrideContainingBlockContentHeight() : LayoutUnit(); |
| + return child.size().height() > containingBlockContentHeight; |
|
cbiesinger
2016/06/23 18:35:12
Don't you need to add the margin-top to the child'
jfernandez
2016/06/24 12:59:15
Umm, that's a good question. The issue is that we
Manuel Rego
2016/07/14 10:13:31
Indeed there's a bug here, I've just reported it:
|
| +} |
| + |
| +bool LayoutGrid::childOverflowingContainingBlockWidth(const LayoutBox& child) const |
| +{ |
| + LayoutUnit containingBlockContentWidth = child.hasOverrideContainingBlockWidth() ? child.overrideContainingBlockContentWidth() : LayoutUnit(); |
| + return child.size().width() > containingBlockContentWidth; |
|
cbiesinger
2016/06/23 18:35:12
same question here
jfernandez
2016/06/24 12:59:15
Done.
|
| +} |
| + |
| void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
| { |
| populateGridPositionsForDirection(sizingData, ForColumns); |
| @@ -1691,7 +1703,7 @@ void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
| LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); |
| SubtreeLayoutScope layoutScope(*child); |
| - if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight && (child->hasRelativeLogicalHeight() || isOrthogonalChild(*child)))) |
| + if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
| layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChanged); |
| child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth); |
| @@ -1716,9 +1728,10 @@ void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
| child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
| // Keep track of children overflowing their grid area as we might need to paint them even if the grid-area is |
| - // not visible |
| - if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
| - || child->logicalWidth() > overrideContainingBlockContentLogicalWidth) |
| + // not visible. |
| + // Using physical dimensions for simplicity, so we can forget about orthogonalty. |
| + if (childOverflowingContainingBlockHeight(*child) |
| + || childOverflowingContainingBlockWidth(*child)) |
|
svillar
2016/07/13 09:00:40
I think we lack a test for this change.
jfernandez
2016/07/14 09:29:15
Done.
|
| m_gridItemsOverflowingGridArea.append(child); |
| } |
| } |
| @@ -1941,9 +1954,9 @@ void LayoutGrid::populateGridPositionsForDirection(GridSizingData& sizingData, G |
| offsetBetweenTracks = offset.distributionOffset; |
| } |
| -static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, LayoutUnit trackBreadth, LayoutUnit childBreadth) |
| +static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, LayoutUnit trackSize, LayoutUnit childSize) |
| { |
| - LayoutUnit offset = trackBreadth - childBreadth; |
| + LayoutUnit offset = trackSize - childSize; |
| switch (overflow) { |
| case OverflowAlignmentSafe: |
| // If overflow is 'safe', we have to make sure we don't overflow the 'start' |
| @@ -2083,31 +2096,46 @@ GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) |
| switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositionStretch)) { |
| case ItemPositionSelfStart: |
| - // If orthogonal writing-modes, this computes to 'start'. |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - // self-start is based on the child's block axis direction. That's why we need to check against the grid container's block flow. |
| - return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisStart : GridAxisEnd; |
| + // Aligns the alignment subject to be flush with the edge of the alignment container |
|
svillar
2016/07/13 09:00:40
"Aligns the alignment subject to be flush" don't
jfernandez
2016/07/14 09:29:15
It's what the Alignment spec literally states at:
|
| + // corresponding to the alignment subject's 'start' side in the column axis. |
| + if (isOrthogonalChild(child)) { |
| + // If orthogonal writing-modes, self-start will be based on the child's inline-axis |
| + // direction (inline-start), because it's the one parallel to the column axis. |
| + if (isFlippedBlocksWritingMode(style()->getWritingMode())) |
| + return child.style()->isLeftToRightDirection() ? GridAxisEnd : GridAxisStart; |
| + return child.style()->isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; |
| + } |
| + // self-start is based on the child's block-flow direction. That's why we need to check against the grid container's block-flow direction. |
| + return hasSameWritingMode ? GridAxisStart : GridAxisEnd; |
| case ItemPositionSelfEnd: |
| - // If orthogonal writing-modes, this computes to 'end'. |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - // self-end is based on the child's block axis direction. That's why we need to check against the grid container's block flow. |
| - return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisEnd : GridAxisStart; |
| + // Aligns the alignment subject to be flush with the edge of the alignment container |
| + // corresponding to the alignment subject's 'end' side in the column axis. |
| + if (isOrthogonalChild(child)) { |
| + // If orthogonal writing-modes, self-end will be based on the child's inline-axis |
| + // direction, (inline-end) because it's the one parallel to the column axis. |
| + if (isFlippedBlocksWritingMode(style()->getWritingMode())) |
| + return child.style()->isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; |
| + return child.style()->isLeftToRightDirection() ? GridAxisEnd : GridAxisStart; |
| + } |
| + // self-end is based on the child's block-flow direction. That's why we need to check against the grid container's block-flow direction. |
| + return hasSameWritingMode ? GridAxisEnd : GridAxisStart; |
| case ItemPositionLeft: |
| - // The alignment axis (column axis) and the inline axis are parallell in |
| - // orthogonal writing mode. Otherwise this this is equivalent to 'start'. |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| + // Aligns the alignment subject to be flush with the alignment container's 'line-left' edge. |
| + // The alignment axis (column axis) is always orthogonal to the inline axis, hence this value behaves as 'start'. |
| return GridAxisStart; |
| case ItemPositionRight: |
| - // The alignment axis (column axis) and the inline axis are parallell in |
| - // orthogonal writing mode. Otherwise this this is equivalent to 'start'. |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - return isOrthogonalChild(child) ? GridAxisEnd : GridAxisStart; |
| + // Aligns the alignment subject to be flush with the alignment container's 'line-right' edge. |
| + // The alignment axis (column axis) is always orthogonal to the inline axis, hence this value behaves as 'start'. |
| + return GridAxisStart; |
| case ItemPositionCenter: |
| + // Centers the alignment subject within its alignment container. |
|
svillar
2016/07/13 09:00:40
The other comments are great but this is not reall
jfernandez
2016/07/14 09:29:15
Done.
|
| return GridAxisCenter; |
| case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalent to 'start'. |
| + // Aligns the alignment subject to be flush with the alignment container's 'start' edge (block-start) in the column axis. |
| case ItemPositionStart: |
| return GridAxisStart; |
| case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. |
| + // Aligns the alignment subject to be flush with the alignment container's 'end' edge (block-end) in the column axis. |
| case ItemPositionEnd: |
| return GridAxisEnd; |
| case ItemPositionStretch: |
| @@ -2128,28 +2156,49 @@ GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) |
| GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) const |
| { |
| bool hasSameDirection = child.styleRef().direction() == styleRef().direction(); |
| - bool isLTR = styleRef().isLeftToRightDirection(); |
| switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), ItemPositionStretch)) { |
| case ItemPositionSelfStart: |
| - // For orthogonal writing-modes, this computes to 'start' |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - // self-start is based on the child's direction. That's why we need to check against the grid container's direction. |
| - return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisStart : GridAxisEnd; |
| + // Aligns the alignment subject to be flush with the edge of the alignment container |
| + // corresponding to the alignment subject's 'start' side in the row axis. |
| + if (isOrthogonalChild(child)) { |
| + // If orthogonal writing-modes, self-start will be based on the child's block-axis |
| + // direction, because it's the one parallel to the row axis. |
| + if (isFlippedBlocksWritingMode(child.style()->getWritingMode())) |
| + return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridAxisStart; |
| + return styleRef().isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; |
| + } |
| + // self-start is based on the child's inline-flow direction. That's why we need to check against the grid container's direction. |
| + return hasSameDirection ? GridAxisStart : GridAxisEnd; |
|
svillar
2016/07/13 09:00:40
Isn't this exactly the same code as in columnAxisP
jfernandez
2016/07/14 09:29:15
No, It's not the same. Alignment along column-axis
|
| case ItemPositionSelfEnd: |
| - // For orthogonal writing-modes, this computes to 'start' |
| - // FIXME: grid track sizing and positioning do not support orthogonal modes yet. |
| - return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisEnd : GridAxisStart; |
| + // Aligns the alignment subject to be flush with the edge of the alignment container |
| + // corresponding to the alignment subject's 'end' side in the row axis. |
| + if (isOrthogonalChild(child)) { |
| + // If orthogonal writing-modes, self-end will be based on the child's block-axis |
| + // direction, because it's the one parallel to the row axis. |
| + if (isFlippedBlocksWritingMode(child.style()->getWritingMode())) |
| + return styleRef().isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; |
| + return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridAxisStart; |
| + } |
| + // self-end is based on the child's inline-flow direction. That's why we need to check against the grid container's direction. |
| + return hasSameDirection ? GridAxisEnd : GridAxisStart; |
|
svillar
2016/07/13 09:00:40
Ditto.
jfernandez
2016/07/14 09:29:15
Already replied above.
|
| case ItemPositionLeft: |
| - return isLTR ? GridAxisStart : GridAxisEnd; |
| + // Aligns the alignment subject to be flush with the alignment container's 'line-left' edge. |
| + // We want the physical 'left' side, so we have to take account, container's inline-flow direction. |
| + return styleRef().isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; |
| case ItemPositionRight: |
| - return isLTR ? GridAxisEnd : GridAxisStart; |
| + // Aligns the alignment subject to be flush with the alignment container's 'line-right' edge. |
| + // We want the physical 'right' side, so we have to take account, container's inline-flow direction. |
| + return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridAxisStart; |
| case ItemPositionCenter: |
| + // Centers the alignment subject within its alignment container. |
|
svillar
2016/07/13 09:00:40
Ditto comment.
jfernandez
2016/07/14 09:29:15
Done.
|
| return GridAxisCenter; |
| case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalent to 'start'. |
| + // Aligns the alignment subject to be flush with the alignment container's 'start' edge (inline-start) in the row axis. |
| case ItemPositionStart: |
| return GridAxisStart; |
| case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. |
| + // Aligns the alignment subject to be flush with the alignment container's 'end' edge (inline-end) in the row axis. |
| case ItemPositionEnd: |
| return GridAxisEnd; |
| case ItemPositionStretch: |
| @@ -2191,9 +2240,9 @@ LayoutUnit LayoutGrid::columnAxisOffsetForChild(const LayoutBox& child, GridSizi |
| endOfRow -= trackGap; |
| endOfRow -= m_offsetBetweenRows; |
| } |
| - LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHeight(); |
| + LayoutUnit columnAxisChildSize = isOrthogonalChild(child) ? child.logicalWidth() + child.marginLogicalWidth() : child.logicalHeight() + child.marginLogicalHeight(); |
| OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef(), ItemPositionStretch).overflow(); |
| - LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(overflow, endOfRow - startOfRow, childBreadth); |
| + LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(overflow, endOfRow - startOfRow, columnAxisChildSize); |
| return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2); |
| } |
| } |
| @@ -2226,8 +2275,8 @@ LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD |
| endOfColumn -= trackGap; |
| endOfColumn -= m_offsetBetweenColumns; |
| } |
| - LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidth(); |
| - LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childBreadth); |
| + LayoutUnit rowAxisChildSize = isOrthogonalChild(child) ? child.logicalHeight() + child.marginLogicalHeight() : child.logicalWidth() + child.marginLogicalWidth(); |
| + LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(child.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, rowAxisChildSize); |
| return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPosition : offsetFromStartPosition / 2); |
| } |
| } |
| @@ -2353,7 +2402,7 @@ LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz |
| // We stored m_columnPosition's data ignoring the direction, hence we might need now |
| // to translate positions from RTL to LTR, as it's more convenient for painting. |
| if (!style()->isLeftToRightDirection()) |
| - rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - child.logicalWidth(); |
| + rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - (isOrthogonalChild(child) ? child.logicalHeight() : child.logicalWidth()); |
| // "In the positioning phase [...] calculations are performed according to the writing mode |
| // of the containing block of the box establishing the orthogonal flow." However, the |