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

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

Issue 2161003003: [css-grid] repeat() syntax should take a <track-list> argument (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 "GridPositionsResolver.h" 5 #include "GridPositionsResolver.h"
6 6
7 #include "core/layout/LayoutBox.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/style/GridArea.h" 8 #include "core/style/GridArea.h"
9 #include <algorithm> 9 #include <algorithm>
10 10
11 namespace blink { 11 namespace blink {
12 12
13 static inline GridTrackSizingDirection directionFromSide(GridPositionSide side) 13 static inline GridTrackSizingDirection directionFromSide(GridPositionSide side)
14 { 14 {
15 return side == ColumnStartSide || side == ColumnEndSide ? ForColumns : ForRo ws; 15 return side == ColumnStartSide || side == ColumnEndSide ? ForColumns : ForRo ws;
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 NamedLineCollection::NamedLineCollection(const ComputedStyle& gridContainerStyle , const String& namedLine, GridTrackSizingDirection direction, size_t lastLine, size_t autoRepeatTracksCount) 23 NamedLineCollection::NamedLineCollection(const ComputedStyle& gridContainerStyle , const String& namedLine, GridTrackSizingDirection direction, size_t lastLine, size_t autoRepeatTracksCount)
24 : m_lastLine(lastLine) 24 : m_lastLine(lastLine)
25 , m_repetitions(autoRepeatTracksCount) 25 , m_autoRepeatTotalTracks(autoRepeatTracksCount)
26 { 26 {
27 bool isRowAxis = direction == ForColumns; 27 bool isRowAxis = direction == ForColumns;
28 const NamedGridLinesMap& gridLineNames = isRowAxis ? gridContainerStyle.name dGridColumnLines() : gridContainerStyle.namedGridRowLines(); 28 const NamedGridLinesMap& gridLineNames = isRowAxis ? gridContainerStyle.name dGridColumnLines() : gridContainerStyle.namedGridRowLines();
29 const NamedGridLinesMap& autoRepeatGridLineNames = isRowAxis ? gridContainer Style.autoRepeatNamedGridColumnLines() : gridContainerStyle.autoRepeatNamedGridR owLines(); 29 const NamedGridLinesMap& autoRepeatGridLineNames = isRowAxis ? gridContainer Style.autoRepeatNamedGridColumnLines() : gridContainerStyle.autoRepeatNamedGridR owLines();
30 30
31 if (!gridLineNames.isEmpty()) { 31 if (!gridLineNames.isEmpty()) {
32 auto it = gridLineNames.find(namedLine); 32 auto it = gridLineNames.find(namedLine);
33 m_namedLinesIndexes = it == gridLineNames.end() ? nullptr : &it->value; 33 m_namedLinesIndexes = it == gridLineNames.end() ? nullptr : &it->value;
34 } 34 }
35 35
36 if (!autoRepeatGridLineNames.isEmpty()) { 36 if (!autoRepeatGridLineNames.isEmpty()) {
37 auto it = autoRepeatGridLineNames.find(namedLine); 37 auto it = autoRepeatGridLineNames.find(namedLine);
38 m_autoRepeatNamedLinesIndexes = it == autoRepeatGridLineNames.end() ? nu llptr : &it->value; 38 m_autoRepeatNamedLinesIndexes = it == autoRepeatGridLineNames.end() ? nu llptr : &it->value;
39 } 39 }
40 40
41 m_insertionPoint = isRowAxis ? gridContainerStyle.gridAutoRepeatColumnsInser tionPoint() : gridContainerStyle.gridAutoRepeatRowsInsertionPoint(); 41 m_insertionPoint = isRowAxis ? gridContainerStyle.gridAutoRepeatColumnsInser tionPoint() : gridContainerStyle.gridAutoRepeatRowsInsertionPoint();
42
43 m_autoRepeatTrackListLength = isRowAxis ? gridContainerStyle.gridAutoRepeatC olumns().size() : gridContainerStyle.gridAutoRepeatRows().size();
42 } 44 }
43 45
44 bool NamedLineCollection::isValidNamedLineOrArea(const String& namedLine, const ComputedStyle& gridContainerStyle, GridPositionSide side) 46 bool NamedLineCollection::isValidNamedLineOrArea(const String& namedLine, const ComputedStyle& gridContainerStyle, GridPositionSide side)
45 { 47 {
46 bool isRowAxis = directionFromSide(side) == ForColumns; 48 bool isRowAxis = directionFromSide(side) == ForColumns;
47 const NamedGridLinesMap& gridLineNames = isRowAxis ? gridContainerStyle.name dGridColumnLines() : gridContainerStyle.namedGridRowLines(); 49 const NamedGridLinesMap& gridLineNames = isRowAxis ? gridContainerStyle.name dGridColumnLines() : gridContainerStyle.namedGridRowLines();
48 const NamedGridLinesMap& autoRepeatGridLineNames = isRowAxis ? gridContainer Style.autoRepeatNamedGridColumnLines() : gridContainerStyle.autoRepeatNamedGridR owLines(); 50 const NamedGridLinesMap& autoRepeatGridLineNames = isRowAxis ? gridContainer Style.autoRepeatNamedGridColumnLines() : gridContainerStyle.autoRepeatNamedGridR owLines();
49 51
50 if (gridLineNames.contains(namedLine) || autoRepeatGridLineNames.contains(na medLine)) 52 if (gridLineNames.contains(namedLine) || autoRepeatGridLineNames.contains(na medLine))
51 return true; 53 return true;
52 54
53 String implicitName = implicitNamedGridLineForSide(namedLine, side); 55 String implicitName = implicitNamedGridLineForSide(namedLine, side);
54 return gridLineNames.contains(implicitName) || autoRepeatGridLineNames.conta ins(implicitName); 56 return gridLineNames.contains(implicitName) || autoRepeatGridLineNames.conta ins(implicitName);
55 } 57 }
56 58
57 bool NamedLineCollection::hasNamedLines() 59 bool NamedLineCollection::hasNamedLines()
58 { 60 {
59 return m_namedLinesIndexes || m_autoRepeatNamedLinesIndexes; 61 return m_namedLinesIndexes || m_autoRepeatNamedLinesIndexes;
60 } 62 }
61 63
62 size_t NamedLineCollection::find(size_t line) 64 size_t NamedLineCollection::find(size_t line)
63 { 65 {
64 if (line > m_lastLine) 66 if (line > m_lastLine)
65 return kNotFound; 67 return kNotFound;
66 68
67 if (!m_autoRepeatNamedLinesIndexes || line < m_insertionPoint) 69 if (!m_autoRepeatNamedLinesIndexes || line < m_insertionPoint)
68 return m_namedLinesIndexes ? m_namedLinesIndexes->find(line) : kNotFound ; 70 return m_namedLinesIndexes ? m_namedLinesIndexes->find(line) : kNotFound ;
69 71
70 if (line <= (m_insertionPoint + m_repetitions)) { 72 if (line <= (m_insertionPoint + m_autoRepeatTotalTracks)) {
71 size_t localIndex = line - m_insertionPoint; 73 size_t localIndex = line - m_insertionPoint;
72 74
75 size_t indexInFirstRepetition = localIndex % m_autoRepeatTrackListLength ;
76 if (indexInFirstRepetition)
77 return m_autoRepeatNamedLinesIndexes->find(indexInFirstRepetition);
78
73 // The line names defined in the last line are also present in the first line of the next 79 // The line names defined in the last line are also present in the first line of the next
74 // repetition (if any). Same for the line names defined in the first lin e. Note that there 80 // repetition (if any). Same for the line names defined in the first lin e.
75 // is only one auto-repeated track allowed by the syntax, that's why it' s enough to store 81 if (localIndex == m_autoRepeatTotalTracks)
76 // indexes 0 and 1 (before and after the track size). 82 return m_autoRepeatNamedLinesIndexes->find(m_autoRepeatTrackListLeng th);
77 if (localIndex == m_repetitions)
78 return m_autoRepeatNamedLinesIndexes->find(static_cast<size_t>(1));
79 size_t position = m_autoRepeatNamedLinesIndexes->find(static_cast<size_t >(0)); 83 size_t position = m_autoRepeatNamedLinesIndexes->find(static_cast<size_t >(0));
80 if (position != kNotFound) 84 if (position != kNotFound)
81 return position; 85 return position;
82 return localIndex == 0 ? kNotFound : m_autoRepeatNamedLinesIndexes->find (static_cast<size_t>(1)); 86 return localIndex == 0 ? kNotFound : m_autoRepeatNamedLinesIndexes->find (m_autoRepeatTrackListLength);
83 } 87 }
84 88
85 return m_namedLinesIndexes ? m_namedLinesIndexes->find(line - (m_repetitions - 1)) : kNotFound; 89 return m_namedLinesIndexes ? m_namedLinesIndexes->find(line - (m_autoRepeatT otalTracks - 1)) : kNotFound;
86 } 90 }
87 91
88 bool NamedLineCollection::contains(size_t line) 92 bool NamedLineCollection::contains(size_t line)
89 { 93 {
90 CHECK(hasNamedLines()); 94 CHECK(hasNamedLines());
91 return find(line) != kNotFound; 95 return find(line) != kNotFound;
92 } 96 }
93 97
94 size_t NamedLineCollection::firstPosition() 98 size_t NamedLineCollection::firstPosition()
95 { 99 {
96 CHECK(hasNamedLines()); 100 CHECK(hasNamedLines());
97 101
98 size_t firstLine = 0; 102 size_t firstLine = 0;
99 103
100 if (!m_autoRepeatNamedLinesIndexes) { 104 if (!m_autoRepeatNamedLinesIndexes) {
101 if (m_insertionPoint == 0 || m_insertionPoint < m_namedLinesIndexes->at( firstLine)) 105 if (m_insertionPoint == 0 || m_insertionPoint < m_namedLinesIndexes->at( firstLine))
102 return m_namedLinesIndexes->at(firstLine) + (m_repetitions ? m_repet itions - 1 : 0); 106 return m_namedLinesIndexes->at(firstLine) + (m_autoRepeatTotalTracks ? m_autoRepeatTotalTracks - 1 : 0);
103 return m_namedLinesIndexes->at(firstLine); 107 return m_namedLinesIndexes->at(firstLine);
104 } 108 }
105 109
106 if (!m_namedLinesIndexes) 110 if (!m_namedLinesIndexes)
107 return m_autoRepeatNamedLinesIndexes->at(firstLine) + m_insertionPoint; 111 return m_autoRepeatNamedLinesIndexes->at(firstLine) + m_insertionPoint;
108 112
109 if (m_insertionPoint == 0) 113 if (m_insertionPoint == 0)
110 return m_autoRepeatNamedLinesIndexes->at(firstLine); 114 return std::min(m_namedLinesIndexes->at(firstLine) + m_autoRepeatTotalTr acks, m_autoRepeatNamedLinesIndexes->at(firstLine));
111 115
112 return std::min(m_namedLinesIndexes->at(firstLine), m_autoRepeatNamedLinesIn dexes->at(firstLine) + m_insertionPoint); 116 return std::min(m_namedLinesIndexes->at(firstLine), m_autoRepeatNamedLinesIn dexes->at(firstLine) + m_insertionPoint);
113 } 117 }
114 118
115 GridPositionSide GridPositionsResolver::initialPositionSide(GridTrackSizingDirec tion direction) 119 GridPositionSide GridPositionsResolver::initialPositionSide(GridTrackSizingDirec tion direction)
116 { 120 {
117 return (direction == ForColumns) ? ColumnStartSide : RowStartSide; 121 return (direction == ForColumns) ? ColumnStartSide : RowStartSide;
118 } 122 }
119 123
120 GridPositionSide GridPositionsResolver::finalPositionSide(GridTrackSizingDirecti on direction) 124 GridPositionSide GridPositionsResolver::finalPositionSide(GridTrackSizingDirecti on direction)
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 375
372 if (endLine < startLine) 376 if (endLine < startLine)
373 std::swap(endLine, startLine); 377 std::swap(endLine, startLine);
374 else if (endLine == startLine) 378 else if (endLine == startLine)
375 endLine = startLine + 1; 379 endLine = startLine + 1;
376 380
377 return GridSpan::untranslatedDefiniteGridSpan(startLine, endLine); 381 return GridSpan::untranslatedDefiniteGridSpan(startLine, endLine);
378 } 382 }
379 383
380 } // namespace blink 384 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698