OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1663 | 1663 |
1664 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 1664 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; |
1665 for (const auto& trackIndex : autoSizedTracksIndex) { | 1665 for (const auto& trackIndex : autoSizedTracksIndex) { |
1666 GridTrack* track = tracks.data() + trackIndex; | 1666 GridTrack* track = tracks.data() + trackIndex; |
1667 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; | 1667 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; |
1668 track->setBaseSize(baseSize); | 1668 track->setBaseSize(baseSize); |
1669 } | 1669 } |
1670 availableSpace = LayoutUnit(); | 1670 availableSpace = LayoutUnit(); |
1671 } | 1671 } |
1672 | 1672 |
1673 bool LayoutGrid::childOverflowingContainingBlockHeight(const LayoutBox& child) c onst | |
1674 { | |
1675 LayoutUnit containingBlockContentHeight = child.hasOverrideContainingBlockHe ight() ? child.overrideContainingBlockContentHeight() : LayoutUnit(); | |
1676 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:
| |
1677 } | |
1678 | |
1679 bool LayoutGrid::childOverflowingContainingBlockWidth(const LayoutBox& child) co nst | |
1680 { | |
1681 LayoutUnit containingBlockContentWidth = child.hasOverrideContainingBlockWid th() ? child.overrideContainingBlockContentWidth() : LayoutUnit(); | |
1682 return child.size().width() > containingBlockContentWidth; | |
cbiesinger
2016/06/23 18:35:12
same question here
jfernandez
2016/06/24 12:59:15
Done.
| |
1683 } | |
1684 | |
1673 void LayoutGrid::layoutGridItems(GridSizingData& sizingData) | 1685 void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
1674 { | 1686 { |
1675 populateGridPositionsForDirection(sizingData, ForColumns); | 1687 populateGridPositionsForDirection(sizingData, ForColumns); |
1676 populateGridPositionsForDirection(sizingData, ForRows); | 1688 populateGridPositionsForDirection(sizingData, ForRows); |
1677 m_gridItemsOverflowingGridArea.resize(0); | 1689 m_gridItemsOverflowingGridArea.resize(0); |
1678 | 1690 |
1679 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { | 1691 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { |
1680 if (child->isOutOfFlowPositioned()) { | 1692 if (child->isOutOfFlowPositioned()) { |
1681 prepareChildForPositionedLayout(*child); | 1693 prepareChildForPositionedLayout(*child); |
1682 continue; | 1694 continue; |
1683 } | 1695 } |
1684 | 1696 |
1685 // Because the grid area cannot be styled, we don't need to adjust | 1697 // Because the grid area cannot be styled, we don't need to adjust |
1686 // the grid breadth to account for 'box-sizing'. | 1698 // the grid breadth to account for 'box-sizing'. |
1687 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); | 1699 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); |
1688 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); | 1700 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); |
1689 | 1701 |
1690 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); | 1702 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); |
1691 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); | 1703 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); |
1692 | 1704 |
1693 SubtreeLayoutScope layoutScope(*child); | 1705 SubtreeLayoutScope layoutScope(*child); |
1694 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && (child->hasRelativeLogicalHeight() || isOrthogonalChild(*child)))) | 1706 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
1695 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); | 1707 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); |
1696 | 1708 |
1697 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 1709 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
1698 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 1710 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
1699 | 1711 |
1700 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded | 1712 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded |
1701 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly | 1713 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly |
1702 // determine the available space before stretching, are not set yet. | 1714 // determine the available space before stretching, are not set yet. |
1703 applyStretchAlignmentToChildIfNeeded(*child); | 1715 applyStretchAlignmentToChildIfNeeded(*child); |
1704 | 1716 |
1705 child->layoutIfNeeded(); | 1717 child->layoutIfNeeded(); |
1706 | 1718 |
1707 // We need pending layouts to be done in order to compute auto-margins p roperly. | 1719 // We need pending layouts to be done in order to compute auto-margins p roperly. |
1708 updateAutoMarginsInColumnAxisIfNeeded(*child); | 1720 updateAutoMarginsInColumnAxisIfNeeded(*child); |
1709 updateAutoMarginsInRowAxisIfNeeded(*child); | 1721 updateAutoMarginsInRowAxisIfNeeded(*child); |
1710 | 1722 |
1711 #if ENABLE(ASSERT) | 1723 #if ENABLE(ASSERT) |
1712 const GridArea& area = cachedGridArea(*child); | 1724 const GridArea& area = cachedGridArea(*child); |
1713 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); | 1725 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); |
1714 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); | 1726 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); |
1715 #endif | 1727 #endif |
1716 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1728 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1717 | 1729 |
1718 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is | 1730 // Keep track of children overflowing their grid area as we might need t o paint them even if the grid-area is |
1719 // not visible | 1731 // not visible. |
1720 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1732 // Using physical dimensions for simplicity, so we can forget about orth ogonalty. |
1721 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt h) | 1733 if (childOverflowingContainingBlockHeight(*child) |
1734 || 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.
| |
1722 m_gridItemsOverflowingGridArea.append(child); | 1735 m_gridItemsOverflowingGridArea.append(child); |
1723 } | 1736 } |
1724 } | 1737 } |
1725 | 1738 |
1726 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) | 1739 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) |
1727 { | 1740 { |
1728 ASSERT(child.isOutOfFlowPositioned()); | 1741 ASSERT(child.isOutOfFlowPositioned()); |
1729 child.containingBlock()->insertPositionedObject(&child); | 1742 child.containingBlock()->insertPositionedObject(&child); |
1730 | 1743 |
1731 PaintLayer* childLayer = child.layer(); | 1744 PaintLayer* childLayer = child.layer(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1934 if (numberOfLines > 1) { | 1947 if (numberOfLines > 1) { |
1935 size_t nextToLastLine = numberOfLines - 2; | 1948 size_t nextToLastLine = numberOfLines - 2; |
1936 for (size_t i = 0; i < nextToLastLine; ++i) | 1949 for (size_t i = 0; i < nextToLastLine; ++i) |
1937 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + trackGap; | 1950 positions[i + 1] = positions[i] + offset.distributionOffset + tracks [i].baseSize() + trackGap; |
1938 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize(); | 1951 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine] .baseSize(); |
1939 } | 1952 } |
1940 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet weenRows; | 1953 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet weenRows; |
1941 offsetBetweenTracks = offset.distributionOffset; | 1954 offsetBetweenTracks = offset.distributionOffset; |
1942 } | 1955 } |
1943 | 1956 |
1944 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth) | 1957 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackSize, LayoutUnit childSize) |
1945 { | 1958 { |
1946 LayoutUnit offset = trackBreadth - childBreadth; | 1959 LayoutUnit offset = trackSize - childSize; |
1947 switch (overflow) { | 1960 switch (overflow) { |
1948 case OverflowAlignmentSafe: | 1961 case OverflowAlignmentSafe: |
1949 // If overflow is 'safe', we have to make sure we don't overflow the 'st art' | 1962 // If overflow is 'safe', we have to make sure we don't overflow the 'st art' |
1950 // edge (potentially cause some data loss as the overflow is unreachable ). | 1963 // edge (potentially cause some data loss as the overflow is unreachable ). |
1951 return offset.clampNegativeToZero(); | 1964 return offset.clampNegativeToZero(); |
1952 case OverflowAlignmentUnsafe: | 1965 case OverflowAlignmentUnsafe: |
1953 case OverflowAlignmentDefault: | 1966 case OverflowAlignmentDefault: |
1954 // If we overflow our alignment container and overflow is 'true' (defaul t), we | 1967 // If we overflow our alignment container and overflow is 'true' (defaul t), we |
1955 // ignore the overflow and just return the value regardless (which may c ause data | 1968 // ignore the overflow and just return the value regardless (which may c ause data |
1956 // loss as we overflow the 'start' edge). | 1969 // loss as we overflow the 'start' edge). |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2076 child.setMarginAfter(availableAlignmentSpace, style()); | 2089 child.setMarginAfter(availableAlignmentSpace, style()); |
2077 } | 2090 } |
2078 } | 2091 } |
2079 | 2092 |
2080 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const | 2093 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const |
2081 { | 2094 { |
2082 bool hasSameWritingMode = child.styleRef().getWritingMode() == styleRef().ge tWritingMode(); | 2095 bool hasSameWritingMode = child.styleRef().getWritingMode() == styleRef().ge tWritingMode(); |
2083 | 2096 |
2084 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { | 2097 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { |
2085 case ItemPositionSelfStart: | 2098 case ItemPositionSelfStart: |
2086 // If orthogonal writing-modes, this computes to 'start'. | 2099 // Aligns the alignment subject to be flush with the edge of the alignme nt 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:
| |
2087 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | 2100 // corresponding to the alignment subject's 'start' side in the column a xis. |
2088 // self-start is based on the child's block axis direction. That's why w e need to check against the grid container's block flow. | 2101 if (isOrthogonalChild(child)) { |
2089 return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisStart : GridAxisEnd; | 2102 // If orthogonal writing-modes, self-start will be based on the chil d's inline-axis |
2103 // direction (inline-start), because it's the one parallel to the co lumn axis. | |
2104 if (isFlippedBlocksWritingMode(style()->getWritingMode())) | |
2105 return child.style()->isLeftToRightDirection() ? GridAxisEnd : G ridAxisStart; | |
2106 return child.style()->isLeftToRightDirection() ? GridAxisStart : Gri dAxisEnd; | |
2107 } | |
2108 // self-start is based on the child's block-flow direction. That's why w e need to check against the grid container's block-flow direction. | |
2109 return hasSameWritingMode ? GridAxisStart : GridAxisEnd; | |
2090 case ItemPositionSelfEnd: | 2110 case ItemPositionSelfEnd: |
2091 // If orthogonal writing-modes, this computes to 'end'. | 2111 // Aligns the alignment subject to be flush with the edge of the alignme nt container |
2092 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | 2112 // corresponding to the alignment subject's 'end' side in the column axi s. |
2093 // 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. | 2113 if (isOrthogonalChild(child)) { |
2094 return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisEnd : GridAxisStart; | 2114 // If orthogonal writing-modes, self-end will be based on the child' s inline-axis |
2115 // direction, (inline-end) because it's the one parallel to the colu mn axis. | |
2116 if (isFlippedBlocksWritingMode(style()->getWritingMode())) | |
2117 return child.style()->isLeftToRightDirection() ? GridAxisStart : GridAxisEnd; | |
2118 return child.style()->isLeftToRightDirection() ? GridAxisEnd : GridA xisStart; | |
2119 } | |
2120 // 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. | |
2121 return hasSameWritingMode ? GridAxisEnd : GridAxisStart; | |
2095 case ItemPositionLeft: | 2122 case ItemPositionLeft: |
2096 // The alignment axis (column axis) and the inline axis are parallell in | 2123 // Aligns the alignment subject to be flush with the alignment container 's 'line-left' edge. |
2097 // orthogonal writing mode. Otherwise this this is equivalent to 'start' . | 2124 // The alignment axis (column axis) is always orthogonal to the inline a xis, hence this value behaves as 'start'. |
2098 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | |
2099 return GridAxisStart; | 2125 return GridAxisStart; |
2100 case ItemPositionRight: | 2126 case ItemPositionRight: |
2101 // The alignment axis (column axis) and the inline axis are parallell in | 2127 // Aligns the alignment subject to be flush with the alignment container 's 'line-right' edge. |
2102 // orthogonal writing mode. Otherwise this this is equivalent to 'start' . | 2128 // The alignment axis (column axis) is always orthogonal to the inline a xis, hence this value behaves as 'start'. |
2103 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | 2129 return GridAxisStart; |
2104 return isOrthogonalChild(child) ? GridAxisEnd : GridAxisStart; | |
2105 case ItemPositionCenter: | 2130 case ItemPositionCenter: |
2131 // 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.
| |
2106 return GridAxisCenter; | 2132 return GridAxisCenter; |
2107 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'. | 2133 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'. |
2134 // Aligns the alignment subject to be flush with the alignment container 's 'start' edge (block-start) in the column axis. | |
2108 case ItemPositionStart: | 2135 case ItemPositionStart: |
2109 return GridAxisStart; | 2136 return GridAxisStart; |
2110 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. | 2137 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. |
2138 // Aligns the alignment subject to be flush with the alignment container 's 'end' edge (block-end) in the column axis. | |
2111 case ItemPositionEnd: | 2139 case ItemPositionEnd: |
2112 return GridAxisEnd; | 2140 return GridAxisEnd; |
2113 case ItemPositionStretch: | 2141 case ItemPositionStretch: |
2114 return GridAxisStart; | 2142 return GridAxisStart; |
2115 case ItemPositionBaseline: | 2143 case ItemPositionBaseline: |
2116 case ItemPositionLastBaseline: | 2144 case ItemPositionLastBaseline: |
2117 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. | 2145 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. |
2118 // crbug.com/234191 | 2146 // crbug.com/234191 |
2119 return GridAxisStart; | 2147 return GridAxisStart; |
2120 case ItemPositionAuto: | 2148 case ItemPositionAuto: |
2121 break; | 2149 break; |
2122 } | 2150 } |
2123 | 2151 |
2124 ASSERT_NOT_REACHED(); | 2152 ASSERT_NOT_REACHED(); |
2125 return GridAxisStart; | 2153 return GridAxisStart; |
2126 } | 2154 } |
2127 | 2155 |
2128 GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con st | 2156 GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con st |
2129 { | 2157 { |
2130 bool hasSameDirection = child.styleRef().direction() == styleRef().direction (); | 2158 bool hasSameDirection = child.styleRef().direction() == styleRef().direction (); |
2131 bool isLTR = styleRef().isLeftToRightDirection(); | |
2132 | 2159 |
2133 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It emPositionStretch)) { | 2160 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It emPositionStretch)) { |
2134 case ItemPositionSelfStart: | 2161 case ItemPositionSelfStart: |
2135 // For orthogonal writing-modes, this computes to 'start' | 2162 // Aligns the alignment subject to be flush with the edge of the alignme nt container |
2136 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | 2163 // corresponding to the alignment subject's 'start' side in the row axis . |
2137 // self-start is based on the child's direction. That's why we need to c heck against the grid container's direction. | 2164 if (isOrthogonalChild(child)) { |
2138 return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisStart : GridAxisEnd; | 2165 // If orthogonal writing-modes, self-start will be based on the chil d's block-axis |
2166 // direction, because it's the one parallel to the row axis. | |
2167 if (isFlippedBlocksWritingMode(child.style()->getWritingMode())) | |
2168 return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridA xisStart; | |
2169 return styleRef().isLeftToRightDirection() ? GridAxisStart : GridAxi sEnd; | |
2170 } | |
2171 // self-start is based on the child's inline-flow direction. That's why we need to check against the grid container's direction. | |
2172 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
| |
2139 case ItemPositionSelfEnd: | 2173 case ItemPositionSelfEnd: |
2140 // For orthogonal writing-modes, this computes to 'start' | 2174 // Aligns the alignment subject to be flush with the edge of the alignme nt container |
2141 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet. | 2175 // corresponding to the alignment subject's 'end' side in the row axis. |
2142 return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisEnd : Gr idAxisStart; | 2176 if (isOrthogonalChild(child)) { |
2177 // If orthogonal writing-modes, self-end will be based on the child' s block-axis | |
2178 // direction, because it's the one parallel to the row axis. | |
2179 if (isFlippedBlocksWritingMode(child.style()->getWritingMode())) | |
2180 return styleRef().isLeftToRightDirection() ? GridAxisStart : Gri dAxisEnd; | |
2181 return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridAxisS tart; | |
2182 } | |
2183 // self-end is based on the child's inline-flow direction. That's why we need to check against the grid container's direction. | |
2184 return hasSameDirection ? GridAxisEnd : GridAxisStart; | |
svillar
2016/07/13 09:00:40
Ditto.
jfernandez
2016/07/14 09:29:15
Already replied above.
| |
2143 case ItemPositionLeft: | 2185 case ItemPositionLeft: |
2144 return isLTR ? GridAxisStart : GridAxisEnd; | 2186 // Aligns the alignment subject to be flush with the alignment container 's 'line-left' edge. |
2187 // We want the physical 'left' side, so we have to take account, contain er's inline-flow direction. | |
2188 return styleRef().isLeftToRightDirection() ? GridAxisStart : GridAxisEnd ; | |
2145 case ItemPositionRight: | 2189 case ItemPositionRight: |
2146 return isLTR ? GridAxisEnd : GridAxisStart; | 2190 // Aligns the alignment subject to be flush with the alignment container 's 'line-right' edge. |
2191 // We want the physical 'right' side, so we have to take account, contai ner's inline-flow direction. | |
2192 return styleRef().isLeftToRightDirection() ? GridAxisEnd : GridAxisStart ; | |
2147 case ItemPositionCenter: | 2193 case ItemPositionCenter: |
2194 // 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.
| |
2148 return GridAxisCenter; | 2195 return GridAxisCenter; |
2149 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'. | 2196 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen t to 'start'. |
2197 // Aligns the alignment subject to be flush with the alignment container 's 'start' edge (inline-start) in the row axis. | |
2150 case ItemPositionStart: | 2198 case ItemPositionStart: |
2151 return GridAxisStart; | 2199 return GridAxisStart; |
2152 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. | 2200 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent to 'end'. |
2201 // Aligns the alignment subject to be flush with the alignment container 's 'end' edge (inline-end) in the row axis. | |
2153 case ItemPositionEnd: | 2202 case ItemPositionEnd: |
2154 return GridAxisEnd; | 2203 return GridAxisEnd; |
2155 case ItemPositionStretch: | 2204 case ItemPositionStretch: |
2156 return GridAxisStart; | 2205 return GridAxisStart; |
2157 case ItemPositionBaseline: | 2206 case ItemPositionBaseline: |
2158 case ItemPositionLastBaseline: | 2207 case ItemPositionLastBaseline: |
2159 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. | 2208 // FIXME: These two require implementing Baseline Alignment. For now, we always 'start' align the child. |
2160 // crbug.com/234191 | 2209 // crbug.com/234191 |
2161 return GridAxisStart; | 2210 return GridAxisStart; |
2162 case ItemPositionAuto: | 2211 case ItemPositionAuto: |
(...skipping 21 matching lines...) Expand all Loading... | |
2184 size_t childEndLine = rowsSpan.endLine(); | 2233 size_t childEndLine = rowsSpan.endLine(); |
2185 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 2234 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
2186 // m_rowPositions include distribution offset (because of content alignm ent) and gutters | 2235 // m_rowPositions include distribution offset (because of content alignm ent) and gutters |
2187 // so we need to subtract them to get the actual end position for a give n row | 2236 // so we need to subtract them to get the actual end position for a give n row |
2188 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). | 2237 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). |
2189 LayoutUnit trackGap = guttersSize(ForRows, 2); | 2238 LayoutUnit trackGap = guttersSize(ForRows, 2); |
2190 if (childEndLine < m_rowPositions.size() - 1) { | 2239 if (childEndLine < m_rowPositions.size() - 1) { |
2191 endOfRow -= trackGap; | 2240 endOfRow -= trackGap; |
2192 endOfRow -= m_offsetBetweenRows; | 2241 endOfRow -= m_offsetBetweenRows; |
2193 } | 2242 } |
2194 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei ght(); | 2243 LayoutUnit columnAxisChildSize = isOrthogonalChild(child) ? child.logica lWidth() + child.marginLogicalWidth() : child.logicalHeight() + child.marginLogi calHeight(); |
2195 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); | 2244 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef (), ItemPositionStretch).overflow(); |
2196 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, childBreadth); | 2245 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over flow, endOfRow - startOfRow, columnAxisChildSize); |
2197 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); | 2246 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); |
2198 } | 2247 } |
2199 } | 2248 } |
2200 | 2249 |
2201 ASSERT_NOT_REACHED(); | 2250 ASSERT_NOT_REACHED(); |
2202 return LayoutUnit(); | 2251 return LayoutUnit(); |
2203 } | 2252 } |
2204 | 2253 |
2205 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD ata& sizingData) const | 2254 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD ata& sizingData) const |
2206 { | 2255 { |
(...skipping 12 matching lines...) Expand all Loading... | |
2219 size_t childEndLine = columnsSpan.endLine(); | 2268 size_t childEndLine = columnsSpan.endLine(); |
2220 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 2269 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
2221 // m_columnPositions include distribution offset (because of content ali gnment) and gutters | 2270 // m_columnPositions include distribution offset (because of content ali gnment) and gutters |
2222 // so we need to subtract them to get the actual end position for a give n column | 2271 // so we need to subtract them to get the actual end position for a give n column |
2223 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). | 2272 // (this does not have to be done for the last track as there are no mor e m_columnPositions after it). |
2224 LayoutUnit trackGap = guttersSize(ForColumns, 2); | 2273 LayoutUnit trackGap = guttersSize(ForColumns, 2); |
2225 if (childEndLine < m_columnPositions.size() - 1) { | 2274 if (childEndLine < m_columnPositions.size() - 1) { |
2226 endOfColumn -= trackGap; | 2275 endOfColumn -= trackGap; |
2227 endOfColumn -= m_offsetBetweenColumns; | 2276 endOfColumn -= m_offsetBetweenColumns; |
2228 } | 2277 } |
2229 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt h(); | 2278 LayoutUnit rowAxisChildSize = isOrthogonalChild(child) ? child.logicalHe ight() + child.marginLogicalHeight() : child.logicalWidth() + child.marginLogica lWidth(); |
2230 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB readth); | 2279 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, rowAxi sChildSize); |
2231 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); | 2280 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos ition : offsetFromStartPosition / 2); |
2232 } | 2281 } |
2233 } | 2282 } |
2234 | 2283 |
2235 ASSERT_NOT_REACHED(); | 2284 ASSERT_NOT_REACHED(); |
2236 return LayoutUnit(); | 2285 return LayoutUnit(); |
2237 } | 2286 } |
2238 | 2287 |
2239 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution) | 2288 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp e distribution) |
2240 { | 2289 { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2346 return rightGridEdgePosition + alignmentOffset - coordinate; | 2395 return rightGridEdgePosition + alignmentOffset - coordinate; |
2347 } | 2396 } |
2348 | 2397 |
2349 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const | 2398 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const |
2350 { | 2399 { |
2351 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); | 2400 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); |
2352 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); | 2401 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); |
2353 // We stored m_columnPosition's data ignoring the direction, hence we might need now | 2402 // We stored m_columnPosition's data ignoring the direction, hence we might need now |
2354 // to translate positions from RTL to LTR, as it's more convenient for paint ing. | 2403 // to translate positions from RTL to LTR, as it's more convenient for paint ing. |
2355 if (!style()->isLeftToRightDirection()) | 2404 if (!style()->isLeftToRightDirection()) |
2356 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - child.logicalWid th(); | 2405 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - (isOrthogonalChi ld(child) ? child.logicalHeight() : child.logicalWidth()); |
2357 | 2406 |
2358 // "In the positioning phase [...] calculations are performed according to t he writing mode | 2407 // "In the positioning phase [...] calculations are performed according to t he writing mode |
2359 // of the containing block of the box establishing the orthogonal flow." How ever, the | 2408 // of the containing block of the box establishing the orthogonal flow." How ever, the |
2360 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's | 2409 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's |
2361 // logical position, which will only take into account the child's writing-m ode. | 2410 // logical position, which will only take into account the child's writing-m ode. |
2362 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); | 2411 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); |
2363 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | 2412 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; |
2364 } | 2413 } |
2365 | 2414 |
2366 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2415 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2367 { | 2416 { |
2368 if (!m_gridItemArea.isEmpty()) | 2417 if (!m_gridItemArea.isEmpty()) |
2369 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2418 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2370 } | 2419 } |
2371 | 2420 |
2372 } // namespace blink | 2421 } // namespace blink |
OLD | NEW |