| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing
Direction direction, const GridResolvedPosition& resolvedInitialPosition) | 65 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing
Direction direction, const GridResolvedPosition& resolvedInitialPosition) |
| 66 { | 66 { |
| 67 GridPosition initialPosition, finalPosition; | 67 GridPosition initialPosition, finalPosition; |
| 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; | 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, r
esolvedInitialPosition, initialPosition, finalSide); |
| 79 if (finalPosition.isSpan()) | 79 if (finalPosition.isSpan()) |
| 80 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r
esolvedInitialPosition, finalPosition, finalSide); | 80 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r
esolvedInitialPosition, finalPosition, finalSide); |
| 81 | 81 |
| 82 return GridSpan(resolvedInitialPosition, resolvedFinalPosition); | 82 return GridSpan(resolvedInitialPosition, resolvedFinalPosition); |
| 83 } | 83 } |
| 84 | 84 |
| 85 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const C
omputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDire
ction direction) | 85 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const C
omputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDire
ction direction) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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; | 115 resolvedFinalPosition = resolvedInitialPosition.next(); |
| 116 | 116 |
| 117 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition)
); | 117 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition)
); |
| 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
); |
| 128 } | 128 } |
| 129 | 129 |
| 130 size_t GridResolvedPosition::explicitGridSizeForSide(const ComputedStyle& gridCo
ntainerStyle, GridPositionSide side) | 130 size_t GridResolvedPosition::explicitGridSizeForSide(const ComputedStyle& gridCo
ntainerStyle, GridPositionSide side) |
| 131 { | 131 { |
| 132 return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColu
mnCount(gridContainerStyle) : explicitGridRowCount(gridContainerStyle); | 132 return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColu
mnCount(gridContainerStyle) : explicitGridRowCount(gridContainerStyle); |
| 133 } | 133 } |
| 134 | 134 |
| 135 GridResolvedPosition GridResolvedPosition::resolveNamedGridLinePositionFromStyle
(const ComputedStyle& gridContainerStyle, const GridPosition& position, GridPosi
tionSide side) | 135 GridResolvedPosition GridResolvedPosition::resolveNamedGridLinePositionFromStyle
(const ComputedStyle& gridContainerStyle, const GridPosition& position, GridPosi
tionSide side) |
| 136 { | 136 { |
| 137 ASSERT(!position.namedGridLine().isNull()); | 137 ASSERT(!position.namedGridLine().isNull()); |
| 138 | 138 |
| 139 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); | 139 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 140 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 140 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 141 if (it == gridLinesNames.end()) { | 141 if (it == gridLinesNames.end()) { |
| 142 if (position.isPositive()) | 142 if (position.isPositive()) |
| 143 return GridResolvedPosition(0); | 143 return GridResolvedPosition(0); |
| 144 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side
); | 144 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side
); |
| 145 return adjustGridPositionForSide(lastLine, side); | 145 return lastLine; |
| 146 } | 146 } |
| 147 | 147 |
| 148 size_t namedGridLineIndex; | 148 size_t namedGridLineIndex; |
| 149 if (position.isPositive()) | 149 if (position.isPositive()) |
| 150 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; | 150 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; |
| 151 else | 151 else |
| 152 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); | 152 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); |
| 153 return adjustGridPositionForSide(it->value[namedGridLineIndex], side); | 153 return it->value[namedGridLineIndex]; |
| 154 } | 154 } |
| 155 | 155 |
| 156 GridResolvedPosition GridResolvedPosition::resolveGridPositionFromStyle(const Co
mputedStyle& gridContainerStyle, const GridPosition& position, GridPositionSide
side) | 156 GridResolvedPosition GridResolvedPosition::resolveGridPositionFromStyle(const Co
mputedStyle& gridContainerStyle, const GridPosition& position, GridPositionSide
side) |
| 157 { | 157 { |
| 158 switch (position.type()) { | 158 switch (position.type()) { |
| 159 case ExplicitPosition: { | 159 case ExplicitPosition: { |
| 160 ASSERT(position.integerPosition()); | 160 ASSERT(position.integerPosition()); |
| 161 | 161 |
| 162 if (!position.namedGridLine().isNull()) | 162 if (!position.namedGridLine().isNull()) |
| 163 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, pos
ition, side); | 163 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, pos
ition, side); |
| 164 | 164 |
| 165 // Handle <integer> explicit position. | 165 // Handle <integer> explicit position. |
| 166 if (position.isPositive()) | 166 if (position.isPositive()) |
| 167 return adjustGridPositionForSide(position.integerPosition() - 1, sid
e); | 167 return position.integerPosition() - 1; |
| 168 | 168 |
| 169 size_t resolvedPosition = abs(position.integerPosition()) - 1; | 169 size_t resolvedPosition = abs(position.integerPosition()) - 1; |
| 170 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si
de); | 170 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si
de); |
| 171 | 171 |
| 172 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. | 172 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. |
| 173 if (endOfTrack < resolvedPosition) | 173 if (endOfTrack < resolvedPosition) |
| 174 return GridResolvedPosition(0); | 174 return GridResolvedPosition(0); |
| 175 | 175 |
| 176 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); | 176 return endOfTrack - resolvedPosition; |
| 177 } | 177 } |
| 178 case NamedGridAreaPosition: | 178 case NamedGridAreaPosition: |
| 179 { | 179 { |
| 180 // First attempt to match the grid area's edge to a named grid area: if
there is a named line with the name | 180 // First attempt to match the grid area's edge to a named grid area: if
there is a named line with the name |
| 181 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such | 181 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such |
| 182 // line to the grid item's placement. | 182 // line to the grid item's placement. |
| 183 String namedGridLine = position.namedGridLine(); | 183 String namedGridLine = position.namedGridLine(); |
| 184 ASSERT(isValidNamedLineOrArea(namedGridLine, gridContainerStyle, side)); | 184 ASSERT(isValidNamedLineOrArea(namedGridLine, gridContainerStyle, side)); |
| 185 | 185 |
| 186 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); | 186 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); |
| 187 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLineForSide(namedGridLine, side)); | 187 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLineForSide(namedGridLine, side)); |
| 188 if (implicitLineIter != gridLineNames.end()) | 188 if (implicitLineIter != gridLineNames.end()) |
| 189 return adjustGridPositionForSide(implicitLineIter->value[0], side); | 189 return implicitLineIter->value[0]; |
| 190 | 190 |
| 191 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid | 191 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid |
| 192 // item's placement. | 192 // item's placement. |
| 193 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); | 193 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); |
| 194 if (explicitLineIter != gridLineNames.end()) | 194 if (explicitLineIter != gridLineNames.end()) |
| 195 return adjustGridPositionForSide(explicitLineIter->value[0], side); | 195 return explicitLineIter->value[0]; |
| 196 | 196 |
| 197 // If none of the above works specs mandate us to treat it as auto BUT w
e should have detected it before calling | 197 // If none of the above works specs mandate us to treat it as auto BUT w
e should have detected it before calling |
| 198 // this function in GridResolvedPosition::resolveGridPositionsFromStyle(
). We should be also covered by the | 198 // this function in GridResolvedPosition::resolveGridPositionsFromStyle(
). We should be also covered by the |
| 199 // ASSERT at the beginning of this block. | 199 // ASSERT at the beginning of this block. |
| 200 ASSERT_NOT_REACHED(); | 200 ASSERT_NOT_REACHED(); |
| 201 return GridResolvedPosition(0); | 201 return GridResolvedPosition(0); |
| 202 } | 202 } |
| 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 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePos
ition(const ComputedStyle& gridContainerStyle, const GridResolvedPosition& resol
vedOppositePosition, const GridPosition& position, GridPositionSide side) |
| 214 { | 214 { |
| 215 if (position.isAuto()) | 215 if (position.isAuto()) { |
| 216 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 216 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) |
| 217 return GridSpan::create(resolvedOppositePosition.prev(), resolvedOpp
ositePosition); |
| 218 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on.next()); |
| 219 } |
| 217 | 220 |
| 218 ASSERT(position.isSpan()); | 221 ASSERT(position.isSpan()); |
| 219 ASSERT(position.spanPosition() > 0); | 222 ASSERT(position.spanPosition() > 0); |
| 220 | 223 |
| 221 if (!position.namedGridLine().isNull()) { | 224 if (!position.namedGridLine().isNull()) { |
| 222 // 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. |
| 223 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); | 226 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); |
| 224 } | 227 } |
| 225 | 228 |
| 226 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); | 229 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); |
| 227 } | 230 } |
| 228 | 231 |
| 229 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
positePosition(const ComputedStyle& gridContainerStyle, const GridResolvedPositi
on& resolvedOppositePosition, const GridPosition& position, GridPositionSide sid
e) | 232 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
positePosition(const ComputedStyle& gridContainerStyle, const GridResolvedPositi
on& resolvedOppositePosition, const GridPosition& position, GridPositionSide sid
e) |
| 230 { | 233 { |
| 231 ASSERT(position.isSpan()); | 234 ASSERT(position.isSpan()); |
| 232 ASSERT(!position.namedGridLine().isNull()); | 235 ASSERT(!position.namedGridLine().isNull()); |
| 233 // 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. |
| 234 ASSERT(position.spanPosition() > 0); | 237 ASSERT(position.spanPosition() > 0); |
| 235 | 238 |
| 236 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); | 239 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 237 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 240 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 238 | 241 |
| 239 // 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). |
| 240 // 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. |
| 241 if (it == gridLinesNames.end()) | 244 if (it == gridLinesNames.end()) { |
| 242 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 245 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) |
| 246 return GridSpan::create(resolvedOppositePosition.prev(), resolvedOpp
ositePosition); |
| 247 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on.next()); |
| 248 } |
| 243 | 249 |
| 244 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 250 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 245 } | 251 } |
| 246 | 252 |
| 247 } // namespace blink | 253 } // namespace blink |
| OLD | NEW |