| 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 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st RenderBox&, GridTrackSizingDirection, const GridResolvedPosition& initialPosi
tion) | |
| 14 { | |
| 15 // FIXME: We don't support spanning with auto positions yet. Once we do, thi
s is wrong. Also we should make | |
| 16 // sure the grid can accomodate the new item as we only grow 1 position in a
given direction. | |
| 17 return GridSpan(initialPosition, initialPosition); | |
| 18 } | |
| 19 | |
| 20 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP
ositionSide side) | 13 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP
ositionSide side) |
| 21 { | 14 { |
| 22 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC
olumnLines() : style.namedGridRowLines(); | 15 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC
olumnLines() : style.namedGridRowLines(); |
| 23 } | 16 } |
| 24 | 17 |
| 25 static inline bool isNonExistentNamedLineOrArea(const String& lineName, const Re
nderStyle& style, GridPositionSide side) | 18 static inline bool isNonExistentNamedLineOrArea(const String& lineName, const Re
nderStyle& style, GridPositionSide side) |
| 26 { | 19 { |
| 27 return !style.namedGridArea().contains(lineName) && !gridLinesForSide(style,
side).contains(lineName); | 20 return !style.namedGridArea().contains(lineName) && !gridLinesForSide(style,
side).contains(lineName); |
| 28 } | 21 } |
| 29 | 22 |
| 30 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R
enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect
ion direction) | 23 static GridPositionSide calculateInitialPositionSide(GridTrackSizingDirection di
rection) |
| 31 { | 24 { |
| 32 GridPosition initialPosition = (direction == ForColumns) ? gridItem.style()-
>gridColumnStart() : gridItem.style()->gridRowStart(); | 25 return (direction == ForColumns) ? ColumnStartSide : RowStartSide; |
| 33 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col
umnStartSide : RowStartSide; | 26 } |
| 34 GridPosition finalPosition = (direction == ForColumns) ? gridItem.style()->g
ridColumnEnd() : gridItem.style()->gridRowEnd(); | 27 |
| 35 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum
nEndSide : RowEndSide; | 28 static GridPositionSide calculateFinalPositionSide(GridTrackSizingDirection dire
ction) |
| 29 { |
| 30 return (direction == ForColumns) ? ColumnEndSide : RowEndSide; |
| 31 } |
| 32 |
| 33 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle&
gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection directio
n, GridPosition& initialPosition, GridPosition& finalPosition) |
| 34 { |
| 35 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt
art() : gridItem.style()->gridRowStart(); |
| 36 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd(
) : gridItem.style()->gridRowEnd(); |
| 37 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio
n); |
| 38 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); |
| 36 | 39 |
| 37 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to | 40 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to |
| 38 // overwrite the specified values. | 41 // overwrite the specified values. |
| 39 if (initialPosition.isSpan() && finalPosition.isSpan()) | 42 if (initialPosition.isSpan() && finalPosition.isSpan()) |
| 40 finalPosition.setAutoPosition(); | 43 finalPosition.setAutoPosition(); |
| 41 | 44 |
| 42 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia
lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) | 45 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia
lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) |
| 43 initialPosition.setAutoPosition(); | 46 initialPosition.setAutoPosition(); |
| 44 | 47 |
| 45 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos
ition.namedGridLine(), gridContainerStyle, finalPositionSide)) | 48 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos
ition.namedGridLine(), gridContainerStyle, finalPositionSide)) |
| 46 finalPosition.setAutoPosition(); | 49 finalPosition.setAutoPosition(); |
| 50 } |
| 51 |
| 52 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con
st RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDi
rection direction, const GridResolvedPosition& resolvedInitialPosition) |
| 53 { |
| 54 GridPosition initialPosition, finalPosition; |
| 55 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 56 |
| 57 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); |
| 58 |
| 59 // This method will only be used when both positions need to be resolved aga
inst the opposite one. |
| 60 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); |
| 61 |
| 62 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition; |
| 63 |
| 64 if (initialPosition.isSpan()) { |
| 65 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC
ontainerStyle, resolvedInitialPosition, initialPosition, finalPositionSide)->res
olvedFinalPosition; |
| 66 } else if (finalPosition.isSpan()) { |
| 67 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC
ontainerStyle, resolvedInitialPosition, finalPosition, finalPositionSide)->resol
vedFinalPosition; |
| 68 } |
| 69 |
| 70 return GridSpan(resolvedInitialPosition, resolvedFinalPosition); |
| 71 } |
| 72 |
| 73 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R
enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect
ion direction) |
| 74 { |
| 75 GridPosition initialPosition, finalPosition; |
| 76 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 77 |
| 78 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio
n); |
| 79 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); |
| 47 | 80 |
| 48 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { | 81 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { |
| 49 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) | 82 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) |
| 50 return adoptPtr(new GridSpan(0, 0)); | 83 return adoptPtr(new GridSpan(0, 0)); |
| 51 | 84 |
| 52 // We can't get our grid positions without running the auto placement al
gorithm. | 85 // We can't get our grid positions without running the auto placement al
gorithm. |
| 53 return nullptr; | 86 return nullptr; |
| 54 } | 87 } |
| 55 | 88 |
| 56 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 89 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 226 |
| 194 // 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). | 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). |
| 195 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 228 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 196 if (it == gridLinesNames.end()) | 229 if (it == gridLinesNames.end()) |
| 197 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 230 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
| 198 | 231 |
| 199 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 232 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 200 } | 233 } |
| 201 | 234 |
| 202 } // namespace WebCore | 235 } // namespace WebCore |
| OLD | NEW |