| 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 // First attempt to match the grid area’s edge to a named grid area: if
there is a named line with the name |
| 129 // Unknown grid area should have been computed to 'auto' by now. | 134 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such |
| 130 ASSERT_WITH_SECURITY_IMPLICATION(it != gridContainerStyle.namedGridArea(
).end()); | 135 // line to the grid item’s placement. |
| 131 const GridCoordinate& gridAreaCoordinate = it->value; | 136 String namedGridLine = position.namedGridLine(); |
| 132 switch (side) { | 137 String implicitNamedGridLine = namedGridLine + ((side == ColumnStartSide
|| side == RowStartSide) ? "-start" : "-end"); |
| 133 case ColumnStartSide: | 138 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); |
| 134 return gridAreaCoordinate.columns.resolvedInitialPosition; | 139 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLine); |
| 135 case ColumnEndSide: | 140 if (implicitLineIter != gridLineNames.end()) |
| 136 return gridAreaCoordinate.columns.resolvedFinalPosition; | 141 return adjustGridPositionForSide(implicitLineIter->value[0], side); |
| 137 case RowStartSide: | 142 |
| 138 return gridAreaCoordinate.rows.resolvedInitialPosition; | 143 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid |
| 139 case RowEndSide: | 144 // item’s placement. |
| 140 return GridResolvedPosition(gridAreaCoordinate.rows.resolvedFinalPos
ition); | 145 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); |
| 141 } | 146 if (explicitLineIter != gridLineNames.end()) |
| 142 ASSERT_NOT_REACHED(); | 147 return adjustGridPositionForSide(explicitLineIter->value[0], side); |
| 148 |
| 149 // FIXME: if none of the above works specs mandate us to treat it as aut
o. We cannot return auto right here |
| 150 // right now because callers expect a resolved position. We need deeper
changes to support this use case. |
| 143 return GridResolvedPosition(0); | 151 return GridResolvedPosition(0); |
| 144 } | 152 } |
| 145 case AutoPosition: | 153 case AutoPosition: |
| 146 case SpanPosition: | 154 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"). | 155 // '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(); | 156 ASSERT_NOT_REACHED(); |
| 149 return GridResolvedPosition(0); | 157 return GridResolvedPosition(0); |
| 150 } | 158 } |
| 151 ASSERT_NOT_REACHED(); | 159 ASSERT_NOT_REACHED(); |
| 152 return GridResolvedPosition(0); | 160 return GridResolvedPosition(0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 168 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); | 176 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); |
| 169 } | 177 } |
| 170 | 178 |
| 171 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition
& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) | 179 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition
& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) |
| 172 { | 180 { |
| 173 ASSERT(position.isSpan()); | 181 ASSERT(position.isSpan()); |
| 174 ASSERT(!position.namedGridLine().isNull()); | 182 ASSERT(!position.namedGridLine().isNull()); |
| 175 // Negative positions are not allowed per the specification and should have
been handled during parsing. | 183 // Negative positions are not allowed per the specification and should have
been handled during parsing. |
| 176 ASSERT(position.spanPosition() > 0); | 184 ASSERT(position.spanPosition() > 0); |
| 177 | 185 |
| 178 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side =
= ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyl
e.namedGridRowLines(); | 186 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl
e, side); |
| 179 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 187 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 180 | 188 |
| 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). | 189 // 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. | 190 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 183 if (it == gridLinesNames.end()) | 191 if (it == gridLinesNames.end()) |
| 184 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 192 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
| 185 | 193 |
| 186 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 194 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 187 } | 195 } |
| 188 | 196 |
| 189 } // namespace WebCore | 197 } // namespace WebCore |
| OLD | NEW |