OLD | NEW |
---|---|
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 Loading... | |
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 definiteGridSpan(const GridResolvedPosition& resolvedInitial Position, const GridResolvedPosition& resolvedFinalPosition) | 53 static GridSpan definiteGridSpan(size_t resolvedInitialPosition, size_t reso lvedFinalPosition) |
54 { | 54 { |
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); | 55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); |
56 } | 56 } |
57 | 57 |
58 static GridSpan indefiniteGridSpan() | 58 static GridSpan indefiniteGridSpan() |
59 { | 59 { |
60 return GridSpan(0, 1, Indefinite); | 60 return GridSpan(0, 1, Indefinite); |
61 } | 61 } |
62 | 62 |
63 bool operator==(const GridSpan& o) const | 63 bool operator==(const GridSpan& o) const |
64 { | 64 { |
65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; | 65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; |
66 } | 66 } |
67 | 67 |
68 size_t integerSpan() const | 68 size_t integerSpan() const |
69 { | 69 { |
70 ASSERT(isDefinite()); | 70 ASSERT(isDefinite()); |
rune
2015/12/03 14:08:38
ASSERT(m_resolvedFinalPosition >= m_resolvedInitia
Manuel Rego
2015/12/04 07:28:06
We're already checking something similar in the co
| |
71 return m_resolvedFinalPosition.toInt() - m_resolvedInitialPosition.toInt (); | 71 return m_resolvedFinalPosition - m_resolvedInitialPosition; |
72 } | 72 } |
73 | 73 |
74 const GridResolvedPosition& resolvedInitialPosition() const | 74 size_t resolvedInitialPosition() const |
75 { | 75 { |
76 ASSERT(isDefinite()); | 76 ASSERT(isDefinite()); |
77 return m_resolvedInitialPosition; | 77 return m_resolvedInitialPosition; |
78 } | 78 } |
79 | 79 |
80 const GridResolvedPosition& resolvedFinalPosition() const | 80 size_t resolvedFinalPosition() const |
81 { | 81 { |
82 ASSERT(isDefinite()); | 82 ASSERT(isDefinite()); |
rune
2015/12/03 14:08:38
ASSERT(m_resolvedFinalPosition)?
Manuel Rego
2015/12/04 07:28:06
Acknowledged.
| |
83 return m_resolvedFinalPosition; | 83 return m_resolvedFinalPosition; |
84 } | 84 } |
85 | 85 |
86 typedef GridResolvedPosition iterator; | 86 struct GridSpanIterator { |
cbiesinger
2015/12/03 17:19:17
How does this work as an iterator without an opera
Manuel Rego
2015/12/04 07:30:21
It's an iterator over a primitive type and it's ov
cbiesinger
2015/12/04 21:06:29
Yes, I think overloading ++ and != would be a lot
| |
87 GridSpanIterator(size_t v) : value(v) {} | |
87 | 88 |
88 iterator begin() const | 89 operator size_t&() { return value; } |
90 size_t operator*() const { return value; } | |
91 | |
92 size_t value; | |
93 }; | |
94 | |
95 GridSpanIterator begin() const | |
89 { | 96 { |
90 ASSERT(isDefinite()); | 97 ASSERT(isDefinite()); |
91 return m_resolvedInitialPosition; | 98 return m_resolvedInitialPosition; |
92 } | 99 } |
93 | 100 |
94 iterator end() const | 101 GridSpanIterator end() const |
95 { | 102 { |
96 ASSERT(isDefinite()); | 103 ASSERT(isDefinite()); |
97 return m_resolvedFinalPosition; | 104 return m_resolvedFinalPosition; |
98 } | 105 } |
99 | 106 |
100 bool isDefinite() const | 107 bool isDefinite() const |
101 { | 108 { |
102 return m_type == Definite; | 109 return m_type == Definite; |
103 } | 110 } |
104 | 111 |
105 private: | 112 private: |
106 | 113 |
107 enum GridSpanType {Definite, Indefinite}; | 114 enum GridSpanType {Definite, Indefinite}; |
108 | 115 |
109 GridSpan(const GridResolvedPosition& resolvedInitialPosition, const GridReso lvedPosition& resolvedFinalPosition, GridSpanType type) | 116 GridSpan(size_t resolvedInitialPosition, size_t resolvedFinalPosition, GridS panType type) |
110 : m_resolvedInitialPosition(std::min(resolvedInitialPosition.toInt(), kG ridMaxTracks - 1)) | 117 : m_resolvedInitialPosition(std::min(resolvedInitialPosition, kGridMaxTr acks - 1)) |
111 , m_resolvedFinalPosition(std::min(resolvedFinalPosition.toInt(), kGridM axTracks)) | 118 , m_resolvedFinalPosition(std::min(resolvedFinalPosition, kGridMaxTracks )) |
112 , m_type(type) | 119 , m_type(type) |
113 { | 120 { |
114 ASSERT(resolvedInitialPosition < resolvedFinalPosition); | 121 ASSERT(resolvedInitialPosition < resolvedFinalPosition); |
115 } | 122 } |
116 | 123 |
117 GridResolvedPosition m_resolvedInitialPosition; | 124 size_t m_resolvedInitialPosition; |
118 GridResolvedPosition m_resolvedFinalPosition; | 125 size_t m_resolvedFinalPosition; |
119 GridSpanType m_type; | 126 GridSpanType m_type; |
120 }; | 127 }; |
121 | 128 |
122 // This represents a grid area that spans in both rows' and columns' direction. | 129 // This represents a grid area that spans in both rows' and columns' direction. |
123 struct GridCoordinate { | 130 struct GridCoordinate { |
124 USING_FAST_MALLOC(GridCoordinate); | 131 USING_FAST_MALLOC(GridCoordinate); |
125 public: | 132 public: |
126 // HashMap requires a default constuctor. | 133 // HashMap requires a default constuctor. |
127 GridCoordinate() | 134 GridCoordinate() |
128 : columns(GridSpan::indefiniteGridSpan()) | 135 : columns(GridSpan::indefiniteGridSpan()) |
(...skipping 19 matching lines...) Expand all Loading... | |
148 | 155 |
149 GridSpan columns; | 156 GridSpan columns; |
150 GridSpan rows; | 157 GridSpan rows; |
151 }; | 158 }; |
152 | 159 |
153 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; | 160 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; |
154 | 161 |
155 } // namespace blink | 162 } // namespace blink |
156 | 163 |
157 #endif // GridCoordinate_h | 164 #endif // GridCoordinate_h |
OLD | NEW |