| 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 |
| 11 namespace WebCore { | 11 namespace WebCore { |
| 12 | 12 |
| 13 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP
ositionSide side) | 13 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP
ositionSide side) |
| 14 { | 14 { |
| 15 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC
olumnLines() : style.namedGridRowLines(); | 15 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC
olumnLines() : style.namedGridRowLines(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 static inline bool isNonExistentNamedLineOrArea(const String& lineName, const Re
nderStyle& style, GridPositionSide side) | 18 static inline String implicitNamedGridLineForSide(const String& lineName, GridPo
sitionSide side) |
| 19 { | 19 { |
| 20 return !style.namedGridArea().contains(lineName) && !gridLinesForSide(style,
side).contains(lineName); | 20 return lineName + ((side == ColumnStartSide || side == RowStartSide) ? "-sta
rt" : "-end"); |
| 21 } |
| 22 |
| 23 static bool isValidNamedLineOrArea(const String& lineName, const RenderStyle& st
yle, GridPositionSide side) |
| 24 { |
| 25 const NamedGridLinesMap& gridLineNames = gridLinesForSide(style, side); |
| 26 |
| 27 return gridLineNames.contains(implicitNamedGridLineForSide(lineName, side))
|| gridLineNames.contains(lineName); |
| 21 } | 28 } |
| 22 | 29 |
| 23 static GridPositionSide calculateInitialPositionSide(GridTrackSizingDirection di
rection) | 30 static GridPositionSide calculateInitialPositionSide(GridTrackSizingDirection di
rection) |
| 24 { | 31 { |
| 25 return (direction == ForColumns) ? ColumnStartSide : RowStartSide; | 32 return (direction == ForColumns) ? ColumnStartSide : RowStartSide; |
| 26 } | 33 } |
| 27 | 34 |
| 28 static GridPositionSide calculateFinalPositionSide(GridTrackSizingDirection dire
ction) | 35 static GridPositionSide calculateFinalPositionSide(GridTrackSizingDirection dire
ction) |
| 29 { | 36 { |
| 30 return (direction == ForColumns) ? ColumnEndSide : RowEndSide; | 37 return (direction == ForColumns) ? ColumnEndSide : RowEndSide; |
| 31 } | 38 } |
| 32 | 39 |
| 33 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle&
gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection directio
n, GridPosition& initialPosition, GridPosition& finalPosition) | 40 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle&
gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection directio
n, GridPosition& initialPosition, GridPosition& finalPosition) |
| 34 { | 41 { |
| 35 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt
art() : gridItem.style()->gridRowStart(); | 42 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt
art() : gridItem.style()->gridRowStart(); |
| 36 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd(
) : gridItem.style()->gridRowEnd(); | 43 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd(
) : gridItem.style()->gridRowEnd(); |
| 37 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio
n); | 44 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio
n); |
| 38 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); | 45 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); |
| 39 | 46 |
| 40 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to | 47 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to |
| 41 // overwrite the specified values. | 48 // overwrite the specified values. |
| 42 if (initialPosition.isSpan() && finalPosition.isSpan()) | 49 if (initialPosition.isSpan() && finalPosition.isSpan()) |
| 43 finalPosition.setAutoPosition(); | 50 finalPosition.setAutoPosition(); |
| 44 | 51 |
| 45 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia
lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) | 52 // Try to early detect the case of non existing named grid lines. This way w
e could assume later that |
| 53 // GridResolvedPosition::resolveGrisPositionFromStyle() always return a vali
d resolved position. |
| 54 if (initialPosition.isNamedGridArea() && !isValidNamedLineOrArea(initialPosi
tion.namedGridLine(), gridContainerStyle, initialPositionSide)) |
| 46 initialPosition.setAutoPosition(); | 55 initialPosition.setAutoPosition(); |
| 47 | 56 |
| 48 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos
ition.namedGridLine(), gridContainerStyle, finalPositionSide)) | 57 if (finalPosition.isNamedGridArea() && !isValidNamedLineOrArea(finalPosition
.namedGridLine(), gridContainerStyle, finalPositionSide)) |
| 49 finalPosition.setAutoPosition(); | 58 finalPosition.setAutoPosition(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDi
rection direction, const GridResolvedPosition& resolvedInitialPosition) | 61 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDi
rection direction, const GridResolvedPosition& resolvedInitialPosition) |
| 53 { | 62 { |
| 54 GridPosition initialPosition, finalPosition; | 63 GridPosition initialPosition, finalPosition; |
| 55 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); | 64 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 56 | 65 |
| 57 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); | 66 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); |
| 58 | 67 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return GridResolvedPosition(0); | 174 return GridResolvedPosition(0); |
| 166 | 175 |
| 167 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); | 176 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); |
| 168 } | 177 } |
| 169 case NamedGridAreaPosition: | 178 case NamedGridAreaPosition: |
| 170 { | 179 { |
| 171 // First attempt to match the grid area’s edge to a named grid area: if
there is a named line with the name | 180 // First attempt to match the grid area’s edge to a named grid area: if
there is a named line with the name |
| 172 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such | 181 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for
grid-*-end), contributes the first such |
| 173 // line to the grid item’s placement. | 182 // line to the grid item’s placement. |
| 174 String namedGridLine = position.namedGridLine(); | 183 String namedGridLine = position.namedGridLine(); |
| 175 String implicitNamedGridLine = namedGridLine + ((side == ColumnStartSide
|| side == RowStartSide) ? "-start" : "-end"); | 184 ASSERT(isValidNamedLineOrArea(namedGridLine, gridContainerStyle, side)); |
| 185 |
| 176 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); | 186 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS
tyle, side); |
| 177 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLine); | 187 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(
implicitNamedGridLineForSide(namedGridLine, side)); |
| 178 if (implicitLineIter != gridLineNames.end()) | 188 if (implicitLineIter != gridLineNames.end()) |
| 179 return adjustGridPositionForSide(implicitLineIter->value[0], side); | 189 return adjustGridPositionForSide(implicitLineIter->value[0], side); |
| 180 | 190 |
| 181 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid | 191 // Otherwise, if there is a named line with the specified name, contribu
tes the first such line to the grid |
| 182 // item’s placement. | 192 // item’s placement. |
| 183 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); | 193 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(
namedGridLine); |
| 184 if (explicitLineIter != gridLineNames.end()) | 194 if (explicitLineIter != gridLineNames.end()) |
| 185 return adjustGridPositionForSide(explicitLineIter->value[0], side); | 195 return adjustGridPositionForSide(explicitLineIter->value[0], side); |
| 186 | 196 |
| 187 // FIXME: if none of the above works specs mandate us to treat it as aut
o. We cannot return auto right here | 197 // If none of the above works specs mandate us to treat it as auto BUT w
e should have detected it before calling |
| 188 // right now because callers expect a resolved position. We need deeper
changes to support this use case. | 198 // this function in GridResolvedPosition::resolveGridPositionsFromStyle(
). We should be also covered by the |
| 199 // ASSERT at the beginning of this block. |
| 200 ASSERT_NOT_REACHED(); |
| 189 return GridResolvedPosition(0); | 201 return GridResolvedPosition(0); |
| 190 } | 202 } |
| 191 case AutoPosition: | 203 case AutoPosition: |
| 192 case SpanPosition: | 204 case SpanPosition: |
| 193 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). | 205 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). |
| 194 ASSERT_NOT_REACHED(); | 206 ASSERT_NOT_REACHED(); |
| 195 return GridResolvedPosition(0); | 207 return GridResolvedPosition(0); |
| 196 } | 208 } |
| 197 ASSERT_NOT_REACHED(); | 209 ASSERT_NOT_REACHED(); |
| 198 return GridResolvedPosition(0); | 210 return GridResolvedPosition(0); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 226 | 238 |
| 227 // 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). | 239 // 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). |
| 228 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 240 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 229 if (it == gridLinesNames.end()) | 241 if (it == gridLinesNames.end()) |
| 230 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 242 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
| 231 | 243 |
| 232 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 244 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 233 } | 245 } |
| 234 | 246 |
| 235 } // namespace WebCore | 247 } // namespace WebCore |
| OLD | NEW |