OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef NGUnits_h | 5 #ifndef NGUnits_h |
6 #define NGUnits_h | 6 #define NGUnits_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/ng/ng_direction.h" | 9 #include "core/layout/ng/ng_direction.h" |
10 #include "core/layout/ng/ng_writing_mode.h" | 10 #include "core/layout/ng/ng_writing_mode.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 struct NGPhysicalLocation { | 85 struct NGPhysicalLocation { |
86 LayoutUnit left; | 86 LayoutUnit left; |
87 LayoutUnit top; | 87 LayoutUnit top; |
88 }; | 88 }; |
89 | 89 |
90 struct NGPhysicalRect { | 90 struct NGPhysicalRect { |
91 NGPhysicalOffset offset; | 91 NGPhysicalOffset offset; |
92 NGPhysicalSize size; | 92 NGPhysicalSize size; |
93 }; | 93 }; |
94 | 94 |
95 // TODO(glebl): move to a separate file in layout/ng/units. | |
95 struct CORE_EXPORT NGLogicalRect { | 96 struct CORE_EXPORT NGLogicalRect { |
96 NGLogicalRect() {} | 97 NGLogicalRect() {} |
98 // TODO(glebl): Make this private and use the builder everywhere. | |
97 NGLogicalRect(LayoutUnit inline_offset, | 99 NGLogicalRect(LayoutUnit inline_offset, |
98 LayoutUnit block_offset, | 100 LayoutUnit block_offset, |
99 LayoutUnit inline_size, | 101 LayoutUnit inline_size, |
100 LayoutUnit block_size) | 102 LayoutUnit block_size) |
101 : offset(inline_offset, block_offset), size(inline_size, block_size) {} | 103 : offset(inline_offset, block_offset), size(inline_size, block_size) {} |
102 | 104 |
103 bool IsEmpty() const; | 105 bool IsEmpty() const; |
106 | |
107 // Whether this rectangle within the provided rectangle. | |
108 bool IsWithin(const NGLogicalRect& other) const; | |
109 | |
104 String ToString() const; | 110 String ToString() const; |
105 bool operator==(const NGLogicalRect& other) const; | 111 bool operator==(const NGLogicalRect& other) const; |
106 | 112 |
113 // Getters | |
114 LayoutUnit InlineStartOffset() const { return offset.inline_offset; } | |
115 | |
116 LayoutUnit InlineEndOffset() const { | |
117 return offset.inline_offset + size.inline_size; | |
118 } | |
119 | |
120 LayoutUnit BlockStartOffset() const { return offset.block_offset; } | |
121 | |
122 LayoutUnit BlockEndOffset() const { | |
123 return offset.block_offset + size.block_size; | |
124 } | |
125 | |
126 LayoutUnit BlockSize() const { return size.block_size; } | |
127 | |
128 LayoutUnit InlineSize() const { return size.inline_size; } | |
129 | |
130 class Builder { | |
ikilpatrick
2016/10/28 23:18:24
yeah, i'm not sold on using the builder for these
Gleb Lanbin
2016/10/28 23:54:09
yes, I'm not a 100% fan of it either because it's
| |
131 public: | |
132 Builder() = default; | |
133 | |
134 Builder& SetInlineOffset(const LayoutUnit& inline_offset) { | |
135 inline_offset_ = inline_offset; | |
136 return *this; | |
137 } | |
138 | |
139 Builder& SetBlockOffset(const LayoutUnit& block_offset) { | |
140 block_offset_ = block_offset; | |
141 return *this; | |
142 } | |
143 | |
144 Builder& SetInlineSize(const LayoutUnit& inline_size) { | |
145 inline_size_ = inline_size; | |
146 return *this; | |
147 } | |
148 | |
149 Builder& SetBlockSize(const LayoutUnit& block_size) { | |
150 block_size_ = block_size; | |
151 return *this; | |
152 } | |
153 | |
154 NGLogicalRect* BuildNew() { | |
155 return new NGLogicalRect(inline_offset_, block_offset_, inline_size_, | |
156 block_size_); | |
157 } | |
158 | |
159 NGLogicalRect Build() { | |
160 return NGLogicalRect(inline_offset_, block_offset_, inline_size_, | |
161 block_size_); | |
162 } | |
163 | |
164 private: | |
165 LayoutUnit inline_offset_; | |
166 LayoutUnit block_offset_; | |
167 LayoutUnit inline_size_; | |
168 LayoutUnit block_size_; | |
169 DISALLOW_COPY_AND_ASSIGN(Builder); | |
170 }; | |
171 | |
107 NGLogicalOffset offset; | 172 NGLogicalOffset offset; |
108 NGLogicalSize size; | 173 NGLogicalSize size; |
109 }; | 174 }; |
110 | 175 |
111 inline std::ostream& operator<<(std::ostream& stream, | 176 inline std::ostream& operator<<(std::ostream& stream, |
112 const NGLogicalRect& value) { | 177 const NGLogicalRect& value) { |
113 return stream << value.ToString(); | 178 return stream << value.ToString(); |
114 } | 179 } |
115 | 180 |
116 struct NGPixelSnappedPhysicalRect { | 181 struct NGPixelSnappedPhysicalRect { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 | 256 |
192 // Struct to represent a simple edge that has start and end. | 257 // Struct to represent a simple edge that has start and end. |
193 struct NGEdge { | 258 struct NGEdge { |
194 LayoutUnit start; | 259 LayoutUnit start; |
195 LayoutUnit end; | 260 LayoutUnit end; |
196 }; | 261 }; |
197 | 262 |
198 } // namespace blink | 263 } // namespace blink |
199 | 264 |
200 #endif // NGUnits_h | 265 #endif // NGUnits_h |
OLD | NEW |