Chromium Code Reviews| 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()) |
| 98 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va lue.size()) - 1; | 103 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va lue.size()) - 1; |
| 99 else | 104 else |
| 100 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ erPosition()), 0); | 105 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ erPosition()), 0); |
| 101 return adjustGridPositionForSide(it->value[namedGridLineIndex], side); | 106 return adjustGridPositionForSide(it->value[namedGridLineIndex], side); |
| 102 } | 107 } |
| 103 | 108 |
| 109 GridResolvedPosition GridResolvedPosition::resolveExplicitPositionFromStyle(cons t RenderStyle& gridContainerStyle, const GridPosition& position, GridPositionSid e side) | |
| 110 { | |
| 111 ASSERT(position.integerPosition()); | |
| 112 | |
| 113 if (!position.namedGridLine().isNull()) | |
| 114 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, positio n, side); | |
| 115 | |
| 116 if (position.isPositive()) | |
| 117 return adjustGridPositionForSide(position.integerPosition() - 1, side); | |
| 118 | |
| 119 size_t resolvedPosition = abs(position.integerPosition()) - 1; | |
| 120 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, side); | |
| 121 | |
| 122 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html, we c lamp negative value to the first line. | |
| 123 if (endOfTrack < resolvedPosition) | |
| 124 return 0; | |
| 125 | |
| 126 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); | |
| 127 } | |
| 128 | |
| 104 GridResolvedPosition GridResolvedPosition::resolveGridPositionFromStyle(const Re nderStyle& gridContainerStyle, const GridPosition& position, GridPositionSide si de) | 129 GridResolvedPosition GridResolvedPosition::resolveGridPositionFromStyle(const Re nderStyle& gridContainerStyle, const GridPosition& position, GridPositionSide si de) |
| 105 { | 130 { |
| 106 switch (position.type()) { | 131 // We shouldn't see any other type of position here because 'auto' and span depend on the opposite position for |
| 107 case ExplicitPosition: { | 132 // resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / myHeader). |
| 108 ASSERT(position.integerPosition()); | 133 ASSERT(position.type() == NamedGridAreaPosition || position.type() == Explic itPosition); |
| 109 | 134 |
| 110 if (!position.namedGridLine().isNull()) | 135 if (position.type() == NamedGridAreaPosition) { |
| 111 return resolveNamedGridLinePositionFromStyle(gridContainerStyle, pos ition, side); | 136 // Four implicit named grid lines are created for each grid area (areaNa me-{start|end} for rows and |
| 137 // columns). Authors can either use the area names or the implicit grid line names. | |
| 138 NamedGridAreaMap::const_iterator areaIter = gridContainerStyle.namedGrid Area().find(position.namedGridLine()); | |
|
Julien - ping for review
2014/05/08 18:48:05
I think this should be a FIXME: if we inserted gri
svillar
2014/05/09 11:14:39
I quite don't get this comment. We *do* insert gri
Julien - ping for review
2014/05/09 17:37:54
OK, I missed that important piece of information.
| |
| 139 if (areaIter != gridContainerStyle.namedGridArea().end()) { | |
| 140 String implicitNamedGridLine = position.namedGridLine() + ((side == ColumnStartSide || side == RowStartSide) ? "-start" : "-end"); | |
| 141 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContai nerStyle, side); | |
| 142 NamedGridLinesMap::const_iterator lineIter = gridLineNames.find(impl icitNamedGridLine); | |
| 112 | 143 |
| 113 // Handle <integer> explicit position. | 144 if (lineIter != gridLineNames.end()) |
| 114 if (position.isPositive()) | 145 return adjustGridPositionForSide(lineIter->value[0], side); |
|
Julien - ping for review
2014/05/08 18:48:05
Shouldn't we pick the smallest between the grid-ar
svillar
2014/05/09 11:14:39
Indeed that's a bug
svillar
2014/05/09 14:40:14
Errr, no the code is correct. The reason why is co
Julien - ping for review
2014/05/09 17:37:54
I agree. Sorry for the noise.
| |
| 115 return adjustGridPositionForSide(position.integerPosition() - 1, sid e); | |
| 116 | 146 |
| 117 size_t resolvedPosition = abs(position.integerPosition()) - 1; | 147 return areaIter->value.positionForSide(side); |
| 118 const size_t endOfTrack = explicitGridSizeForSide(gridContainerStyle, si de); | 148 } |
| 149 // Fallback to a implicit grid line position if there is no grid area wi th that name. | |
| 150 GridPosition adjustedPosition; | |
| 151 adjustedPosition.setExplicitPosition(1, position.namedGridLine()); | |
| 152 return resolveExplicitPositionFromStyle(gridContainerStyle, adjustedPosi tion, side); | |
|
Julien - ping for review
2014/05/08 18:48:05
Why do we need to override the integer position? T
svillar
2014/05/09 11:14:39
We're converting a NamedGridAreaPosition into a ex
| |
| 153 } | |
| 119 | 154 |
|
Julien - ping for review
2014/05/08 18:48:05
I think we should check for the named grid line in
svillar
2014/05/09 11:14:39
Again, resolveExplicitPositionFromStyle() calls re
svillar
2014/05/09 11:14:39
Same comment as above we handle that case in resol
| |
| 120 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html, we clamp negative value to the first line. | 155 return resolveExplicitPositionFromStyle(gridContainerStyle, position, side); |
| 121 if (endOfTrack < resolvedPosition) | |
| 122 return GridResolvedPosition(0); | |
| 123 | |
| 124 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); | |
| 125 } | |
| 126 case NamedGridAreaPosition: | |
| 127 { | |
| 128 NamedGridAreaMap::const_iterator it = gridContainerStyle.namedGridArea() .find(position.namedGridLine()); | |
| 129 // Unknown grid area should have been computed to 'auto' by now. | |
| 130 ASSERT_WITH_SECURITY_IMPLICATION(it != gridContainerStyle.namedGridArea( ).end()); | |
| 131 const GridCoordinate& gridAreaCoordinate = it->value; | |
| 132 switch (side) { | |
| 133 case ColumnStartSide: | |
| 134 return gridAreaCoordinate.columns.resolvedInitialPosition; | |
| 135 case ColumnEndSide: | |
| 136 return gridAreaCoordinate.columns.resolvedFinalPosition; | |
| 137 case RowStartSide: | |
| 138 return gridAreaCoordinate.rows.resolvedInitialPosition; | |
| 139 case RowEndSide: | |
| 140 return GridResolvedPosition(gridAreaCoordinate.rows.resolvedFinalPos ition); | |
| 141 } | |
| 142 ASSERT_NOT_REACHED(); | |
| 143 return GridResolvedPosition(0); | |
| 144 } | |
| 145 case AutoPosition: | |
| 146 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"). | |
| 148 ASSERT_NOT_REACHED(); | |
| 149 return GridResolvedPosition(0); | |
| 150 } | |
| 151 ASSERT_NOT_REACHED(); | |
| 152 return GridResolvedPosition(0); | |
| 153 } | 156 } |
| 154 | 157 |
| 155 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePos ition(const RenderStyle& gridContainerStyle, const GridResolvedPosition& resolve dOppositePosition, const GridPosition& position, GridPositionSide side) | 158 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionAgainstOppositePos ition(const RenderStyle& gridContainerStyle, const GridResolvedPosition& resolve dOppositePosition, const GridPosition& position, GridPositionSide side) |
| 156 { | 159 { |
| 157 if (position.isAuto()) | 160 if (position.isAuto()) |
| 158 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); | 161 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); |
| 159 | 162 |
| 160 ASSERT(position.isSpan()); | 163 ASSERT(position.isSpan()); |
| 161 ASSERT(position.spanPosition() > 0); | 164 ASSERT(position.spanPosition() > 0); |
| 162 | 165 |
| 163 if (!position.namedGridLine().isNull()) { | 166 if (!position.namedGridLine().isNull()) { |
| 164 // span 2 'c' -> we need to find the appropriate grid line before / afte r our opposite position. | 167 // span 2 'c' -> we need to find the appropriate grid line before / afte r our opposite position. |
| 165 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer Style, resolvedOppositePosition, position, side); | 168 return resolveNamedGridLinePositionAgainstOppositePosition(gridContainer Style, resolvedOppositePosition, position, side); |
| 166 } | 169 } |
| 167 | 170 |
| 168 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos ition, side); | 171 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos ition, side); |
| 169 } | 172 } |
| 170 | 173 |
| 171 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition & resolvedOppositePosition, const GridPosition& position, GridPositionSide side) | 174 PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp positePosition(const RenderStyle& gridContainerStyle, const GridResolvedPosition & resolvedOppositePosition, const GridPosition& position, GridPositionSide side) |
| 172 { | 175 { |
| 173 ASSERT(position.isSpan()); | 176 ASSERT(position.isSpan()); |
| 174 ASSERT(!position.namedGridLine().isNull()); | 177 ASSERT(!position.namedGridLine().isNull()); |
| 175 // Negative positions are not allowed per the specification and should have been handled during parsing. | 178 // Negative positions are not allowed per the specification and should have been handled during parsing. |
| 176 ASSERT(position.spanPosition() > 0); | 179 ASSERT(position.spanPosition() > 0); |
| 177 | 180 |
| 178 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side = = ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyl e.namedGridRowLines(); | 181 const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyl e, side); |
| 179 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); | 182 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri dLine()); |
| 180 | 183 |
| 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). | 184 // 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. | 185 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 183 if (it == gridLinesNames.end()) | 186 if (it == gridLinesNames.end()) |
| 184 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); | 187 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); |
| 185 | 188 |
| 186 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); | 189 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace WebCore | 192 } // namespace WebCore |
| OLD | NEW |