| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/style/GridResolvedPosition.h" | 6 #include "core/style/GridResolvedPosition.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutBox.h" | 8 #include "core/layout/LayoutBox.h" |
| 9 #include "core/style/GridCoordinate.h" | 9 #include "core/style/GridCoordinate.h" |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); | 68 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 69 | 69 |
| 70 GridPositionSide finalSide = finalPositionSide(direction); | 70 GridPositionSide finalSide = finalPositionSide(direction); |
| 71 | 71 |
| 72 // This method will only be used when both positions need to be resolved aga
inst the opposite one. | 72 // This method will only be used when both positions need to be resolved aga
inst the opposite one. |
| 73 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); | 73 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); |
| 74 | 74 |
| 75 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition.next(); | 75 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition.next(); |
| 76 | 76 |
| 77 if (initialPosition.isSpan()) | 77 if (initialPosition.isSpan()) |
| 78 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r
esolvedInitialPosition, initialPosition, finalSide); | 78 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, initialPosition, finalSide); |
| 79 if (finalPosition.isSpan()) | 79 if (finalPosition.isSpan()) |
| 80 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r
esolvedInitialPosition, finalPosition, finalSide); | 80 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, finalPosition, finalSide); |
| 81 | 81 |
| 82 return GridSpan(resolvedInitialPosition, resolvedFinalPosition); | 82 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); |
| 83 } | 83 } |
| 84 | 84 |
| 85 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const C
omputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDire
ction direction) | 85 GridSpan GridResolvedPosition::resolveGridPositionsFromStyle(const ComputedStyle
& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direct
ion) |
| 86 { | 86 { |
| 87 GridPosition initialPosition, finalPosition; | 87 GridPosition initialPosition, finalPosition; |
| 88 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); | 88 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 89 | 89 |
| 90 GridPositionSide initialSide = initialPositionSide(direction); | 90 GridPositionSide initialSide = initialPositionSide(direction); |
| 91 GridPositionSide finalSide = finalPositionSide(direction); | 91 GridPositionSide finalSide = finalPositionSide(direction); |
| 92 | 92 |
| 93 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { | 93 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { |
| 94 // We can't get our grid positions without running the auto placement al
gorithm. | 94 // We can't get our grid positions without running the auto placement al
gorithm. |
| 95 return nullptr; | 95 return GridSpan::indefiniteGridSpan(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 98 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 99 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). | 99 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). |
| 100 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(gridContainerStyle, finalPosition, finalSide); | 100 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(gridContainerStyle, finalPosition, finalSide); |
| 101 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialSide); | 101 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialSide); |
| 102 } | 102 } |
| 103 | 103 |
| 104 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { | 104 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 105 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). | 105 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). |
| 106 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(gridContainerStyle, initialPosition, initialSide); | 106 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(gridContainerStyle, initialPosition, initialSide); |
| 107 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalSide); | 107 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalSide); |
| 108 } | 108 } |
| 109 | 109 |
| 110 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle(
gridContainerStyle, initialPosition, initialSide); | 110 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle(
gridContainerStyle, initialPosition, initialSide); |
| 111 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(gr
idContainerStyle, finalPosition, finalSide); | 111 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(gr
idContainerStyle, finalPosition, finalSide); |
| 112 | 112 |
| 113 // If 'grid-after' specifies a line at or before that specified by 'grid-bef
ore', it computes to 'span 1'. | 113 // If 'grid-after' specifies a line at or before that specified by 'grid-bef
ore', it computes to 'span 1'. |
| 114 if (resolvedFinalPosition <= resolvedInitialPosition) | 114 if (resolvedFinalPosition <= resolvedInitialPosition) |
| 115 resolvedFinalPosition = resolvedInitialPosition.next(); | 115 resolvedFinalPosition = resolvedInitialPosition.next(); |
| 116 | 116 |
| 117 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition)
); | 117 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); |
| 118 } | 118 } |
| 119 | 119 |
| 120 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo
ntainerStyle) | 120 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo
ntainerStyle) |
| 121 { | 121 { |
| 122 return std::min(gridContainerStyle.gridTemplateColumns().size(), kGridMaxTra
cks); | 122 return std::min(gridContainerStyle.gridTemplateColumns().size(), kGridMaxTra
cks); |
| 123 } | 123 } |
| 124 | 124 |
| 125 size_t GridResolvedPosition::explicitGridRowCount(const ComputedStyle& gridConta
inerStyle) | 125 size_t GridResolvedPosition::explicitGridRowCount(const ComputedStyle& gridConta
inerStyle) |
| 126 { | 126 { |
| 127 return std::min(gridContainerStyle.gridTemplateRows().size(), kGridMaxTracks
); | 127 return std::min(gridContainerStyle.gridTemplateRows().size(), kGridMaxTracks
); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 case AutoPosition: | 203 case AutoPosition: |
| 204 case SpanPosition: | 204 case SpanPosition: |
| 205 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). | 205 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). |
| 206 ASSERT_NOT_REACHED(); | 206 ASSERT_NOT_REACHED(); |
| 207 return GridResolvedPosition(0); | 207 return GridResolvedPosition(0); |
| 208 } | 208 } |
| 209 ASSERT_NOT_REACHED(); | 209 ASSERT_NOT_REACHED(); |
| 210 return GridResolvedPosition(0); | 210 return GridResolvedPosition(0); |
| 211 } | 211 } |
| 212 | 212 |
| 213 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePos
ition(const ComputedStyle& gridContainerStyle, const GridResolvedPosition& resol
vedOppositePosition, const GridPosition& position, GridPositionSide side) | 213 GridSpan GridResolvedPosition::resolveGridPositionAgainstOppositePosition(const
ComputedStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositeP
osition, const GridPosition& position, GridPositionSide side) |
| 214 { | 214 { |
| 215 if (position.isAuto()) { | 215 if (position.isAuto()) { |
| 216 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) | 216 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) |
| 217 return GridSpan::create(resolvedOppositePosition.prev(), resolvedOpp
ositePosition); | 217 return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), r
esolvedOppositePosition); |
| 218 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on.next()); | 218 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition.next()); |
| 219 } | 219 } |
| 220 | 220 |
| 221 ASSERT(position.isSpan()); | 221 ASSERT(position.isSpan()); |
| 222 ASSERT(position.spanPosition() > 0); | 222 ASSERT(position.spanPosition() > 0); |
| 223 | 223 |
| 224 if (!position.namedGridLine().isNull()) { | 224 if (!position.namedGridLine().isNull()) { |
| 225 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. | 225 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. |
| 226 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); | 226 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); |
| 227 } | 227 } |
| 228 | 228 |
| 229 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); | 229 return GridSpan::definiteGridSpanWithSpanAgainstOpposite(resolvedOppositePos
ition, position, side); |
| 230 } | 230 } |
| 231 | 231 |
| 232 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
positePosition(const ComputedStyle& gridContainerStyle, const GridResolvedPositi
on& resolvedOppositePosition, const GridPosition& position, GridPositionSide sid
e) | 232 GridSpan GridResolvedPosition::resolveNamedGridLinePositionAgainstOppositePositi
on(const ComputedStyle& gridContainerStyle, const GridResolvedPosition& resolved
OppositePosition, const GridPosition& position, GridPositionSide side) |
| 233 { | 233 { |
| 234 ASSERT(position.isSpan()); | 234 ASSERT(position.isSpan()); |
| 235 ASSERT(!position.namedGridLine().isNull()); | 235 ASSERT(!position.namedGridLine().isNull()); |
| 236 // Negative positions are not allowed per the specification and should have
been handled during parsing. | 236 // Negative positions are not allowed per the specification and should have
been handled during parsing. |
| 237 ASSERT(position.spanPosition() > 0); | 237 ASSERT(position.spanPosition() > 0); |
| 238 | 238 |
| 239 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); | 239 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 240 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 240 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 241 | 241 |
| 242 // If there is no named grid line of that name, we resolve the position to '
auto' (which is equivalent to 'span 1' in this case). | 242 // If there is no named grid line of that name, we resolve the position to '
auto' (which is equivalent to 'span 1' in this case). |
| 243 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 243 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 244 if (it == gridLinesNames.end()) { | 244 if (it == gridLinesNames.end()) { |
| 245 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) | 245 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) |
| 246 return GridSpan::create(resolvedOppositePosition.prev(), resolvedOpp
ositePosition); | 246 return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), r
esolvedOppositePosition); |
| 247 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on.next()); | 247 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition.next()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 250 return GridSpan::definiteGridSpanWithNamedSpanAgainstOpposite(resolvedOpposi
tePosition, position, side, it->value); |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace blink | 253 } // namespace blink |
| OLD | NEW |