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 c310533d05364a05b7b3dded3c7ce4408e07dc38..d86724e1b70b040e8f9018f08f54fe50528bf7b1 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| @@ -1822,6 +1822,20 @@ void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection |
| availableSpace = LayoutUnit(); |
| } |
| +bool LayoutGrid::isChildOverflowingContainingBlockHeight(const LayoutBox& child) const |
| +{ |
| + // TODO (lajava) We must consider margins to determine whether it overflows or not (see https://crbug/628155) |
| + LayoutUnit containingBlockContentHeight = child.hasOverrideContainingBlockHeight() ? child.overrideContainingBlockContentHeight() : LayoutUnit(); |
| + return child.size().height() > containingBlockContentHeight; |
| +} |
| + |
| +bool LayoutGrid::isChildOverflowingContainingBlockWidth(const LayoutBox& child) const |
| +{ |
| + // TODO (lajava) We must consider margins to determine whether it overflows or not (see https://crbug/628155) |
| + LayoutUnit containingBlockContentWidth = child.hasOverrideContainingBlockWidth() ? child.overrideContainingBlockContentWidth() : LayoutUnit(); |
| + return child.size().width() > containingBlockContentWidth; |
| +} |
| + |
| void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
| { |
| populateGridPositionsForDirection(sizingData, ForColumns); |
| @@ -1843,7 +1857,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())) |
|
svillar
2016/07/20 09:23:36
Why don't we need to force a layout for orthogonal
jfernandez
2016/07/20 13:46:14
Sincerely, that condition has been added in r40124
|
| layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChanged); |
| child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth); |
| @@ -1868,9 +1882,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 (isChildOverflowingContainingBlockHeight(*child) |
| + || isChildOverflowingContainingBlockWidth(*child)) |
|
svillar
2016/07/20 09:23:36
One line.
jfernandez
2016/07/20 13:46:14
Done.
|
| m_gridItemsOverflowingGridArea.append(child); |
| } |
| } |
| @@ -2117,9 +2132,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' |
| @@ -2259,31 +2274,45 @@ GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) |
|
svillar
2016/07/20 09:23:36
I think it'd be a good idea to store in a bool the
jfernandez
2016/07/20 13:46:14
Acknowledged.
|
| 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 |
| + // 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; |
| + } |
|
svillar
2016/07/20 09:23:36
I definitely think we should move this code block
jfernandez
2016/07/20 13:46:14
This logic, and the similar one implemented in row
|
| + // 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: |
| 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: |
| @@ -2304,28 +2333,48 @@ 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; |
| 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; |
| 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: |
| 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: |
| @@ -2367,9 +2416,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); |
| } |
| } |
| @@ -2402,8 +2451,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); |
| } |
| } |
| @@ -2529,7 +2578,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 |