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

Side by Side Diff: third_party/WebKit/Source/core/style/GridCoordinate.h

Issue 1529083006: [css-grid] Initial support for implicit grid before explicit grid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try to fix Windows build Created 5 years 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Recommended maximum size for both explicit and implicit grids. 43 // Recommended maximum size for both explicit and implicit grids.
44 const size_t kGridMaxTracks = 1000000; 44 const size_t kGridMaxTracks = 1000000;
45 45
46 // A span in a single direction (either rows or columns). Note that |resolvedIni tialPosition| 46 // A span in a single direction (either rows or columns). Note that |resolvedIni tialPosition|
47 // and |resolvedFinalPosition| are grid lines' indexes. 47 // and |resolvedFinalPosition| are grid lines' indexes.
48 // Iterating over the span shouldn't include |resolvedFinalPosition| to be corre ct. 48 // Iterating over the span shouldn't include |resolvedFinalPosition| to be corre ct.
49 struct GridSpan { 49 struct GridSpan {
50 USING_FAST_MALLOC(GridSpan); 50 USING_FAST_MALLOC(GridSpan);
51 public: 51 public:
52 52
53 static GridSpan untranslatedGridSpan(int resolvedInitialPosition, int resolv edFinalPosition)
jfernandez 2015/12/18 14:33:21 I find the 'unstranslated" concept a bit obscure.
Manuel Rego 2015/12/18 22:42:30 Untranslated is only used during the code to resol
54 {
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Untransl ated);
56 }
57
53 static GridSpan definiteGridSpan(size_t resolvedInitialPosition, size_t reso lvedFinalPosition) 58 static GridSpan definiteGridSpan(size_t resolvedInitialPosition, size_t reso lvedFinalPosition)
54 { 59 {
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); 60 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite );
56 } 61 }
57 62
58 static GridSpan indefiniteGridSpan() 63 static GridSpan indefiniteGridSpan()
59 { 64 {
60 return GridSpan(0, 1, Indefinite); 65 return GridSpan(0, 1, Indefinite);
61 } 66 }
62 67
63 bool operator==(const GridSpan& o) const 68 bool operator==(const GridSpan& o) const
64 { 69 {
65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; 70 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition;
66 } 71 }
67 72
68 size_t integerSpan() const 73 size_t integerSpan() const
69 { 74 {
70 ASSERT(isDefinite()); 75 ASSERT(isDefinite());
71 ASSERT(m_resolvedFinalPosition > m_resolvedInitialPosition); 76 ASSERT(m_resolvedFinalPosition > m_resolvedInitialPosition);
72 return m_resolvedFinalPosition - m_resolvedInitialPosition; 77 return m_resolvedFinalPosition - m_resolvedInitialPosition;
73 } 78 }
74 79
80 int untranslatedResolvedInitialPosition() const
81 {
82 ASSERT(m_type == Untranslated);
83 return m_resolvedInitialPosition;
84 }
85
86 int untranslatedResolvedFinalPosition() const
87 {
88 ASSERT(m_type == Untranslated);
89 return m_resolvedFinalPosition;
90 }
91
75 size_t resolvedInitialPosition() const 92 size_t resolvedInitialPosition() const
76 { 93 {
77 ASSERT(isDefinite()); 94 ASSERT(isDefinite());
95 ASSERT(m_resolvedInitialPosition >= 0);
78 return m_resolvedInitialPosition; 96 return m_resolvedInitialPosition;
79 } 97 }
80 98
81 size_t resolvedFinalPosition() const 99 size_t resolvedFinalPosition() const
82 { 100 {
83 ASSERT(isDefinite()); 101 ASSERT(isDefinite());
84 ASSERT(m_resolvedFinalPosition); 102 ASSERT(m_resolvedFinalPosition > 0);
85 return m_resolvedFinalPosition; 103 return m_resolvedFinalPosition;
86 } 104 }
87 105
88 struct GridSpanIterator { 106 struct GridSpanIterator {
89 GridSpanIterator(size_t v) : value(v) {} 107 GridSpanIterator(size_t v) : value(v) {}
90 108
91 size_t operator*() const { return value; } 109 size_t operator*() const { return value; }
92 size_t operator++() { return value++; } 110 size_t operator++() { return value++; }
93 bool operator!=(GridSpanIterator other) const { return value != other.va lue; } 111 bool operator!=(GridSpanIterator other) const { return value != other.va lue; }
94 112
(...skipping 10 matching lines...) Expand all
105 { 123 {
106 ASSERT(isDefinite()); 124 ASSERT(isDefinite());
107 return m_resolvedFinalPosition; 125 return m_resolvedFinalPosition;
108 } 126 }
109 127
110 bool isDefinite() const 128 bool isDefinite() const
111 { 129 {
112 return m_type == Definite; 130 return m_type == Definite;
113 } 131 }
114 132
133 bool isIndefinite() const
134 {
135 return m_type == Indefinite;
136 }
svillar 2015/12/18 13:08:30 I don't like this API because is super-confusing.
Manuel Rego 2015/12/18 22:42:30 I agree this is confusing. So I've changed the po
137
138 void translate(size_t offset)
139 {
140 ASSERT(m_type == Untranslated);
141
142 m_type = Definite;
143 m_resolvedInitialPosition += offset;
144 m_resolvedFinalPosition += offset;
145
svillar 2015/12/18 13:08:30 Looks like it's missing the kGridMaxTrack checks?
Manuel Rego 2015/12/18 22:42:30 I don't think we need them here. We've already the
146 ASSERT(m_resolvedInitialPosition >= 0);
147 ASSERT(m_resolvedFinalPosition > 0);
jfernandez 2015/12/18 14:33:21 I don't get the purpose of these asserts. If 'offs
Manuel Rego 2015/12/18 22:42:30 I think you're missing the fact that m_resolvedIni
148 }
149
115 private: 150 private:
116 151
117 enum GridSpanType {Definite, Indefinite}; 152 enum GridSpanType {Untranslated, Definite, Indefinite};
118 153
119 GridSpan(size_t resolvedInitialPosition, size_t resolvedFinalPosition, GridS panType type) 154 GridSpan(int resolvedInitialPosition, int resolvedFinalPosition, GridSpanTyp e type)
120 : m_resolvedInitialPosition(std::min(resolvedInitialPosition, kGridMaxTr acks - 1)) 155 : m_type(type)
121 , m_resolvedFinalPosition(std::min(resolvedFinalPosition, kGridMaxTracks ))
122 , m_type(type)
123 { 156 {
157 #if ENABLE(ASSERT)
124 ASSERT(resolvedInitialPosition < resolvedFinalPosition); 158 ASSERT(resolvedInitialPosition < resolvedFinalPosition);
159 if (type == Definite) {
160 ASSERT(resolvedInitialPosition >= 0);
161 ASSERT(resolvedFinalPosition > 0);
162 }
163 #endif
164
165 if (resolvedInitialPosition >= 0)
166 m_resolvedInitialPosition = std::min(resolvedInitialPosition, static _cast<int>(kGridMaxTracks) - 1);
svillar 2015/12/18 13:08:30 Just convert kGridMaxTracks to int and remove the
jfernandez 2015/12/18 14:33:21 I think many other casts have been added because o
Manuel Rego 2015/12/18 22:42:30 Done.
Manuel Rego 2015/12/18 22:42:30 I've converted it to int so I think we don't have
167 else
168 m_resolvedInitialPosition = std::max(resolvedInitialPosition, -stati c_cast<int>(kGridMaxTracks));
169
170 if (resolvedFinalPosition >= 0)
171 m_resolvedFinalPosition = std::min(resolvedFinalPosition, static_cas t<int>(kGridMaxTracks));
172 else
173 m_resolvedFinalPosition = std::max(resolvedFinalPosition, -static_ca st<int>(kGridMaxTracks) + 1);
125 } 174 }
126 175
127 size_t m_resolvedInitialPosition; 176 int m_resolvedInitialPosition;
128 size_t m_resolvedFinalPosition; 177 int m_resolvedFinalPosition;
129 GridSpanType m_type; 178 GridSpanType m_type;
130 }; 179 };
131 180
132 // This represents a grid area that spans in both rows' and columns' direction. 181 // This represents a grid area that spans in both rows' and columns' direction.
133 struct GridCoordinate { 182 struct GridCoordinate {
134 USING_FAST_MALLOC(GridCoordinate); 183 USING_FAST_MALLOC(GridCoordinate);
135 public: 184 public:
136 // HashMap requires a default constuctor. 185 // HashMap requires a default constuctor.
137 GridCoordinate() 186 GridCoordinate()
138 : columns(GridSpan::indefiniteGridSpan()) 187 : columns(GridSpan::indefiniteGridSpan())
(...skipping 19 matching lines...) Expand all
158 207
159 GridSpan columns; 208 GridSpan columns;
160 GridSpan rows; 209 GridSpan rows;
161 }; 210 };
162 211
163 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; 212 typedef HashMap<String, GridCoordinate> NamedGridAreaMap;
164 213
165 } // namespace blink 214 } // namespace blink
166 215
167 #endif // GridCoordinate_h 216 #endif // GridCoordinate_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698