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 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 | 1815 |
1816 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 1816 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; |
1817 for (const auto& trackIndex : autoSizedTracksIndex) { | 1817 for (const auto& trackIndex : autoSizedTracksIndex) { |
1818 GridTrack* track = tracks.data() + trackIndex; | 1818 GridTrack* track = tracks.data() + trackIndex; |
1819 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; | 1819 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; |
1820 track->setBaseSize(baseSize); | 1820 track->setBaseSize(baseSize); |
1821 } | 1821 } |
1822 availableSpace = LayoutUnit(); | 1822 availableSpace = LayoutUnit(); |
1823 } | 1823 } |
1824 | 1824 |
| 1825 bool LayoutGrid::isChildOverflowingContainingBlockHeight(const LayoutBox& child)
const |
| 1826 { |
| 1827 // TODO (lajava) We must consider margins to determine whether it overflows
or not (see https://crbug/628155) |
| 1828 LayoutUnit containingBlockContentHeight = child.hasOverrideContainingBlockHe
ight() ? child.overrideContainingBlockContentHeight() : LayoutUnit(); |
| 1829 return child.size().height() > containingBlockContentHeight; |
| 1830 } |
| 1831 |
| 1832 bool LayoutGrid::isChildOverflowingContainingBlockWidth(const LayoutBox& child)
const |
| 1833 { |
| 1834 // TODO (lajava) We must consider margins to determine whether it overflows
or not (see https://crbug/628155) |
| 1835 LayoutUnit containingBlockContentWidth = child.hasOverrideContainingBlockWid
th() ? child.overrideContainingBlockContentWidth() : LayoutUnit(); |
| 1836 return child.size().width() > containingBlockContentWidth; |
| 1837 } |
| 1838 |
1825 void LayoutGrid::layoutGridItems(GridSizingData& sizingData) | 1839 void LayoutGrid::layoutGridItems(GridSizingData& sizingData) |
1826 { | 1840 { |
1827 populateGridPositionsForDirection(sizingData, ForColumns); | 1841 populateGridPositionsForDirection(sizingData, ForColumns); |
1828 populateGridPositionsForDirection(sizingData, ForRows); | 1842 populateGridPositionsForDirection(sizingData, ForRows); |
1829 m_gridItemsOverflowingGridArea.resize(0); | 1843 m_gridItemsOverflowingGridArea.resize(0); |
1830 | 1844 |
1831 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 1845 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
1832 if (child->isOutOfFlowPositioned()) { | 1846 if (child->isOutOfFlowPositioned()) { |
1833 prepareChildForPositionedLayout(*child); | 1847 prepareChildForPositionedLayout(*child); |
1834 continue; | 1848 continue; |
1835 } | 1849 } |
1836 | 1850 |
1837 // Because the grid area cannot be styled, we don't need to adjust | 1851 // Because the grid area cannot be styled, we don't need to adjust |
1838 // the grid breadth to account for 'box-sizing'. | 1852 // the grid breadth to account for 'box-sizing'. |
1839 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve
rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica
lWidth() : LayoutUnit(); | 1853 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve
rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica
lWidth() : LayoutUnit(); |
1840 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv
errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi
calHeight() : LayoutUnit(); | 1854 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv
errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi
calHeight() : LayoutUnit(); |
1841 | 1855 |
1842 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF
orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); | 1856 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF
orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); |
1843 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth
ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); | 1857 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth
ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); |
1844 | 1858 |
1845 SubtreeLayoutScope layoutScope(*child); | 1859 SubtreeLayoutScope layoutScope(*child); |
1846 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && (child->hasRelativeLogicalHeight()
|| isOrthogonalChild(*child)))) | 1860 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB
lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov
errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) |
1847 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); | 1861 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan
ged); |
1848 | 1862 |
1849 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); | 1863 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB
lockContentLogicalWidth); |
1850 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); | 1864 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining
BlockContentLogicalHeight); |
1851 | 1865 |
1852 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded | 1866 // Stretching logic might force a child layout, so we need to run it bef
ore the layoutIfNeeded |
1853 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly | 1867 // call to avoid unnecessary relayouts. This might imply that child marg
ins, needed to correctly |
1854 // determine the available space before stretching, are not set yet. | 1868 // determine the available space before stretching, are not set yet. |
1855 applyStretchAlignmentToChildIfNeeded(*child); | 1869 applyStretchAlignmentToChildIfNeeded(*child); |
1856 | 1870 |
1857 child->layoutIfNeeded(); | 1871 child->layoutIfNeeded(); |
1858 | 1872 |
1859 // We need pending layouts to be done in order to compute auto-margins p
roperly. | 1873 // We need pending layouts to be done in order to compute auto-margins p
roperly. |
1860 updateAutoMarginsInColumnAxisIfNeeded(*child); | 1874 updateAutoMarginsInColumnAxisIfNeeded(*child); |
1861 updateAutoMarginsInRowAxisIfNeeded(*child); | 1875 updateAutoMarginsInRowAxisIfNeeded(*child); |
1862 | 1876 |
1863 #if ENABLE(ASSERT) | 1877 #if ENABLE(ASSERT) |
1864 const GridArea& area = cachedGridArea(*child); | 1878 const GridArea& area = cachedGridArea(*child); |
1865 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); | 1879 ASSERT(area.columns.startLine() < sizingData.columnTracks.size()); |
1866 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); | 1880 ASSERT(area.rows.startLine() < sizingData.rowTracks.size()); |
1867 #endif | 1881 #endif |
1868 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); | 1882 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); |
1869 | 1883 |
1870 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is | 1884 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is |
1871 // not visible | 1885 // not visible. |
1872 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 1886 // Using physical dimensions for simplicity, so we can forget about orth
ogonalty. |
1873 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) | 1887 if (isChildOverflowingContainingBlockHeight(*child) || isChildOverflowin
gContainingBlockWidth(*child)) |
1874 m_gridItemsOverflowingGridArea.append(child); | 1888 m_gridItemsOverflowingGridArea.append(child); |
1875 } | 1889 } |
1876 } | 1890 } |
1877 | 1891 |
1878 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) | 1892 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) |
1879 { | 1893 { |
1880 ASSERT(child.isOutOfFlowPositioned()); | 1894 ASSERT(child.isOutOfFlowPositioned()); |
1881 child.containingBlock()->insertPositionedObject(&child); | 1895 child.containingBlock()->insertPositionedObject(&child); |
1882 | 1896 |
1883 PaintLayer* childLayer = child.layer(); | 1897 PaintLayer* childLayer = child.layer(); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 } | 2124 } |
2111 positions[i] += gapAccumulator; | 2125 positions[i] += gapAccumulator; |
2112 } | 2126 } |
2113 positions[lastLine] += gapAccumulator; | 2127 positions[lastLine] += gapAccumulator; |
2114 } | 2128 } |
2115 } | 2129 } |
2116 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet
weenRows; | 2130 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet
weenRows; |
2117 offsetBetweenTracks = offset.distributionOffset; | 2131 offsetBetweenTracks = offset.distributionOffset; |
2118 } | 2132 } |
2119 | 2133 |
2120 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackBreadth, LayoutUnit childBreadth) | 2134 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackSize, LayoutUnit childSize) |
2121 { | 2135 { |
2122 LayoutUnit offset = trackBreadth - childBreadth; | 2136 LayoutUnit offset = trackSize - childSize; |
2123 switch (overflow) { | 2137 switch (overflow) { |
2124 case OverflowAlignmentSafe: | 2138 case OverflowAlignmentSafe: |
2125 // If overflow is 'safe', we have to make sure we don't overflow the 'st
art' | 2139 // If overflow is 'safe', we have to make sure we don't overflow the 'st
art' |
2126 // edge (potentially cause some data loss as the overflow is unreachable
). | 2140 // edge (potentially cause some data loss as the overflow is unreachable
). |
2127 return offset.clampNegativeToZero(); | 2141 return offset.clampNegativeToZero(); |
2128 case OverflowAlignmentUnsafe: | 2142 case OverflowAlignmentUnsafe: |
2129 case OverflowAlignmentDefault: | 2143 case OverflowAlignmentDefault: |
2130 // If we overflow our alignment container and overflow is 'true' (defaul
t), we | 2144 // If we overflow our alignment container and overflow is 'true' (defaul
t), we |
2131 // ignore the overflow and just return the value regardless (which may c
ause data | 2145 // ignore the overflow and just return the value regardless (which may c
ause data |
2132 // loss as we overflow the 'start' edge). | 2146 // loss as we overflow the 'start' edge). |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 } else if (marginBefore.isAuto()) { | 2263 } else if (marginBefore.isAuto()) { |
2250 child.setMarginBefore(availableAlignmentSpace, style()); | 2264 child.setMarginBefore(availableAlignmentSpace, style()); |
2251 } else if (marginAfter.isAuto()) { | 2265 } else if (marginAfter.isAuto()) { |
2252 child.setMarginAfter(availableAlignmentSpace, style()); | 2266 child.setMarginAfter(availableAlignmentSpace, style()); |
2253 } | 2267 } |
2254 } | 2268 } |
2255 | 2269 |
2256 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
const | 2270 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child)
const |
2257 { | 2271 { |
2258 bool hasSameWritingMode = child.styleRef().getWritingMode() == styleRef().ge
tWritingMode(); | 2272 bool hasSameWritingMode = child.styleRef().getWritingMode() == styleRef().ge
tWritingMode(); |
| 2273 bool childIsLTR = child.styleRef().isLeftToRightDirection(); |
2259 | 2274 |
2260 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo
sitionStretch)) { | 2275 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo
sitionStretch)) { |
2261 case ItemPositionSelfStart: | 2276 case ItemPositionSelfStart: |
2262 // If orthogonal writing-modes, this computes to 'start'. | 2277 // TODO (lajava): Should we implement this logic in a generic utility fu
nction ? |
2263 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 2278 // Aligns the alignment subject to be flush with the edge of the alignme
nt container |
2264 // 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. | 2279 // corresponding to the alignment subject's 'start' side in the column a
xis. |
2265 return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisStart
: GridAxisEnd; | 2280 if (isOrthogonalChild(child)) { |
| 2281 // If orthogonal writing-modes, self-start will be based on the chil
d's inline-axis |
| 2282 // direction (inline-start), because it's the one parallel to the co
lumn axis. |
| 2283 if (styleRef().isFlippedBlocksWritingMode()) |
| 2284 return childIsLTR ? GridAxisEnd : GridAxisStart; |
| 2285 return childIsLTR ? GridAxisStart : GridAxisEnd; |
| 2286 } |
| 2287 // 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. |
| 2288 return hasSameWritingMode ? GridAxisStart : GridAxisEnd; |
2266 case ItemPositionSelfEnd: | 2289 case ItemPositionSelfEnd: |
2267 // If orthogonal writing-modes, this computes to 'end'. | 2290 // TODO (lajava): Should we implement this logic in a generic utility fu
nction ? |
2268 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 2291 // Aligns the alignment subject to be flush with the edge of the alignme
nt container |
2269 // 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. | 2292 // corresponding to the alignment subject's 'end' side in the column axi
s. |
2270 return (isOrthogonalChild(child) || hasSameWritingMode) ? GridAxisEnd :
GridAxisStart; | 2293 if (isOrthogonalChild(child)) { |
| 2294 // If orthogonal writing-modes, self-end will be based on the child'
s inline-axis |
| 2295 // direction, (inline-end) because it's the one parallel to the colu
mn axis. |
| 2296 if (styleRef().isFlippedBlocksWritingMode()) |
| 2297 return childIsLTR ? GridAxisStart : GridAxisEnd; |
| 2298 return childIsLTR ? GridAxisEnd : GridAxisStart; |
| 2299 } |
| 2300 // 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. |
| 2301 return hasSameWritingMode ? GridAxisEnd : GridAxisStart; |
2271 case ItemPositionLeft: | 2302 case ItemPositionLeft: |
2272 // The alignment axis (column axis) and the inline axis are parallell in | 2303 // Aligns the alignment subject to be flush with the alignment container
's 'line-left' edge. |
2273 // orthogonal writing mode. Otherwise this this is equivalent to 'start'
. | 2304 // The alignment axis (column axis) is always orthogonal to the inline a
xis, hence this value behaves as 'start'. |
2274 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | |
2275 return GridAxisStart; | 2305 return GridAxisStart; |
2276 case ItemPositionRight: | 2306 case ItemPositionRight: |
2277 // The alignment axis (column axis) and the inline axis are parallell in | 2307 // Aligns the alignment subject to be flush with the alignment container
's 'line-right' edge. |
2278 // orthogonal writing mode. Otherwise this this is equivalent to 'start'
. | 2308 // The alignment axis (column axis) is always orthogonal to the inline a
xis, hence this value behaves as 'start'. |
2279 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 2309 return GridAxisStart; |
2280 return isOrthogonalChild(child) ? GridAxisEnd : GridAxisStart; | |
2281 case ItemPositionCenter: | 2310 case ItemPositionCenter: |
2282 return GridAxisCenter; | 2311 return GridAxisCenter; |
2283 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen
t to 'start'. | 2312 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen
t to 'start'. |
| 2313 // Aligns the alignment subject to be flush with the alignment container
's 'start' edge (block-start) in the column axis. |
2284 case ItemPositionStart: | 2314 case ItemPositionStart: |
2285 return GridAxisStart; | 2315 return GridAxisStart; |
2286 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent
to 'end'. | 2316 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent
to 'end'. |
| 2317 // Aligns the alignment subject to be flush with the alignment container
's 'end' edge (block-end) in the column axis. |
2287 case ItemPositionEnd: | 2318 case ItemPositionEnd: |
2288 return GridAxisEnd; | 2319 return GridAxisEnd; |
2289 case ItemPositionStretch: | 2320 case ItemPositionStretch: |
2290 return GridAxisStart; | 2321 return GridAxisStart; |
2291 case ItemPositionBaseline: | 2322 case ItemPositionBaseline: |
2292 case ItemPositionLastBaseline: | 2323 case ItemPositionLastBaseline: |
2293 // FIXME: These two require implementing Baseline Alignment. For now, we
always 'start' align the child. | 2324 // FIXME: These two require implementing Baseline Alignment. For now, we
always 'start' align the child. |
2294 // crbug.com/234191 | 2325 // crbug.com/234191 |
2295 return GridAxisStart; | 2326 return GridAxisStart; |
2296 case ItemPositionAuto: | 2327 case ItemPositionAuto: |
2297 break; | 2328 break; |
2298 } | 2329 } |
2299 | 2330 |
2300 ASSERT_NOT_REACHED(); | 2331 ASSERT_NOT_REACHED(); |
2301 return GridAxisStart; | 2332 return GridAxisStart; |
2302 } | 2333 } |
2303 | 2334 |
2304 GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con
st | 2335 GridAxisPosition LayoutGrid::rowAxisPositionForChild(const LayoutBox& child) con
st |
2305 { | 2336 { |
2306 bool hasSameDirection = child.styleRef().direction() == styleRef().direction
(); | 2337 bool hasSameDirection = child.styleRef().direction() == styleRef().direction
(); |
2307 bool isLTR = styleRef().isLeftToRightDirection(); | 2338 bool gridIsLTR = styleRef().isLeftToRightDirection(); |
2308 | 2339 |
2309 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It
emPositionStretch)) { | 2340 switch (ComputedStyle::resolveJustification(styleRef(), child.styleRef(), It
emPositionStretch)) { |
2310 case ItemPositionSelfStart: | 2341 case ItemPositionSelfStart: |
2311 // For orthogonal writing-modes, this computes to 'start' | 2342 // TODO (lajava): Should we implement this logic in a generic utility fu
nction ? |
2312 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 2343 // Aligns the alignment subject to be flush with the edge of the alignme
nt container |
2313 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. | 2344 // corresponding to the alignment subject's 'start' side in the row axis
. |
2314 return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisStart :
GridAxisEnd; | 2345 if (isOrthogonalChild(child)) { |
| 2346 // If orthogonal writing-modes, self-start will be based on the chil
d's block-axis |
| 2347 // direction, because it's the one parallel to the row axis. |
| 2348 if (child.styleRef().isFlippedBlocksWritingMode()) |
| 2349 return gridIsLTR ? GridAxisEnd : GridAxisStart; |
| 2350 return gridIsLTR ? GridAxisStart : GridAxisEnd; |
| 2351 } |
| 2352 // self-start is based on the child's inline-flow direction. That's why
we need to check against the grid container's direction. |
| 2353 return hasSameDirection ? GridAxisStart : GridAxisEnd; |
2315 case ItemPositionSelfEnd: | 2354 case ItemPositionSelfEnd: |
2316 // For orthogonal writing-modes, this computes to 'start' | 2355 // TODO (lajava): Should we implement this logic in a generic utility fu
nction ? |
2317 // FIXME: grid track sizing and positioning do not support orthogonal mo
des yet. | 2356 // Aligns the alignment subject to be flush with the edge of the alignme
nt container |
2318 return (isOrthogonalChild(child) || hasSameDirection) ? GridAxisEnd : Gr
idAxisStart; | 2357 // corresponding to the alignment subject's 'end' side in the row axis. |
| 2358 if (isOrthogonalChild(child)) { |
| 2359 // If orthogonal writing-modes, self-end will be based on the child'
s block-axis |
| 2360 // direction, because it's the one parallel to the row axis. |
| 2361 if (child.styleRef().isFlippedBlocksWritingMode()) |
| 2362 return gridIsLTR ? GridAxisStart : GridAxisEnd; |
| 2363 return gridIsLTR ? GridAxisEnd : GridAxisStart; |
| 2364 } |
| 2365 // self-end is based on the child's inline-flow direction. That's why we
need to check against the grid container's direction. |
| 2366 return hasSameDirection ? GridAxisEnd : GridAxisStart; |
2319 case ItemPositionLeft: | 2367 case ItemPositionLeft: |
2320 return isLTR ? GridAxisStart : GridAxisEnd; | 2368 // Aligns the alignment subject to be flush with the alignment container
's 'line-left' edge. |
| 2369 // We want the physical 'left' side, so we have to take account, contain
er's inline-flow direction. |
| 2370 return gridIsLTR ? GridAxisStart : GridAxisEnd; |
2321 case ItemPositionRight: | 2371 case ItemPositionRight: |
2322 return isLTR ? GridAxisEnd : GridAxisStart; | 2372 // Aligns the alignment subject to be flush with the alignment container
's 'line-right' edge. |
| 2373 // We want the physical 'right' side, so we have to take account, contai
ner's inline-flow direction. |
| 2374 return gridIsLTR ? GridAxisEnd : GridAxisStart; |
2323 case ItemPositionCenter: | 2375 case ItemPositionCenter: |
2324 return GridAxisCenter; | 2376 return GridAxisCenter; |
2325 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen
t to 'start'. | 2377 case ItemPositionFlexStart: // Only used in flex layout, otherwise equivalen
t to 'start'. |
| 2378 // Aligns the alignment subject to be flush with the alignment container
's 'start' edge (inline-start) in the row axis. |
2326 case ItemPositionStart: | 2379 case ItemPositionStart: |
2327 return GridAxisStart; | 2380 return GridAxisStart; |
2328 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent
to 'end'. | 2381 case ItemPositionFlexEnd: // Only used in flex layout, otherwise equivalent
to 'end'. |
| 2382 // Aligns the alignment subject to be flush with the alignment container
's 'end' edge (inline-end) in the row axis. |
2329 case ItemPositionEnd: | 2383 case ItemPositionEnd: |
2330 return GridAxisEnd; | 2384 return GridAxisEnd; |
2331 case ItemPositionStretch: | 2385 case ItemPositionStretch: |
2332 return GridAxisStart; | 2386 return GridAxisStart; |
2333 case ItemPositionBaseline: | 2387 case ItemPositionBaseline: |
2334 case ItemPositionLastBaseline: | 2388 case ItemPositionLastBaseline: |
2335 // FIXME: These two require implementing Baseline Alignment. For now, we
always 'start' align the child. | 2389 // FIXME: These two require implementing Baseline Alignment. For now, we
always 'start' align the child. |
2336 // crbug.com/234191 | 2390 // crbug.com/234191 |
2337 return GridAxisStart; | 2391 return GridAxisStart; |
2338 case ItemPositionAuto: | 2392 case ItemPositionAuto: |
(...skipping 21 matching lines...) Expand all Loading... |
2360 size_t childEndLine = rowsSpan.endLine(); | 2414 size_t childEndLine = rowsSpan.endLine(); |
2361 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 2415 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
2362 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters | 2416 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters |
2363 // so we need to subtract them to get the actual end position for a give
n row | 2417 // so we need to subtract them to get the actual end position for a give
n row |
2364 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2418 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
2365 LayoutUnit trackGap = gridGapForDirection(ForRows); | 2419 LayoutUnit trackGap = gridGapForDirection(ForRows); |
2366 if (childEndLine < m_rowPositions.size() - 1) { | 2420 if (childEndLine < m_rowPositions.size() - 1) { |
2367 endOfRow -= trackGap; | 2421 endOfRow -= trackGap; |
2368 endOfRow -= m_offsetBetweenRows; | 2422 endOfRow -= m_offsetBetweenRows; |
2369 } | 2423 } |
2370 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); | 2424 LayoutUnit columnAxisChildSize = isOrthogonalChild(child) ? child.logica
lWidth() + child.marginLogicalWidth() : child.logicalHeight() + child.marginLogi
calHeight(); |
2371 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); | 2425 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); |
2372 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, childBreadth); | 2426 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, columnAxisChildSize); |
2373 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2427 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
2374 } | 2428 } |
2375 } | 2429 } |
2376 | 2430 |
2377 ASSERT_NOT_REACHED(); | 2431 ASSERT_NOT_REACHED(); |
2378 return LayoutUnit(); | 2432 return LayoutUnit(); |
2379 } | 2433 } |
2380 | 2434 |
2381 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD
ata& sizingData) const | 2435 LayoutUnit LayoutGrid::rowAxisOffsetForChild(const LayoutBox& child, GridSizingD
ata& sizingData) const |
2382 { | 2436 { |
(...skipping 12 matching lines...) Expand all Loading... |
2395 size_t childEndLine = columnsSpan.endLine(); | 2449 size_t childEndLine = columnsSpan.endLine(); |
2396 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 2450 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
2397 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters | 2451 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters |
2398 // so we need to subtract them to get the actual end position for a give
n column | 2452 // so we need to subtract them to get the actual end position for a give
n column |
2399 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2453 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
2400 LayoutUnit trackGap = gridGapForDirection(ForColumns); | 2454 LayoutUnit trackGap = gridGapForDirection(ForColumns); |
2401 if (childEndLine < m_columnPositions.size() - 1) { | 2455 if (childEndLine < m_columnPositions.size() - 1) { |
2402 endOfColumn -= trackGap; | 2456 endOfColumn -= trackGap; |
2403 endOfColumn -= m_offsetBetweenColumns; | 2457 endOfColumn -= m_offsetBetweenColumns; |
2404 } | 2458 } |
2405 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); | 2459 LayoutUnit rowAxisChildSize = isOrthogonalChild(child) ? child.logicalHe
ight() + child.marginLogicalHeight() : child.logicalWidth() + child.marginLogica
lWidth(); |
2406 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); | 2460 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, rowAxi
sChildSize); |
2407 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2461 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
2408 } | 2462 } |
2409 } | 2463 } |
2410 | 2464 |
2411 ASSERT_NOT_REACHED(); | 2465 ASSERT_NOT_REACHED(); |
2412 return LayoutUnit(); | 2466 return LayoutUnit(); |
2413 } | 2467 } |
2414 | 2468 |
2415 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp
e distribution) | 2469 ContentPosition static resolveContentDistributionFallback(ContentDistributionTyp
e distribution) |
2416 { | 2470 { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 return rightGridEdgePosition + alignmentOffset - coordinate; | 2576 return rightGridEdgePosition + alignmentOffset - coordinate; |
2523 } | 2577 } |
2524 | 2578 |
2525 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz
ingData& sizingData) const | 2579 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz
ingData& sizingData) const |
2526 { | 2580 { |
2527 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); | 2581 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); |
2528 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); | 2582 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); |
2529 // We stored m_columnPosition's data ignoring the direction, hence we might
need now | 2583 // We stored m_columnPosition's data ignoring the direction, hence we might
need now |
2530 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. | 2584 // to translate positions from RTL to LTR, as it's more convenient for paint
ing. |
2531 if (!style()->isLeftToRightDirection()) | 2585 if (!style()->isLeftToRightDirection()) |
2532 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - child.logicalWid
th(); | 2586 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - (isOrthogonalChi
ld(child) ? child.logicalHeight() : child.logicalWidth()); |
2533 | 2587 |
2534 // "In the positioning phase [...] calculations are performed according to t
he writing mode | 2588 // "In the positioning phase [...] calculations are performed according to t
he writing mode |
2535 // of the containing block of the box establishing the orthogonal flow." How
ever, the | 2589 // of the containing block of the box establishing the orthogonal flow." How
ever, the |
2536 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se
t the child's | 2590 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se
t the child's |
2537 // logical position, which will only take into account the child's writing-m
ode. | 2591 // logical position, which will only take into account the child's writing-m
ode. |
2538 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); | 2592 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); |
2539 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; | 2593 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; |
2540 } | 2594 } |
2541 | 2595 |
2542 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2596 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
2543 { | 2597 { |
2544 if (!m_gridItemArea.isEmpty()) | 2598 if (!m_gridItemArea.isEmpty()) |
2545 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2599 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2546 } | 2600 } |
2547 | 2601 |
2548 } // namespace blink | 2602 } // namespace blink |
OLD | NEW |