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 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirection directio n, GridPosition& initialPosition, const GridPositionSide initialPositionSide, Gr idPosition& finalPosition, const GridPositionSide finalPositionSide) |
Julien - ping for review
2014/05/29 21:07:00
I don't see what this refactoring gives us:
- the
| |
31 { | 24 { |
32 GridPosition initialPosition = (direction == ForColumns) ? gridItem.style()- >gridColumnStart() : gridItem.style()->gridRowStart(); | 25 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt art() : gridItem.style()->gridRowStart(); |
33 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col umnStartSide : RowStartSide; | 26 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd( ) : gridItem.style()->gridRowEnd(); |
34 GridPosition finalPosition = (direction == ForColumns) ? gridItem.style()->g ridColumnEnd() : gridItem.style()->gridRowEnd(); | |
35 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum nEndSide : RowEndSide; | |
36 | 27 |
37 // We must handle the placement error handling code here instead of in the S tyleAdjuster because we don't want to | 28 // 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. | 29 // overwrite the specified values. |
39 if (initialPosition.isSpan() && finalPosition.isSpan()) | 30 if (initialPosition.isSpan() && finalPosition.isSpan()) |
40 finalPosition.setAutoPosition(); | 31 finalPosition.setAutoPosition(); |
41 | 32 |
42 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) | 33 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) |
43 initialPosition.setAutoPosition(); | 34 initialPosition.setAutoPosition(); |
44 | 35 |
45 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos ition.namedGridLine(), gridContainerStyle, finalPositionSide)) | 36 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos ition.namedGridLine(), gridContainerStyle, finalPositionSide)) |
46 finalPosition.setAutoPosition(); | 37 finalPosition.setAutoPosition(); |
38 } | |
39 | |
40 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromAutoPlacement Position(const RenderStyle& gridContainerStyle, const RenderBox& gridItem, GridT rackSizingDirection direction, const GridResolvedPosition& resolvedInitialPositi on) | |
Julien - ping for review
2014/05/29 21:07:00
This function cannot return nullptr so we should m
| |
41 { | |
42 GridPosition initialPosition; | |
43 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col umnStartSide : RowStartSide; | |
44 GridPosition finalPosition; | |
45 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum nEndSide : RowEndSide; | |
46 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, initialPositionSide, finalPosition, finalPositionSide); | |
47 | |
48 // This method will only be used when both positions need to be resolved aga inst the opposite one. | |
49 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos ition.shouldBeResolvedAgainstOppositePosition()); | |
50 | |
51 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition; | |
52 | |
53 if (initialPosition.isSpan()) { | |
54 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC ontainerStyle, resolvedInitialPosition, initialPosition, finalPositionSide)->res olvedFinalPosition; | |
55 } else if (finalPosition.isSpan()) { | |
56 resolvedFinalPosition = resolveGridPositionAgainstOppositePosition(gridC ontainerStyle, resolvedInitialPosition, finalPosition, finalPositionSide)->resol vedFinalPosition; | |
57 } | |
58 | |
59 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition) ); | |
60 } | |
61 | |
62 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect ion direction) | |
63 { | |
64 GridPosition initialPosition; | |
65 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col umnStartSide : RowStartSide; | |
66 GridPosition finalPosition; | |
67 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum nEndSide : RowEndSide; | |
68 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, initialPositionSide, finalPosition, finalPositionSide); | |
47 | 69 |
48 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { | 70 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { |
49 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) | 71 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) |
50 return adoptPtr(new GridSpan(0, 0)); | 72 return adoptPtr(new GridSpan(0, 0)); |
51 | 73 |
52 // We can't get our grid positions without running the auto placement al gorithm. | 74 // We can't get our grid positions without running the auto placement al gorithm. |
53 return nullptr; | 75 return nullptr; |
54 } | 76 } |
55 | 77 |
56 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 78 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 215 |
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). | 216 // 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. | 217 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
196 if (it == gridLinesNames.end()) | 218 if (it == gridLinesNames.end()) |
197 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); | 219 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); |
198 | 220 |
199 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); | 221 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); |
200 } | 222 } |
201 | 223 |
202 } // namespace WebCore | 224 } // namespace WebCore |
OLD | NEW |