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) | 13 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle&
gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection directio
n, GridPosition& initialPosition, GridPosition& finalPosition) |
14 { | 14 { |
15 // FIXME: We don't support spanning with auto positions yet. Once we do, thi
s is wrong. Also we should make | 15 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt
art() : gridItem.style()->gridRowStart(); |
16 // sure the grid can accomodate the new item as we only grow 1 position in a
given direction. | 16 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd(
) : gridItem.style()->gridRowEnd(); |
17 return GridSpan(initialPosition, initialPosition); | 17 |
| 18 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to |
| 19 // overwrite the specified values. |
| 20 if (initialPosition.isSpan() && finalPosition.isSpan()) |
| 21 finalPosition.setAutoPosition(); |
| 22 |
| 23 if (initialPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea()
.contains(initialPosition.namedGridLine())) |
| 24 initialPosition.setAutoPosition(); |
| 25 |
| 26 if (finalPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea().c
ontains(finalPosition.namedGridLine())) |
| 27 finalPosition.setAutoPosition(); |
| 28 } |
| 29 |
| 30 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromAutoPlacement
Position(const RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridT
rackSizingDirection direction, const GridResolvedPosition& resolvedInitialPositi
on) |
| 31 { |
| 32 GridPosition initialPosition; |
| 33 GridPosition finalPosition; |
| 34 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
| 35 |
| 36 // This method will only be used when both positions need to be resolved aga
inst the opposite one. |
| 37 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos
ition.shouldBeResolvedAgainstOppositePosition()); |
| 38 |
| 39 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum
nEndSide : RowEndSide; |
| 40 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition; |
| 41 |
| 42 if (initialPosition.isSpan()) { |
| 43 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC
ontainerStyle, resolvedInitialPosition, initialPosition, finalPositionSide)->res
olvedFinalPosition; |
| 44 } else if (finalPosition.isSpan()) { |
| 45 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC
ontainerStyle, resolvedInitialPosition, finalPosition, finalPositionSide)->resol
vedFinalPosition; |
| 46 } |
| 47 |
| 48 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition)
); |
18 } | 49 } |
19 | 50 |
20 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R
enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect
ion direction) | 51 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R
enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect
ion direction) |
21 { | 52 { |
22 GridPosition initialPosition = (direction == ForColumns) ? gridItem.style()-
>gridColumnStart() : gridItem.style()->gridRowStart(); | 53 GridPosition initialPosition; |
23 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col
umnStartSide : RowStartSide; | 54 GridPosition finalPosition; |
24 GridPosition finalPosition = (direction == ForColumns) ? gridItem.style()->g
ridColumnEnd() : gridItem.style()->gridRowEnd(); | 55 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i
nitialPosition, finalPosition); |
25 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum
nEndSide : RowEndSide; | |
26 | 56 |
27 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to | 57 // We must handle the placement error handling code here instead of in the S
tyleAdjuster because we don't want to |
28 // overwrite the specified values. | 58 // overwrite the specified values. |
29 if (initialPosition.isSpan() && finalPosition.isSpan()) | 59 if (initialPosition.isSpan() && finalPosition.isSpan()) |
30 finalPosition.setAutoPosition(); | 60 finalPosition.setAutoPosition(); |
31 | 61 |
32 if (initialPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea()
.contains(initialPosition.namedGridLine())) | 62 if (initialPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea()
.contains(initialPosition.namedGridLine())) |
33 initialPosition.setAutoPosition(); | 63 initialPosition.setAutoPosition(); |
34 | 64 |
35 if (finalPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea().c
ontains(finalPosition.namedGridLine())) | 65 if (finalPosition.isNamedGridArea() && !gridContainerStyle.namedGridArea().c
ontains(finalPosition.namedGridLine())) |
36 finalPosition.setAutoPosition(); | 66 finalPosition.setAutoPosition(); |
37 | 67 |
38 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { | 68 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { |
39 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) | 69 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) |
40 return adoptPtr(new GridSpan(0, 0)); | 70 return adoptPtr(new GridSpan(0, 0)); |
41 | 71 |
42 // We can't get our grid positions without running the auto placement al
gorithm. | 72 // We can't get our grid positions without running the auto placement al
gorithm. |
43 return nullptr; | 73 return nullptr; |
44 } | 74 } |
45 | 75 |
| 76 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col
umnStartSide : RowStartSide; |
| 77 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum
nEndSide : RowEndSide; |
| 78 |
46 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 79 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
47 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). | 80 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). |
48 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(gridContainerStyle, finalPosition, finalPositionSide); | 81 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(gridContainerStyle, finalPosition, finalPositionSide); |
49 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialPositionSide); | 82 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi
nalResolvedPosition, initialPosition, initialPositionSide); |
50 } | 83 } |
51 | 84 |
52 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { | 85 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { |
53 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). | 86 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). |
54 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(gridContainerStyle, initialPosition, initialPositionSide); | 87 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(gridContainerStyle, initialPosition, initialPositionSide); |
55 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalPositionSide); | 88 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in
itialResolvedPosition, finalPosition, finalPositionSide); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 213 |
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). | 214 // 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. | 215 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
183 if (it == gridLinesNames.end()) | 216 if (it == gridLinesNames.end()) |
184 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 217 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
185 | 218 |
186 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 219 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
187 } | 220 } |
188 | 221 |
189 } // namespace WebCore | 222 } // namespace WebCore |
OLD | NEW |