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 "GridPositionsResolver.h" | 5 #include "GridPositionsResolver.h" |
6 | 6 |
7 #include "core/layout/LayoutBox.h" | 7 #include "core/layout/LayoutBox.h" |
8 #include "core/style/GridArea.h" | 8 #include "core/style/GridArea.h" |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 } | 99 } |
100 | 100 |
101 for (; numberOfLines; --start) { | 101 for (; numberOfLines; --start) { |
102 if (start < 0 || namedGridLinesIndexes->contains(static_cast<size_t>(sta rt))) | 102 if (start < 0 || namedGridLinesIndexes->contains(static_cast<size_t>(sta rt))) |
103 numberOfLines--; | 103 numberOfLines--; |
104 } | 104 } |
105 | 105 |
106 return start + 1; | 106 return start + 1; |
107 } | 107 } |
108 | 108 |
109 static GridSpan definiteGridSpanWithNamedSpanAgainstOpposite(int resolvedOpposit ePosition, const GridPosition& position, GridPositionSide side, const Vector<siz e_t>* gridLines, int lastLine) | 109 static GridSpan definiteGridSpanWithNamedSpanAgainstOpposite(int opossiteLine, c onst GridPosition& position, GridPositionSide side, const Vector<size_t>* gridLi nes, int lastLine) |
110 { | 110 { |
111 int start, end; | 111 int start, end; |
112 | 112 |
113 if (side == RowStartSide || side == ColumnStartSide) { | 113 if (side == RowStartSide || side == ColumnStartSide) { |
114 start = lookBackForNamedGridLine(resolvedOppositePosition - 1, position. spanPosition(), gridLines, lastLine); | 114 start = lookBackForNamedGridLine(opossiteLine - 1, position.spanPosition (), gridLines, lastLine); |
115 end = resolvedOppositePosition; | 115 end = opossiteLine; |
116 } else { | 116 } else { |
117 start = resolvedOppositePosition; | 117 start = opossiteLine; |
118 end = lookAheadForNamedGridLine(resolvedOppositePosition + 1, position.s panPosition(), gridLines, lastLine); | 118 end = lookAheadForNamedGridLine(opossiteLine + 1, position.spanPosition( ), gridLines, lastLine); |
119 } | 119 } |
120 | 120 |
121 return GridSpan::untranslatedDefiniteGridSpan(start, end); | 121 return GridSpan::untranslatedDefiniteGridSpan(start, end); |
122 } | 122 } |
123 | 123 |
124 size_t GridPositionsResolver::explicitGridColumnCount(const ComputedStyle& gridC ontainerStyle) | 124 size_t GridPositionsResolver::explicitGridColumnCount(const ComputedStyle& gridC ontainerStyle) |
125 { | 125 { |
126 return std::min<size_t>(gridContainerStyle.gridTemplateColumns().size(), kGr idMaxTracks); | 126 return std::min<size_t>(gridContainerStyle.gridTemplateColumns().size(), kGr idMaxTracks); |
127 } | 127 } |
128 | 128 |
129 size_t GridPositionsResolver::explicitGridRowCount(const ComputedStyle& gridCont ainerStyle) | 129 size_t GridPositionsResolver::explicitGridRowCount(const ComputedStyle& gridCont ainerStyle) |
130 { | 130 { |
131 return std::min<size_t>(gridContainerStyle.gridTemplateRows().size(), kGridM axTracks); | 131 return std::min<size_t>(gridContainerStyle.gridTemplateRows().size(), kGridM axTracks); |
132 } | 132 } |
133 | 133 |
134 static size_t explicitGridSizeForSide(const ComputedStyle& gridContainerStyle, G ridPositionSide side) | 134 static size_t explicitGridSizeForSide(const ComputedStyle& gridContainerStyle, G ridPositionSide side) |
135 { | 135 { |
136 return (side == ColumnStartSide || side == ColumnEndSide) ? GridPositionsRes olver::explicitGridColumnCount(gridContainerStyle) : GridPositionsResolver::expl icitGridRowCount(gridContainerStyle); | 136 return (side == ColumnStartSide || side == ColumnEndSide) ? GridPositionsRes olver::explicitGridColumnCount(gridContainerStyle) : GridPositionsResolver::expl icitGridRowCount(gridContainerStyle); |
137 } | 137 } |
138 | 138 |
139 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition(const Comput edStyle& gridContainerStyle, int resolvedOppositePosition, const GridPosition& p osition, GridPositionSide side) | 139 static GridSpan resolveNamedGridLinePositionAgainstOppositePosition(const Comput edStyle& gridContainerStyle, int opossiteLine, const GridPosition& position, Gri dPositionSide side) |
140 { | 140 { |
141 ASSERT(position.isSpan()); | 141 ASSERT(position.isSpan()); |
142 ASSERT(!position.namedGridLine().isNull()); | 142 ASSERT(!position.namedGridLine().isNull()); |
143 // Negative positions are not allowed per the specification and should have been handled during parsing. | 143 // Negative positions are not allowed per the specification and should have been handled during parsing. |
144 ASSERT(position.spanPosition() > 0); | 144 ASSERT(position.spanPosition() > 0); |
145 | 145 |
146 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl e, side); | 146 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl e, side); |
147 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); | 147 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); |
148 const Vector<size_t>* gridLines = it == gridLinesNames.end() ? nullptr : &it ->value; | 148 const Vector<size_t>* gridLines = it == gridLinesNames.end() ? nullptr : &it ->value; |
149 size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side); | 149 size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side); |
150 return definiteGridSpanWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, gridLines, lastLine); | 150 return definiteGridSpanWithNamedSpanAgainstOpposite(opossiteLine, position, side, gridLines, lastLine); |
151 } | 151 } |
152 | 152 |
153 static GridSpan definiteGridSpanWithSpanAgainstOpposite(size_t resolvedOppositeP osition, const GridPosition& position, GridPositionSide side) | 153 static GridSpan definiteGridSpanWithSpanAgainstOpposite(size_t opossiteLine, con st GridPosition& position, GridPositionSide side) |
svillar
2016/03/17 13:21:51
Not directly related with the patch but why are we
Manuel Rego
2016/03/17 15:02:05
Yep, you're right, this is wrong.
It's working fin
| |
154 { | 154 { |
155 size_t positionOffset = position.spanPosition(); | 155 size_t positionOffset = position.spanPosition(); |
156 if (side == ColumnStartSide || side == RowStartSide) | 156 if (side == ColumnStartSide || side == RowStartSide) |
157 return GridSpan::untranslatedDefiniteGridSpan(resolvedOppositePosition - positionOffset, resolvedOppositePosition); | 157 return GridSpan::untranslatedDefiniteGridSpan(opossiteLine - positionOff set, opossiteLine); |
158 | 158 |
159 return GridSpan::untranslatedDefiniteGridSpan(resolvedOppositePosition, reso lvedOppositePosition + positionOffset); | 159 return GridSpan::untranslatedDefiniteGridSpan(opossiteLine, opossiteLine + p ositionOffset); |
160 } | 160 } |
161 | 161 |
162 static GridSpan resolveGridPositionAgainstOppositePosition(const ComputedStyle& gridContainerStyle, int resolvedOppositePosition, const GridPosition& position, GridPositionSide side) | 162 static GridSpan resolveGridPositionAgainstOppositePosition(const ComputedStyle& gridContainerStyle, int opossiteLine, const GridPosition& position, GridPosition Side side) |
163 { | 163 { |
164 if (position.isAuto()) { | 164 if (position.isAuto()) { |
165 if (side == ColumnStartSide || side == RowStartSide) | 165 if (side == ColumnStartSide || side == RowStartSide) |
166 return GridSpan::untranslatedDefiniteGridSpan(resolvedOppositePositi on - 1, resolvedOppositePosition); | 166 return GridSpan::untranslatedDefiniteGridSpan(opossiteLine - 1, opos siteLine); |
167 return GridSpan::untranslatedDefiniteGridSpan(resolvedOppositePosition, resolvedOppositePosition + 1); | 167 return GridSpan::untranslatedDefiniteGridSpan(opossiteLine, opossiteLine + 1); |
168 } | 168 } |
169 | 169 |
170 ASSERT(position.isSpan()); | 170 ASSERT(position.isSpan()); |
171 ASSERT(position.spanPosition() > 0); | 171 ASSERT(position.spanPosition() > 0); |
172 | 172 |
173 if (!position.namedGridLine().isNull()) { | 173 if (!position.namedGridLine().isNull()) { |
174 // span 2 'c' -> we need to find the appropriate grid line before / afte r our opposite position. | 174 // span 2 'c' -> we need to find the appropriate grid line before / afte r our opposite position. |
175 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer Style, resolvedOppositePosition, position, side); | 175 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer Style, opossiteLine, position, side); |
176 } | 176 } |
177 | 177 |
178 return definiteGridSpanWithSpanAgainstOpposite(resolvedOppositePosition, pos ition, side); | 178 return definiteGridSpanWithSpanAgainstOpposite(opossiteLine, position, side) ; |
179 } | 179 } |
180 | 180 |
181 size_t GridPositionsResolver::spanSizeForAutoPlacedItem(const ComputedStyle& gri dContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direction) | 181 size_t GridPositionsResolver::spanSizeForAutoPlacedItem(const ComputedStyle& gri dContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direction) |
182 { | 182 { |
183 GridPosition initialPosition, finalPosition; | 183 GridPosition initialPosition, finalPosition; |
184 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition); | 184 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition); |
185 | 185 |
186 // This method will only be used when both positions need to be resolved aga inst the opposite one. | 186 // This method will only be used when both positions need to be resolved aga inst the opposite one. |
187 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos ition.shouldBeResolvedAgainstOppositePosition()); | 187 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos ition.shouldBeResolvedAgainstOppositePosition()); |
188 | 188 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 GridPositionSide initialSide = initialPositionSide(direction); | 269 GridPositionSide initialSide = initialPositionSide(direction); |
270 GridPositionSide finalSide = finalPositionSide(direction); | 270 GridPositionSide finalSide = finalPositionSide(direction); |
271 | 271 |
272 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { | 272 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { |
273 // We can't get our grid positions without running the auto placement al gorithm. | 273 // We can't get our grid positions without running the auto placement al gorithm. |
274 return GridSpan::indefiniteGridSpan(); | 274 return GridSpan::indefiniteGridSpan(); |
275 } | 275 } |
276 | 276 |
277 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 277 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
278 // Infer the position from the final position ('auto / 1' or 'span 2 / 3 ' case). | 278 // Infer the position from the final position ('auto / 1' or 'span 2 / 3 ' case). |
279 int finalResolvedPosition = resolveGridPositionFromStyle(gridContainerSt yle, finalPosition, finalSide); | 279 int endLine = resolveGridPositionFromStyle(gridContainerStyle, finalPosi tion, finalSide); |
280 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi nalResolvedPosition, initialPosition, initialSide); | 280 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, en dLine, initialPosition, initialSide); |
281 } | 281 } |
282 | 282 |
283 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { | 283 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { |
284 // Infer our position from the initial position ('1 / auto' or '3 / span 2' case). | 284 // Infer our position from the initial position ('1 / auto' or '3 / span 2' case). |
285 int initialResolvedPosition = resolveGridPositionFromStyle(gridContainer Style, initialPosition, initialSide); | 285 int startLine = resolveGridPositionFromStyle(gridContainerStyle, initial Position, initialSide); |
286 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in itialResolvedPosition, finalPosition, finalSide); | 286 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, st artLine, finalPosition, finalSide); |
287 } | 287 } |
288 | 288 |
289 int resolvedInitialPosition = resolveGridPositionFromStyle(gridContainerStyl e, initialPosition, initialSide); | 289 int startLine = resolveGridPositionFromStyle(gridContainerStyle, initialPosi tion, initialSide); |
290 int resolvedFinalPosition = resolveGridPositionFromStyle(gridContainerStyle, finalPosition, finalSide); | 290 int endLine = resolveGridPositionFromStyle(gridContainerStyle, finalPosition , finalSide); |
291 | 291 |
292 if (resolvedFinalPosition < resolvedInitialPosition) | 292 if (endLine < startLine) |
293 std::swap(resolvedFinalPosition, resolvedInitialPosition); | 293 std::swap(endLine, startLine); |
294 else if (resolvedFinalPosition == resolvedInitialPosition) | 294 else if (endLine == startLine) |
295 resolvedFinalPosition = resolvedInitialPosition + 1; | 295 endLine = startLine + 1; |
296 | 296 |
297 return GridSpan::untranslatedDefiniteGridSpan(resolvedInitialPosition, resol vedFinalPosition); | 297 return GridSpan::untranslatedDefiniteGridSpan(startLine, endLine); |
298 } | 298 } |
299 | 299 |
300 } // namespace blink | 300 } // namespace blink |
OLD | NEW |