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

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: Apply suggested changes 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 23 matching lines...) Expand all
34 #include "core/style/GridResolvedPosition.h" 34 #include "core/style/GridResolvedPosition.h"
35 #include "wtf/Allocator.h" 35 #include "wtf/Allocator.h"
36 #include "wtf/HashMap.h" 36 #include "wtf/HashMap.h"
37 #include "wtf/PassOwnPtr.h" 37 #include "wtf/PassOwnPtr.h"
38 #include "wtf/text/WTFString.h" 38 #include "wtf/text/WTFString.h"
39 #include <algorithm> 39 #include <algorithm>
40 40
41 namespace blink { 41 namespace blink {
42 42
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 int 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 definiteGridSpan(size_t resolvedInitialPosition, size_t reso lvedFinalPosition) 53 static GridSpan untranslatedDefiniteGridSpan(int resolvedInitialPosition, in t resolvedFinalPosition)
54 { 54 {
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); 55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Untransl atedDefinite);
56 }
57
58 static GridSpan translatedDefiniteGridSpan(size_t resolvedInitialPosition, s ize_t resolvedFinalPosition)
59 {
60 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Translat edDefinite);
56 } 61 }
57 62
svillar 2016/01/04 09:10:06 I don't think we need these. Why don't we make the
Manuel Rego 2016/01/04 10:00:11 The main reason to have these static methods (whic
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(isTranslatedDefinite());
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 == UntranslatedDefinite);
83 return m_resolvedInitialPosition;
84 }
85
86 int untranslatedResolvedFinalPosition() const
87 {
88 ASSERT(m_type == UntranslatedDefinite);
89 return m_resolvedFinalPosition;
90 }
91
75 size_t resolvedInitialPosition() const 92 size_t resolvedInitialPosition() const
76 { 93 {
77 ASSERT(isDefinite()); 94 ASSERT(isTranslatedDefinite());
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(isTranslatedDefinite());
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
95 size_t value; 113 size_t value;
96 }; 114 };
97 115
98 GridSpanIterator begin() const 116 GridSpanIterator begin() const
99 { 117 {
100 ASSERT(isDefinite()); 118 ASSERT(isTranslatedDefinite());
101 return m_resolvedInitialPosition; 119 return m_resolvedInitialPosition;
102 } 120 }
103 121
104 GridSpanIterator end() const 122 GridSpanIterator end() const
105 { 123 {
106 ASSERT(isDefinite()); 124 ASSERT(isTranslatedDefinite());
107 return m_resolvedFinalPosition; 125 return m_resolvedFinalPosition;
108 } 126 }
109 127
110 bool isDefinite() const 128 bool isTranslatedDefinite() const
111 { 129 {
112 return m_type == Definite; 130 return m_type == TranslatedDefinite;
131 }
132
133 bool isIndefinite() const
134 {
135 return m_type == Indefinite;
136 }
137
138 void translate(size_t offset)
139 {
140 ASSERT(m_type == UntranslatedDefinite);
141
142 m_type = TranslatedDefinite;
143 m_resolvedInitialPosition += offset;
144 m_resolvedFinalPosition += offset;
145
146 ASSERT(m_resolvedInitialPosition >= 0);
147 ASSERT(m_resolvedFinalPosition > 0);
113 } 148 }
114 149
115 private: 150 private:
116 151
117 enum GridSpanType {Definite, Indefinite}; 152 enum GridSpanType {UntranslatedDefinite, TranslatedDefinite, 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 == TranslatedDefinite) {
160 ASSERT(resolvedInitialPosition >= 0);
161 ASSERT(resolvedFinalPosition > 0);
162 }
163 #endif
164
165 if (resolvedInitialPosition >= 0)
166 m_resolvedInitialPosition = std::min(resolvedInitialPosition, kGridM axTracks - 1);
167 else
168 m_resolvedInitialPosition = std::max(resolvedInitialPosition, -kGrid MaxTracks);
169
170 if (resolvedFinalPosition >= 0)
171 m_resolvedFinalPosition = std::min(resolvedFinalPosition, kGridMaxTr acks);
172 else
173 m_resolvedFinalPosition = std::max(resolvedFinalPosition, -kGridMaxT racks + 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
« no previous file with comments | « third_party/WebKit/Source/core/paint/GridPainter.cpp ('k') | third_party/WebKit/Source/core/style/GridResolvedPosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698