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

Side by Side Diff: Source/core/rendering/style/GridResolvedPosition.cpp

Issue 309393002: [CSS Grid Layout] Add 'auto' fallback for non existent named grid lines (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Minor refactoring Created 6 years, 6 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 | « no previous file | 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/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 GridSpan GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(con st RenderBox&, GridTrackSizingDirection, const GridResolvedPosition& initialPosi tion)
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 // 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. 16 // sure the grid can accomodate the new item as we only grow 1 position in a given direction.
17 return GridSpan(initialPosition, initialPosition); 17 return GridSpan(initialPosition, initialPosition);
18 } 18 }
19 19
20 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP ositionSide side) 20 static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridP ositionSide side)
21 { 21 {
22 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC olumnLines() : style.namedGridRowLines(); 22 return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridC olumnLines() : style.namedGridRowLines();
23 } 23 }
24 24
25 static inline bool isNonExistentNamedLineOrArea(const String& lineName, const Re nderStyle& style, GridPositionSide side) 25 static inline const String implicitNamedGridLineForSide(const String& lineName, GridPositionSide side)
Julien - ping for review 2014/06/11 22:24:14 Not sure if returning a const gives us much, espec
26 { 26 {
27 return !style.namedGridArea().contains(lineName) && !gridLinesForSide(style, side).contains(lineName); 27 return lineName + ((side == ColumnStartSide || side == RowStartSide) ? "-sta rt" : "-end");
28 }
29
30 static bool isNonExistentNamedLineOrArea(const String& lineName, const RenderSty le& style, GridPositionSide side)
Julien - ping for review 2014/06/11 22:24:14 We should probably just flip the logic as we are d
31 {
32 const NamedGridLinesMap& gridLineNames = gridLinesForSide(style, side);
33
34 return !gridLineNames.contains(implicitNamedGridLineForSide(lineName, side)) && !gridLineNames.contains(lineName);
28 } 35 }
29 36
30 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect ion direction) 37 PassOwnPtr<GridSpan> GridResolvedPosition::resolveGridPositionsFromStyle(const R enderStyle& gridContainerStyle, const RenderBox& gridItem, GridTrackSizingDirect ion direction)
31 { 38 {
32 GridPosition initialPosition = (direction == ForColumns) ? gridItem.style()- >gridColumnStart() : gridItem.style()->gridRowStart(); 39 GridPosition initialPosition = (direction == ForColumns) ? gridItem.style()- >gridColumnStart() : gridItem.style()->gridRowStart();
33 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col umnStartSide : RowStartSide; 40 const GridPositionSide initialPositionSide = (direction == ForColumns) ? Col umnStartSide : RowStartSide;
34 GridPosition finalPosition = (direction == ForColumns) ? gridItem.style()->g ridColumnEnd() : gridItem.style()->gridRowEnd(); 41 GridPosition finalPosition = (direction == ForColumns) ? gridItem.style()->g ridColumnEnd() : gridItem.style()->gridRowEnd();
35 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum nEndSide : RowEndSide; 42 const GridPositionSide finalPositionSide = (direction == ForColumns) ? Colum nEndSide : RowEndSide;
36 43
37 // We must handle the placement error handling code here instead of in the S tyleAdjuster because we don't want to 44 // 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. 45 // overwrite the specified values.
39 if (initialPosition.isSpan() && finalPosition.isSpan()) 46 if (initialPosition.isSpan() && finalPosition.isSpan())
40 finalPosition.setAutoPosition(); 47 finalPosition.setAutoPosition();
41 48
49 // Try to early detect the case of non existing named grid lines. This way w e could assume later that
50 // GridResolvedPosition::resolveGrisPositionFromStyle() always return a vali d resolved position.
42 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia lPosition.namedGridLine(), gridContainerStyle, initialPositionSide)) 51 if (initialPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(initia lPosition.namedGridLine(), gridContainerStyle, initialPositionSide))
43 initialPosition.setAutoPosition(); 52 initialPosition.setAutoPosition();
44 53
45 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos ition.namedGridLine(), gridContainerStyle, finalPositionSide)) 54 if (finalPosition.isNamedGridArea() && isNonExistentNamedLineOrArea(finalPos ition.namedGridLine(), gridContainerStyle, finalPositionSide))
46 finalPosition.setAutoPosition(); 55 finalPosition.setAutoPosition();
47 56
48 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) { 57 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi on.shouldBeResolvedAgainstOppositePosition()) {
49 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone) 58 if (gridContainerStyle.gridAutoFlow() == AutoFlowNone)
50 return adoptPtr(new GridSpan(0, 0)); 59 return adoptPtr(new GridSpan(0, 0));
51 60
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return GridResolvedPosition(0); 141 return GridResolvedPosition(0);
133 142
134 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side); 143 return adjustGridPositionForSide(endOfTrack - resolvedPosition, side);
135 } 144 }
136 case NamedGridAreaPosition: 145 case NamedGridAreaPosition:
137 { 146 {
138 // First attempt to match the grid area’s edge to a named grid area: if there is a named line with the name 147 // First attempt to match the grid area’s edge to a named grid area: if there is a named line with the name
139 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for grid-*-end), contributes the first such 148 // ''<custom-ident>-start (for grid-*-start) / <custom-ident>-end'' (for grid-*-end), contributes the first such
140 // line to the grid item’s placement. 149 // line to the grid item’s placement.
141 String namedGridLine = position.namedGridLine(); 150 String namedGridLine = position.namedGridLine();
142 String implicitNamedGridLine = namedGridLine + ((side == ColumnStartSide || side == RowStartSide) ? "-start" : "-end"); 151 ASSERT(!isNonExistentNamedLineOrArea(namedGridLine, gridContainerStyle, side));
152
143 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS tyle, side); 153 const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerS tyle, side);
144 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find( implicitNamedGridLine); 154 NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find( implicitNamedGridLineForSide(namedGridLine, side));
145 if (implicitLineIter != gridLineNames.end()) 155 if (implicitLineIter != gridLineNames.end())
146 return adjustGridPositionForSide(implicitLineIter->value[0], side); 156 return adjustGridPositionForSide(implicitLineIter->value[0], side);
147 157
148 // Otherwise, if there is a named line with the specified name, contribu tes the first such line to the grid 158 // Otherwise, if there is a named line with the specified name, contribu tes the first such line to the grid
149 // item’s placement. 159 // item’s placement.
150 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find( namedGridLine); 160 NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find( namedGridLine);
151 if (explicitLineIter != gridLineNames.end()) 161 if (explicitLineIter != gridLineNames.end())
152 return adjustGridPositionForSide(explicitLineIter->value[0], side); 162 return adjustGridPositionForSide(explicitLineIter->value[0], side);
153 163
154 // FIXME: if none of the above works specs mandate us to treat it as aut o. We cannot return auto right here 164 // If none of the above works specs mandate us to treat it as auto BUT w e should have detected it before calling
155 // right now because callers expect a resolved position. We need deeper changes to support this use case. 165 // this function in GridResolvedPosition::resolveGridPositionsFromStyle( ). We should be also covered by the
166 // ASSERT at the beginning of this block.
167 ASSERT_NOT_REACHED();
156 return GridResolvedPosition(0); 168 return GridResolvedPosition(0);
157 } 169 }
158 case AutoPosition: 170 case AutoPosition:
159 case SpanPosition: 171 case SpanPosition:
160 // 'auto' and span depend on the opposite position for resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / "myHeader"). 172 // 'auto' and span depend on the opposite position for resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / "myHeader").
161 ASSERT_NOT_REACHED(); 173 ASSERT_NOT_REACHED();
162 return GridResolvedPosition(0); 174 return GridResolvedPosition(0);
163 } 175 }
164 ASSERT_NOT_REACHED(); 176 ASSERT_NOT_REACHED();
165 return GridResolvedPosition(0); 177 return GridResolvedPosition(0);
(...skipping 27 matching lines...) Expand all
193 205
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). 206 // 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. 207 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html.
196 if (it == gridLinesNames.end()) 208 if (it == gridLinesNames.end())
197 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on); 209 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi on);
198 210
199 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value); 211 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition , position, side, it->value);
200 } 212 }
201 213
202 } // namespace WebCore 214 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698