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