| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 if (finalPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamedLi
neOrArea(finalPosition.namedGridLine(), gridContainerStyle, GridResolvedPosition
::finalPositionSide(direction))) | 55 if (finalPosition.isNamedGridArea() && !GridResolvedPosition::isValidNamedLi
neOrArea(finalPosition.namedGridLine(), gridContainerStyle, GridResolvedPosition
::finalPositionSide(direction))) |
| 56 finalPosition.setAutoPosition(); | 56 finalPosition.setAutoPosition(); |
| 57 | 57 |
| 58 // If the grid item has an automatic position and a grid span for a named li
ne in a given dimension, instead treat the grid span as one. | 58 // If the grid item has an automatic position and a grid span for a named li
ne in a given dimension, instead treat the grid span as one. |
| 59 if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.nam
edGridLine().isNull()) | 59 if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.nam
edGridLine().isNull()) |
| 60 finalPosition.setSpanPosition(1, String()); | 60 finalPosition.setSpanPosition(1, String()); |
| 61 if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.n
amedGridLine().isNull()) | 61 if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.n
amedGridLine().isNull()) |
| 62 initialPosition.setSpanPosition(1, String()); | 62 initialPosition.setSpanPosition(1, String()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static GridSpan definiteGridSpanWithInitialNamedSpanAgainstOpposite(const GridRe
solvedPosition& resolvedOppositePosition, const GridPosition& position, const Ve
ctor<size_t>& gridLines) | 65 static GridSpan definiteGridSpanWithInitialNamedSpanAgainstOpposite(const size_t
resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& g
ridLines) |
| 66 { | 66 { |
| 67 if (resolvedOppositePosition == 0) | 67 if (resolvedOppositePosition == 0) |
| 68 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition.next()); | 68 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition + 1); |
| 69 | 69 |
| 70 size_t firstLineBeforeOppositePositionIndex = 0; | 70 size_t firstLineBeforeOppositePositionIndex = 0; |
| 71 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLines.b
egin(), gridLines.end(), resolvedOppositePosition.toInt()); | 71 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLines.b
egin(), gridLines.end(), resolvedOppositePosition); |
| 72 if (firstLineBeforeOppositePosition != gridLines.end()) | 72 if (firstLineBeforeOppositePosition != gridLines.end()) |
| 73 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePosition -
gridLines.begin(); | 73 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePosition -
gridLines.begin(); |
| 74 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex
- position.spanPosition()); | 74 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex
- position.spanPosition()); |
| 75 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(gridLin
es[gridLineIndex]); | 75 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; |
| 76 if (resolvedGridLinePosition >= resolvedOppositePosition) | 76 if (resolvedGridLinePosition >= resolvedOppositePosition) |
| 77 resolvedGridLinePosition = resolvedOppositePosition.prev(); | 77 resolvedGridLinePosition = resolvedOppositePosition - 1; |
| 78 return GridSpan::definiteGridSpan(resolvedGridLinePosition, resolvedOpposite
Position); | 78 return GridSpan::definiteGridSpan(resolvedGridLinePosition, resolvedOpposite
Position); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static GridSpan definiteGridSpanWithFinalNamedSpanAgainstOpposite(const GridReso
lvedPosition& resolvedOppositePosition, const GridPosition& position, const Vect
or<size_t>& gridLines) | 81 static GridSpan definiteGridSpanWithFinalNamedSpanAgainstOpposite(const size_t r
esolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gri
dLines) |
| 82 { | 82 { |
| 83 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; | 83 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; |
| 84 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLines.be
gin(), gridLines.end(), resolvedOppositePosition.toInt()); | 84 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLines.be
gin(), gridLines.end(), resolvedOppositePosition); |
| 85 if (firstLineAfterOppositePosition != gridLines.end()) | 85 if (firstLineAfterOppositePosition != gridLines.end()) |
| 86 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition - g
ridLines.begin(); | 86 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition - g
ridLines.begin(); |
| 87 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOpposite
PositionIndex + position.spanPosition() - 1); | 87 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOpposite
PositionIndex + position.spanPosition() - 1); |
| 88 GridResolvedPosition resolvedGridLinePosition = gridLines[gridLineIndex]; | 88 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; |
| 89 if (resolvedGridLinePosition <= resolvedOppositePosition) | 89 if (resolvedGridLinePosition <= resolvedOppositePosition) |
| 90 resolvedGridLinePosition = resolvedOppositePosition.next(); | 90 resolvedGridLinePosition = resolvedOppositePosition + 1; |
| 91 | 91 |
| 92 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedGridLine
Position); | 92 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedGridLine
Position); |
| 93 } | 93 } |
| 94 | 94 |
| 95 static GridSpan definiteGridSpanWithNamedSpanAgainstOpposite(const GridResolvedP
osition& resolvedOppositePosition, const GridPosition& position, GridPositionSid
e side, const Vector<size_t>& gridLines) | 95 static GridSpan definiteGridSpanWithNamedSpanAgainstOpposite(const size_t resolv
edOppositePosition, const GridPosition& position, GridPositionSide side, const V
ector<size_t>& gridLines) |
| 96 { | 96 { |
| 97 if (side == RowStartSide || side == ColumnStartSide) | 97 if (side == RowStartSide || side == ColumnStartSide) |
| 98 return definiteGridSpanWithInitialNamedSpanAgainstOpposite(resolvedOppos
itePosition, position, gridLines); | 98 return definiteGridSpanWithInitialNamedSpanAgainstOpposite(resolvedOppos
itePosition, position, gridLines); |
| 99 | 99 |
| 100 return definiteGridSpanWithFinalNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); | 100 return definiteGridSpanWithFinalNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); |
| 101 } | 101 } |
| 102 | 102 |
| 103 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition(const Comput
edStyle& gridContainerStyle, const GridResolvedPosition& resolvedOppositePositio
n, const GridPosition& position, GridPositionSide side) | 103 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition(const Comput
edStyle& gridContainerStyle, const size_t resolvedOppositePosition, const GridPo
sition& position, GridPositionSide side) |
| 104 { | 104 { |
| 105 ASSERT(position.isSpan()); | 105 ASSERT(position.isSpan()); |
| 106 ASSERT(!position.namedGridLine().isNull()); | 106 ASSERT(!position.namedGridLine().isNull()); |
| 107 // Negative positions are not allowed per the specification and should have
been handled during parsing. | 107 // Negative positions are not allowed per the specification and should have
been handled during parsing. |
| 108 ASSERT(position.spanPosition() > 0); | 108 ASSERT(position.spanPosition() > 0); |
| 109 | 109 |
| 110 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); | 110 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 111 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 111 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 112 | 112 |
| 113 // 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). | 113 // 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). |
| 114 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 114 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 115 if (it == gridLinesNames.end()) { | 115 if (it == gridLinesNames.end()) { |
| 116 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) | 116 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition) |
| 117 return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), r
esolvedOppositePosition); | 117 return GridSpan::definiteGridSpan(resolvedOppositePosition - 1, reso
lvedOppositePosition); |
| 118 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition.next()); | 118 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition + 1); |
| 119 } | 119 } |
| 120 | 120 |
| 121 return definiteGridSpanWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 121 return definiteGridSpanWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 122 } | 122 } |
| 123 | 123 |
| 124 static GridSpan definiteGridSpanWithSpanAgainstOpposite(const GridResolvedPositi
on& resolvedOppositePosition, const GridPosition& position, GridPositionSide sid
e) | 124 static GridSpan definiteGridSpanWithSpanAgainstOpposite(const size_t resolvedOpp
ositePosition, const GridPosition& position, GridPositionSide side) |
| 125 { | 125 { |
| 126 size_t positionOffset = position.spanPosition(); | 126 size_t positionOffset = position.spanPosition(); |
| 127 if (side == ColumnStartSide || side == RowStartSide) { | 127 if (side == ColumnStartSide || side == RowStartSide) { |
| 128 if (resolvedOppositePosition == 0) | 128 if (resolvedOppositePosition == 0) |
| 129 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolved
OppositePosition.next()); | 129 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolved
OppositePosition + 1); |
| 130 | 130 |
| 131 GridResolvedPosition initialResolvedPosition = GridResolvedPosition(std:
:max<int>(0, resolvedOppositePosition.toInt() - positionOffset)); | 131 size_t initialResolvedPosition = std::max<int>(0, resolvedOppositePositi
on - positionOffset); |
| 132 return GridSpan::definiteGridSpan(initialResolvedPosition, resolvedOppos
itePosition); | 132 return GridSpan::definiteGridSpan(initialResolvedPosition, resolvedOppos
itePosition); |
| 133 } | 133 } |
| 134 | 134 |
| 135 return GridSpan::definiteGridSpan(resolvedOppositePosition, GridResolvedPosi
tion(resolvedOppositePosition.toInt() + positionOffset)); | 135 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOpposite
Position + positionOffset); |
| 136 } | 136 } |
| 137 | 137 |
| 138 static GridSpan resolveGridPositionAgainstOppositePosition(const ComputedStyle&
gridContainerStyle, const GridResolvedPosition& resolvedOppositePosition, const
GridPosition& position, GridPositionSide side) | 138 static GridSpan resolveGridPositionAgainstOppositePosition(const ComputedStyle&
gridContainerStyle, const size_t resolvedOppositePosition, const GridPosition& p
osition, GridPositionSide side) |
| 139 { | 139 { |
| 140 if (position.isAuto()) { | 140 if (position.isAuto()) { |
| 141 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition.toInt()) | 141 if ((side == ColumnStartSide || side == RowStartSide) && resolvedOpposit
ePosition) |
| 142 return GridSpan::definiteGridSpan(resolvedOppositePosition.prev(), r
esolvedOppositePosition); | 142 return GridSpan::definiteGridSpan(resolvedOppositePosition - 1, reso
lvedOppositePosition); |
| 143 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition.next()); | 143 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedOppo
sitePosition + 1); |
| 144 } | 144 } |
| 145 | 145 |
| 146 ASSERT(position.isSpan()); | 146 ASSERT(position.isSpan()); |
| 147 ASSERT(position.spanPosition() > 0); | 147 ASSERT(position.spanPosition() > 0); |
| 148 | 148 |
| 149 if (!position.namedGridLine().isNull()) { | 149 if (!position.namedGridLine().isNull()) { |
| 150 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. | 150 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. |
| 151 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); | 151 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer
Style, resolvedOppositePosition, position, side); |
| 152 } | 152 } |
| 153 | 153 |
| 154 return definiteGridSpanWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); | 154 return definiteGridSpanWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); |
| 155 } | 155 } |
| 156 | 156 |
| 157 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing
Direction direction, const GridResolvedPosition& resolvedInitialPosition) | 157 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing
Direction direction, const size_t resolvedInitialPosition) |
| 158 { | 158 { |
| 159 GridPosition initialPosition, finalPosition; | 159 GridPosition initialPosition, finalPosition; |
| 160 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); | 160 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 161 | 161 |
| 162 GridPositionSide finalSide = finalPositionSide(direction); | 162 GridPositionSide finalSide = finalPositionSide(direction); |
| 163 | 163 |
| 164 // This method will only be used when both positions need to be resolved aga
inst the opposite one. | 164 // This method will only be used when both positions need to be resolved aga
inst the opposite one. |
| 165 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); | 165 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); |
| 166 | 166 |
| 167 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition.next(); | 167 size_t resolvedFinalPosition = resolvedInitialPosition + 1; |
| 168 | 168 |
| 169 if (initialPosition.isSpan()) | 169 if (initialPosition.isSpan()) |
| 170 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, initialPosition, finalSide); | 170 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, initialPosition, finalSide); |
| 171 if (finalPosition.isSpan()) | 171 if (finalPosition.isSpan()) |
| 172 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, finalPosition, finalSide); | 172 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, re
solvedInitialPosition, finalPosition, finalSide); |
| 173 | 173 |
| 174 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); | 174 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); |
| 175 } | 175 } |
| 176 | 176 |
| 177 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo
ntainerStyle) | 177 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo
ntainerStyle) |
| 178 { | 178 { |
| 179 return std::min(gridContainerStyle.gridTemplateColumns().size(), kGridMaxTra
cks); | 179 return std::min(gridContainerStyle.gridTemplateColumns().size(), kGridMaxTra
cks); |
| 180 } | 180 } |
| 181 | 181 |
| 182 size_t GridResolvedPosition::explicitGridRowCount(const ComputedStyle& gridConta
inerStyle) | 182 size_t GridResolvedPosition::explicitGridRowCount(const ComputedStyle& gridConta
inerStyle) |
| 183 { | 183 { |
| 184 return std::min(gridContainerStyle.gridTemplateRows().size(), kGridMaxTracks
); | 184 return std::min(gridContainerStyle.gridTemplateRows().size(), kGridMaxTracks
); |
| 185 } | 185 } |
| 186 | 186 |
| 187 static size_t explicitGridSizeForSide(const ComputedStyle& gridContainerStyle, G
ridPositionSide side) | 187 static size_t explicitGridSizeForSide(const ComputedStyle& gridContainerStyle, G
ridPositionSide side) |
| 188 { | 188 { |
| 189 return (side == ColumnStartSide || side == ColumnEndSide) ? GridResolvedPosi
tion::explicitGridColumnCount(gridContainerStyle) : GridResolvedPosition::explic
itGridRowCount(gridContainerStyle); | 189 return (side == ColumnStartSide || side == ColumnEndSide) ? GridResolvedPosi
tion::explicitGridColumnCount(gridContainerStyle) : GridResolvedPosition::explic
itGridRowCount(gridContainerStyle); |
| 190 } | 190 } |
| 191 | 191 |
| 192 static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const Computed
Style& gridContainerStyle, const GridPosition& position, GridPositionSide side) | 192 static size_t resolveNamedGridLinePositionFromStyle(const ComputedStyle& gridCon
tainerStyle, const GridPosition& position, GridPositionSide side) |
| 193 { | 193 { |
| 194 ASSERT(!position.namedGridLine().isNull()); | 194 ASSERT(!position.namedGridLine().isNull()); |
| 195 | 195 |
| 196 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); | 196 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 197 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 197 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 198 if (it == gridLinesNames.end()) { | 198 if (it == gridLinesNames.end()) { |
| 199 if (position.isPositive()) | 199 if (position.isPositive()) |
| 200 return GridResolvedPosition(0); | 200 return 0; |
| 201 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side
); | 201 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side
); |
| 202 return lastLine; | 202 return lastLine; |
| 203 } | 203 } |
| 204 | 204 |
| 205 size_t namedGridLineIndex; | 205 size_t namedGridLineIndex; |
| 206 if (position.isPositive()) | 206 if (position.isPositive()) |
| 207 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; | 207 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; |
| 208 else | 208 else |
| 209 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); | 209 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); |
| 210 return it->value[namedGridLineIndex]; | 210 return it->value[namedGridLineIndex]; |
| 211 } | 211 } |
| 212 | 212 |
| 213 static GridResolvedPosition resolveGridPositionFromStyle(const ComputedStyle& gr
idContainerStyle, const GridPosition& position, GridPositionSide side) | 213 static size_t resolveGridPositionFromStyle(const ComputedStyle& gridContainerSty
le, const GridPosition& position, GridPositionSide side) |
| 214 { | 214 { |
| 215 switch (position.type()) { | 215 switch (position.type()) { |
| 216 case ExplicitPosition: { | 216 case ExplicitPosition: { |
| 217 ASSERT(position.integerPosition()); | 217 ASSERT(position.integerPosition()); |
| 218 | 218 |
| 219 if (!position.namedGridLine().isNull()) | 219 if (!position.namedGridLine().isNull()) |
| 220 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, pos
ition, side); | 220 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, pos
ition, side); |
| 221 | 221 |
| 222 // Handle <integer> explicit position. | 222 // Handle <integer> explicit position. |
| 223 if (position.isPositive()) | 223 if (position.isPositive()) |
| 224 return position.integerPosition() - 1; | 224 return position.integerPosition() - 1; |
| 225 | 225 |
| 226 size_t resolvedPosition = abs(position.integerPosition()) - 1; | 226 size_t resolvedPosition = abs(position.integerPosition()) - 1; |
| 227 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si
de); | 227 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si
de); |
| 228 | 228 |
| 229 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. | 229 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. |
| 230 if (endOfTrack < resolvedPosition) | 230 if (endOfTrack < resolvedPosition) |
| 231 return GridResolvedPosition(0); | 231 return 0; |
| 232 | 232 |
| 233 return endOfTrack - resolvedPosition; | 233 return endOfTrack - resolvedPosition; |
| 234 } | 234 } |
| 235 case NamedGridAreaPosition: | 235 case NamedGridAreaPosition: |
| 236 { | 236 { |
| 237 // First attempt to match the grid area's edge to a named grid area: if
there is a named line with the name | 237 // First attempt to match the grid area's edge to a named grid area: if
there is a named line with the name |
| 238 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such | 238 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such |
| 239 // line to the grid item's placement. | 239 // line to the grid item's placement. |
| 240 String namedGridLine = position.namedGridLine(); | 240 String namedGridLine = position.namedGridLine(); |
| 241 ASSERT(GridResolvedPosition::isValidNamedLineOrArea(namedGridLine, gridC
ontainerStyle, side)); | 241 ASSERT(GridResolvedPosition::isValidNamedLineOrArea(namedGridLine, gridC
ontainerStyle, side)); |
| 242 | 242 |
| 243 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); | 243 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); |
| 244 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLineForSide(namedGridLine, side)); | 244 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLineForSide(namedGridLine, side)); |
| 245 if (implicitLineIter != gridLineNames.end()) | 245 if (implicitLineIter != gridLineNames.end()) |
| 246 return implicitLineIter->value[0]; | 246 return implicitLineIter->value[0]; |
| 247 | 247 |
| 248 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid | 248 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid |
| 249 // item's placement. | 249 // item's placement. |
| 250 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); | 250 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); |
| 251 if (explicitLineIter != gridLineNames.end()) | 251 if (explicitLineIter != gridLineNames.end()) |
| 252 return explicitLineIter->value[0]; | 252 return explicitLineIter->value[0]; |
| 253 | 253 |
| 254 // If none of the above works specs mandate us to treat it as auto BUT w
e should have detected it before calling | 254 // If none of the above works specs mandate us to treat it as auto BUT w
e should have detected it before calling |
| 255 // this function in GridResolvedPosition::resolveGridPositionsFromStyle(
). We should be also covered by the | 255 // this function in GridResolvedPosition::resolveGridPositionsFromStyle(
). We should be also covered by the |
| 256 // ASSERT at the beginning of this block. | 256 // ASSERT at the beginning of this block. |
| 257 ASSERT_NOT_REACHED(); | 257 ASSERT_NOT_REACHED(); |
| 258 return GridResolvedPosition(0); | 258 return 0; |
| 259 } | 259 } |
| 260 case AutoPosition: | 260 case AutoPosition: |
| 261 case SpanPosition: | 261 case SpanPosition: |
| 262 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). | 262 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). |
| 263 ASSERT_NOT_REACHED(); | 263 ASSERT_NOT_REACHED(); |
| 264 return GridResolvedPosition(0); | 264 return 0; |
| 265 } | 265 } |
| 266 ASSERT_NOT_REACHED(); | 266 ASSERT_NOT_REACHED(); |
| 267 return GridResolvedPosition(0); | 267 return 0; |
| 268 } | 268 } |
| 269 | 269 |
| 270 GridSpan GridResolvedPosition::resolveGridPositionsFromStyle(const ComputedStyle
& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direct
ion) | 270 GridSpan GridResolvedPosition::resolveGridPositionsFromStyle(const ComputedStyle
& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direct
ion) |
| 271 { | 271 { |
| 272 GridPosition initialPosition, finalPosition; | 272 GridPosition initialPosition, finalPosition; |
| 273 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); | 273 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 274 | 274 |
| 275 GridPositionSide initialSide = initialPositionSide(direction); | 275 GridPositionSide initialSide = initialPositionSide(direction); |
| 276 GridPositionSide finalSide = finalPositionSide(direction); | 276 GridPositionSide finalSide = finalPositionSide(direction); |
| 277 | 277 |
| 278 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { | 278 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { |
| 279 // We can't get our grid positions without running the auto placement al
gorithm. | 279 // We can't get our grid positions without running the auto placement al
gorithm. |
| 280 return GridSpan::indefiniteGridSpan(); | 280 return GridSpan::indefiniteGridSpan(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 283 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 284 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). | 284 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). |
| 285 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(gridContainerStyle, finalPosition, finalSide); | 285 size_t finalResolvedPosition = resolveGridPositionFromStyle(gridContaine
rStyle, finalPosition, finalSide); |
| 286 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialSide); | 286 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialSide); |
| 287 } | 287 } |
| 288 | 288 |
| 289 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { | 289 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 290 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). | 290 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). |
| 291 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(gridContainerStyle, initialPosition, initialSide); | 291 size_t initialResolvedPosition = resolveGridPositionFromStyle(gridContai
nerStyle, initialPosition, initialSide); |
| 292 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalSide); | 292 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalSide); |
| 293 } | 293 } |
| 294 | 294 |
| 295 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle(
gridContainerStyle, initialPosition, initialSide); | 295 size_t resolvedInitialPosition = resolveGridPositionFromStyle(gridContainerS
tyle, initialPosition, initialSide); |
| 296 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(gr
idContainerStyle, finalPosition, finalSide); | 296 size_t resolvedFinalPosition = resolveGridPositionFromStyle(gridContainerSty
le, finalPosition, finalSide); |
| 297 | 297 |
| 298 if (resolvedFinalPosition < resolvedInitialPosition) | 298 if (resolvedFinalPosition < resolvedInitialPosition) |
| 299 std::swap(resolvedFinalPosition, resolvedInitialPosition); | 299 std::swap(resolvedFinalPosition, resolvedInitialPosition); |
| 300 else if (resolvedFinalPosition == resolvedInitialPosition) | 300 else if (resolvedFinalPosition == resolvedInitialPosition) |
| 301 resolvedFinalPosition = resolvedInitialPosition.next(); | 301 resolvedFinalPosition = resolvedInitialPosition + 1; |
| 302 | 302 |
| 303 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); | 303 return GridSpan::definiteGridSpan(resolvedInitialPosition, resolvedFinalPosi
tion); |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace blink | 306 } // namespace blink |
| OLD | NEW |