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/rendering/style/GridResolvedPosition.h" | 6 #include "core/rendering/style/GridResolvedPosition.h" |
7 | 7 |
8 #include "core/rendering/RenderBox.h" | 8 #include "core/rendering/RenderBox.h" |
9 #include "core/rendering/style/GridCoordinate.h" | 9 #include "core/rendering/style/GridCoordinate.h" |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 size_t GridResolvedPosition::explicitGridRowCount(const RenderStyle& gridContain erStyle) | 73 size_t GridResolvedPosition::explicitGridRowCount(const RenderStyle& gridContain erStyle) |
74 { | 74 { |
75 return gridContainerStyle.gridTemplateRows().size(); | 75 return gridContainerStyle.gridTemplateRows().size(); |
76 } | 76 } |
77 | 77 |
78 size_t GridResolvedPosition::explicitGridSizeForSide(const RenderStyle& gridCont ainerStyle, GridPositionSide side) | 78 size_t GridResolvedPosition::explicitGridSizeForSide(const RenderStyle& gridCont ainerStyle, GridPositionSide side) |
79 { | 79 { |
80 return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColu mnCount(gridContainerStyle) : explicitGridRowCount(gridContainerStyle); | 80 return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColu mnCount(gridContainerStyle) : explicitGridRowCount(gridContainerStyle); |
81 } | 81 } |
82 | 82 |
83 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP ositionSide side) | |
84 { | |
85 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC olumnLines() : style.namedGridRowLines(); | |
86 } | |
87 | |
83 GridResolvedPosition GridResolvedPosition::resolveNamedGridLinePositionFromStyle (const RenderStyle& gridContainerStyle, const GridPosition& position, GridPositi onSide side) | 88 GridResolvedPosition GridResolvedPosition::resolveNamedGridLinePositionFromStyle (const RenderStyle& gridContainerStyle, const GridPosition& position, GridPositi onSide side) |
84 { | 89 { |
85 ASSERT(!position.namedGridLine().isNull()); | 90 ASSERT(!position.namedGridLine().isNull()); |
86 | 91 |
87 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side = = ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyl e.namedGridRowLines(); | 92 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl e, side); |
88 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); | 93 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); |
89 if (it == gridLinesNames.end()) { | 94 if (it == gridLinesNames.end()) { |
90 if (position.isPositive()) | 95 if (position.isPositive()) |
91 return GridResolvedPosition(0); | 96 return GridResolvedPosition(0); |
92 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side ); | 97 const size_t lastLine = explicitGridSizeForSide(gridContainerStyle, side ); |
93 return adjustGridPositionForSide(lastLine, side); | 98 return adjustGridPositionForSide(lastLine, side); |
94 } | 99 } |
95 | 100 |
96 size_t namedGridLineIndex; | 101 size_t namedGridLineIndex; |
97 if (position.isPositive()) | 102 if (position.isPositive()) |
(...skipping 20 matching lines...) Expand all Loading... | |
118 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si de); | 123 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si de); |
119 | 124 |
120 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html, we clamp negative value to the first line. | 125 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html, we clamp negative value to the first line. |
121 if (endOfTrack < resolvedPosition) | 126 if (endOfTrack < resolvedPosition) |
122 return GridResolvedPosition(0); | 127 return GridResolvedPosition(0); |
123 | 128 |
124 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); | 129 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); |
125 } | 130 } |
126 case NamedGridAreaPosition: | 131 case NamedGridAreaPosition: |
127 { | 132 { |
128 NamedGridAreaMap::const_iterator it = gridContainerStyle.namedGridArea() .find(position.namedGridLine()); | 133 // Four implicit named grid lines are created for each grid area (areaNa me-{start|end} for rows and |
129 // Unknown grid area should have been computed to 'auto' by now. | 134 // columns). Authors can either use the area names or the implicit grid line names. |
130 ASSERT_WITH_SECURITY_IMPLICATION(it != gridContainerStyle.namedGridArea( ).end()); | 135 String namedGridLine = position.namedGridLine(); |
131 const GridCoordinate& gridAreaCoordinate = it->value; | 136 String implicitNamedGridLine = namedGridLine + ((side == ColumnStartSide || side == RowStartSide) ? "-start" : "-end"); |
132 switch (side) { | 137 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS tyle, side); |
133 case ColumnStartSide: | 138 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find( implicitNamedGridLine); |
134 return gridAreaCoordinate.columns.resolvedInitialPosition; | 139 if (implicitLineIter != gridLineNames.end()) |
135 case ColumnEndSide: | 140 return adjustGridPositionForSide(implicitLineIter->value[0], side); |
136 return gridAreaCoordinate.columns.resolvedFinalPosition; | 141 |
137 case RowStartSide: | 142 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find( namedGridLine); |
Julien - ping for review
2014/05/12 11:42:12
Nit: I would put the specification's wording with
| |
138 return gridAreaCoordinate.rows.resolvedInitialPosition; | 143 if (explicitLineIter != gridLineNames.end()) |
139 case RowEndSide: | 144 return adjustGridPositionForSide(explicitLineIter->value[0], side); |
140 return GridResolvedPosition(gridAreaCoordinate.rows.resolvedFinalPos ition); | 145 |
141 } | 146 // FIXME: if none of the above works specs mandate us to treat it as aut o. We cannot return auto right here |
142 ASSERT_NOT_REACHED(); | 147 // right now because callers expect a resolved position. We need deeper changes to support this use case. |
143 return GridResolvedPosition(0); | 148 return GridResolvedPosition(0); |
144 } | 149 } |
145 case AutoPosition: | 150 case AutoPosition: |
146 case SpanPosition: | 151 case SpanPosition: |
147 // 'auto' and span depend on the opposite position for resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / "myHeader"). | 152 // 'auto' and span depend on the opposite position for resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / "myHeader"). |
148 ASSERT_NOT_REACHED(); | 153 ASSERT_NOT_REACHED(); |
149 return GridResolvedPosition(0); | 154 return GridResolvedPosition(0); |
150 } | 155 } |
151 ASSERT_NOT_REACHED(); | 156 ASSERT_NOT_REACHED(); |
152 return GridResolvedPosition(0); | 157 return GridResolvedPosition(0); |
(...skipping 15 matching lines...) Expand all Loading... | |
168 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos ition, side); | 173 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos ition, side); |
169 } | 174 } |
170 | 175 |
171 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition & resolvedOppositePosition, const GridPosition& position, GridPositionSide side) | 176 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition & resolvedOppositePosition, const GridPosition& position, GridPositionSide side) |
172 { | 177 { |
173 ASSERT(position.isSpan()); | 178 ASSERT(position.isSpan()); |
174 ASSERT(!position.namedGridLine().isNull()); | 179 ASSERT(!position.namedGridLine().isNull()); |
175 // Negative positions are not allowed per the specification and should have been handled during parsing. | 180 // Negative positions are not allowed per the specification and should have been handled during parsing. |
176 ASSERT(position.spanPosition() > 0); | 181 ASSERT(position.spanPosition() > 0); |
177 | 182 |
178 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side = = ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyl e.namedGridRowLines(); | 183 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl e, side); |
179 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); | 184 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); |
180 | 185 |
181 // 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). | 186 // 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). |
182 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 187 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
183 if (it == gridLinesNames.end()) | 188 if (it == gridLinesNames.end()) |
184 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); | 189 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); |
185 | 190 |
186 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); | 191 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); |
187 } | 192 } |
188 | 193 |
189 } // namespace WebCore | 194 } // namespace WebCore |
OLD | NEW |