Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/WebKit/Source/core/style/GridResolvedPosition.cpp

Issue 1375173002: [css-grid] Unknown named grid lines on absolutely positioned items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/style/GridResolvedPosition.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/style/GridResolvedPosition.h" 6 #include "core/style/GridResolvedPosition.h"
7 7
8 #include "core/layout/LayoutBox.h" 8 #include "core/layout/LayoutBox.h"
9 #include "core/style/GridCoordinate.h" 9 #include "core/style/GridCoordinate.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 static const NamedGridLinesMap& gridLinesForSide(const ComputedStyle& style, Gri dPositionSide side) 13 static const NamedGridLinesMap& gridLinesForSide(const ComputedStyle& style, Gri dPositionSide 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 String implicitNamedGridLineForSide(const String& lineName, GridPo sitionSide side) 18 static inline String implicitNamedGridLineForSide(const String& lineName, GridPo sitionSide side)
19 { 19 {
20 return lineName + ((side == ColumnStartSide || side == RowStartSide) ? "-sta rt" : "-end"); 20 return lineName + ((side == ColumnStartSide || side == RowStartSide) ? "-sta rt" : "-end");
21 } 21 }
22 22
23 static bool isValidNamedLineOrArea(const String& lineName, const ComputedStyle& style, GridPositionSide side) 23 bool GridResolvedPosition::isValidNamedLineOrArea(const String& lineName, const ComputedStyle& style, GridPositionSide side)
24 { 24 {
25 const NamedGridLinesMap& gridLineNames = gridLinesForSide(style, side); 25 const NamedGridLinesMap& gridLineNames = gridLinesForSide(style, side);
26 26
27 return gridLineNames.contains(implicitNamedGridLineForSide(lineName, side)) || gridLineNames.contains(lineName); 27 return gridLineNames.contains(implicitNamedGridLineForSide(lineName, side)) || gridLineNames.contains(lineName);
28 } 28 }
29 29
30 static GridPositionSide calculateInitialPositionSide(GridTrackSizingDirection di rection) 30 GridPositionSide GridResolvedPosition::initialPositionSide(GridTrackSizingDirect ion direction)
31 { 31 {
32 return (direction == ForColumns) ? ColumnStartSide : RowStartSide; 32 return (direction == ForColumns) ? ColumnStartSide : RowStartSide;
33 } 33 }
34 34
35 static GridPositionSide calculateFinalPositionSide(GridTrackSizingDirection dire ction) 35 GridPositionSide GridResolvedPosition::finalPositionSide(GridTrackSizingDirectio n direction)
36 { 36 {
37 return (direction == ForColumns) ? ColumnEndSide : RowEndSide; 37 return (direction == ForColumns) ? ColumnEndSide : RowEndSide;
38 } 38 }
39 39
40 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const ComputedStyle & gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direct ion, GridPosition& initialPosition, GridPosition& finalPosition) 40 void GridResolvedPosition::initialAndFinalPositionsFromStyle(const ComputedStyle & gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDirection direct ion, GridPosition& initialPosition, GridPosition& finalPosition)
41 { 41 {
42 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt art() : gridItem.style()->gridRowStart(); 42 initialPosition = (direction == ForColumns) ? gridItem.style()->gridColumnSt art() : gridItem.style()->gridRowStart();
43 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd( ) : gridItem.style()->gridRowEnd(); 43 finalPosition = (direction == ForColumns) ? gridItem.style()->gridColumnEnd( ) : gridItem.style()->gridRowEnd();
44 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio n);
45 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction);
46 44
47 // We must handle the placement error handling code here instead of in the S tyleAdjuster because we don't want to 45 // We must handle the placement error handling code here instead of in the S tyleAdjuster because we don't want to
48 // overwrite the specified values. 46 // overwrite the specified values.
49 if (initialPosition.isSpan() && finalPosition.isSpan()) 47 if (initialPosition.isSpan() && finalPosition.isSpan())
50 finalPosition.setAutoPosition(); 48 finalPosition.setAutoPosition();
51 49
52 // Try to early detect the case of non existing named grid lines. This way w e could assume later that 50 // 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. 51 // GridResolvedPosition::resolveGrisPositionFromStyle() always return a vali d resolved position.
54 if (initialPosition.isNamedGridArea() && !isValidNamedLineOrArea(initialPosi tion.namedGridLine(), gridContainerStyle, initialPositionSide)) 52 if (initialPosition.isNamedGridArea() && !isValidNamedLineOrArea(initialPosi tion.namedGridLine(), gridContainerStyle, initialPositionSide(direction)))
55 initialPosition.setAutoPosition(); 53 initialPosition.setAutoPosition();
56 54
57 if (finalPosition.isNamedGridArea() && !isValidNamedLineOrArea(finalPosition .namedGridLine(), gridContainerStyle, finalPositionSide)) 55 if (finalPosition.isNamedGridArea() && !isValidNamedLineOrArea(finalPosition .namedGridLine(), gridContainerStyle, finalPositionSide(direction)))
58 finalPosition.setAutoPosition(); 56 finalPosition.setAutoPosition();
59 57
60 // If the grid item has an automatic position and a grid span for a named li ne in a given dimension, instead treat the grid span as one. 58 // If the grid item has an automatic position and a grid span for a named li ne in a given dimension, instead treat the grid span as one.
61 if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.nam edGridLine().isNull()) 59 if (initialPosition.isAuto() && finalPosition.isSpan() && !finalPosition.nam edGridLine().isNull())
62 finalPosition.setSpanPosition(1, String()); 60 finalPosition.setSpanPosition(1, String());
63 if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.n amedGridLine().isNull()) 61 if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.n amedGridLine().isNull())
64 initialPosition.setSpanPosition(1, String()); 62 initialPosition.setSpanPosition(1, String());
65 } 63 }
66 64
67 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing Direction direction, const GridResolvedPosition& resolvedInitialPosition) 65 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con st ComputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizing Direction direction, const GridResolvedPosition& resolvedInitialPosition)
68 { 66 {
69 GridPosition initialPosition, finalPosition; 67 GridPosition initialPosition, finalPosition;
70 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition); 68 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition);
71 69
72 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); 70 GridPositionSide finalSide = finalPositionSide(direction);
73 71
74 // This method will only be used when both positions need to be resolved aga inst the opposite one. 72 // This method will only be used when both positions need to be resolved aga inst the opposite one.
75 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos ition.shouldBeResolvedAgainstOppositePosition()); 73 ASSERT(initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPos ition.shouldBeResolvedAgainstOppositePosition());
76 74
77 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition; 75 GridResolvedPosition resolvedFinalPosition = resolvedInitialPosition;
78 76
79 if (initialPosition.isSpan()) 77 if (initialPosition.isSpan())
80 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r esolvedInitialPosition, initialPosition, finalPositionSide); 78 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r esolvedInitialPosition, initialPosition, finalSide);
81 if (finalPosition.isSpan()) 79 if (finalPosition.isSpan())
82 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r esolvedInitialPosition, finalPosition, finalPositionSide); 80 return *resolveGridPositionAgainstOppositePosition(gridContainerStyle, r esolvedInitialPosition, finalPosition, finalSide);
83 81
84 return GridSpan(resolvedInitialPosition, resolvedFinalPosition); 82 return GridSpan(resolvedInitialPosition, resolvedFinalPosition);
85 } 83 }
86 84
87 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const C omputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDire ction direction) 85 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const C omputedStyle& gridContainerStyle, const LayoutBox& gridItem, GridTrackSizingDire ction direction)
88 { 86 {
89 GridPosition initialPosition, finalPosition; 87 GridPosition initialPosition, finalPosition;
90 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition); 88 initialAndFinalPositionsFromStyle(gridContainerStyle, gridItem, direction, i nitialPosition, finalPosition);
91 89
92 GridPositionSide initialPositionSide = calculateInitialPositionSide(directio n); 90 GridPositionSide initialSide = initialPositionSide(direction);
93 GridPositionSide finalPositionSide = calculateFinalPositionSide(direction); 91 GridPositionSide finalSide = finalPositionSide(direction);
94 92
95 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { 93 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) {
96 // We can't get our grid positions without running the auto placement al gorithm. 94 // We can't get our grid positions without running the auto placement al gorithm.
97 return nullptr; 95 return nullptr;
98 } 96 }
99 97
100 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { 98 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) {
101 // Infer the position from the final position ('auto / 1' or 'span 2 / 3 ' case). 99 // Infer the position from the final position ('auto / 1' or 'span 2 / 3 ' case).
102 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl e(gridContainerStyle, finalPosition, finalPositionSide); 100 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl e(gridContainerStyle, finalPosition, finalSide);
103 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi nalResolvedPosition, initialPosition, initialPositionSide); 101 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, fi nalResolvedPosition, initialPosition, initialSide);
104 } 102 }
105 103
106 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { 104 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) {
107 // Infer our position from the initial position ('1 / auto' or '3 / span 2' case). 105 // Infer our position from the initial position ('1 / auto' or '3 / span 2' case).
108 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt yle(gridContainerStyle, initialPosition, initialPositionSide); 106 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt yle(gridContainerStyle, initialPosition, initialSide);
109 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in itialResolvedPosition, finalPosition, finalPositionSide); 107 return resolveGridPositionAgainstOppositePosition(gridContainerStyle, in itialResolvedPosition, finalPosition, finalSide);
110 } 108 }
111 109
112 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle( gridContainerStyle, initialPosition, initialPositionSide); 110 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle( gridContainerStyle, initialPosition, initialSide);
113 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(gr idContainerStyle, finalPosition, finalPositionSide); 111 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(gr idContainerStyle, finalPosition, finalSide);
114 112
115 // If 'grid-after' specifies a line at or before that specified by 'grid-bef ore', it computes to 'span 1'. 113 // If 'grid-after' specifies a line at or before that specified by 'grid-bef ore', it computes to 'span 1'.
116 if (resolvedFinalPosition < resolvedInitialPosition) 114 if (resolvedFinalPosition < resolvedInitialPosition)
117 resolvedFinalPosition = resolvedInitialPosition; 115 resolvedFinalPosition = resolvedInitialPosition;
118 116
119 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition) ); 117 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition) );
120 } 118 }
121 119
122 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo ntainerStyle) 120 size_t GridResolvedPosition::explicitGridColumnCount(const ComputedStyle& gridCo ntainerStyle)
123 { 121 {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 238
241 // 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).
242 // 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.
243 if (it == gridLinesNames.end()) 241 if (it == gridLinesNames.end())
244 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); 242 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on);
245 243
246 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); 244 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value);
247 } 245 }
248 246
249 } // namespace blink 247 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/GridResolvedPosition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698