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_writing_mode.h" | 9 #include "core/layout/ng/ng_writing_mode.h" |
10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 LayoutUnit inline_size; | 38 LayoutUnit inline_size; |
39 LayoutUnit block_size; | 39 LayoutUnit block_size; |
40 | 40 |
41 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; | 41 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; |
42 bool operator==(const NGLogicalSize& other) const; | 42 bool operator==(const NGLogicalSize& other) const; |
43 | 43 |
44 bool IsEmpty() const { | 44 bool IsEmpty() const { |
45 return inline_size == LayoutUnit() || block_size == LayoutUnit(); | 45 return inline_size == LayoutUnit() || block_size == LayoutUnit(); |
46 } | 46 } |
47 | |
48 private: | |
49 friend class NGBlockLayoutAlgorithmTest; | |
ikilpatrick
2017/01/24 00:22:13
can you ad a comment here as to why friend class?
Gleb Lanbin
2017/01/24 04:38:02
Done.
| |
50 NGLogicalSize(int inline_size, int block_size) | |
51 : inline_size(LayoutUnit(inline_size)), | |
52 block_size(LayoutUnit(block_size)) {} | |
47 }; | 53 }; |
48 | 54 |
49 inline std::ostream& operator<<(std::ostream& stream, | 55 inline std::ostream& operator<<(std::ostream& stream, |
50 const NGLogicalSize& value) { | 56 const NGLogicalSize& value) { |
51 return stream << value.inline_size << "x" << value.block_size; | 57 return stream << value.inline_size << "x" << value.block_size; |
52 } | 58 } |
53 | 59 |
54 // NGLogicalOffset is the position of a rect (typically a fragment) relative to | 60 // NGLogicalOffset is the position of a rect (typically a fragment) relative to |
55 // its parent rect in the logical coordinate system. | 61 // its parent rect in the logical coordinate system. |
56 struct NGLogicalOffset { | 62 struct NGLogicalOffset { |
(...skipping 13 matching lines...) Expand all Loading... | |
70 // @param inner_size the size of the inner rect (typically a child fragment). | 76 // @param inner_size the size of the inner rect (typically a child fragment). |
71 CORE_EXPORT NGPhysicalOffset | 77 CORE_EXPORT NGPhysicalOffset |
72 ConvertToPhysical(NGWritingMode, | 78 ConvertToPhysical(NGWritingMode, |
73 TextDirection, | 79 TextDirection, |
74 NGPhysicalSize outer_size, | 80 NGPhysicalSize outer_size, |
75 NGPhysicalSize inner_size) const; | 81 NGPhysicalSize inner_size) const; |
76 | 82 |
77 bool operator==(const NGLogicalOffset& other) const; | 83 bool operator==(const NGLogicalOffset& other) const; |
78 | 84 |
79 NGLogicalOffset operator+(const NGLogicalOffset& other) const; | 85 NGLogicalOffset operator+(const NGLogicalOffset& other) const; |
86 NGLogicalOffset& operator+=(const NGLogicalOffset& other); | |
80 | 87 |
81 NGLogicalOffset& operator+=(const NGLogicalOffset& other); | 88 NGLogicalOffset operator-(const NGLogicalOffset& other) const; |
89 NGLogicalOffset& operator-=(const NGLogicalOffset& other); | |
82 | 90 |
83 bool operator>(const NGLogicalOffset& other) const; | 91 bool operator>(const NGLogicalOffset& other) const; |
84 bool operator>=(const NGLogicalOffset& other) const; | 92 bool operator>=(const NGLogicalOffset& other) const; |
85 | 93 |
86 bool operator<(const NGLogicalOffset& other) const; | 94 bool operator<(const NGLogicalOffset& other) const; |
87 bool operator<=(const NGLogicalOffset& other) const; | 95 bool operator<=(const NGLogicalOffset& other) const; |
88 | 96 |
89 String ToString() const; | 97 String ToString() const; |
98 | |
99 private: | |
100 friend class NGBlockLayoutAlgorithmTest; | |
ikilpatrick
2017/01/24 00:22:13
as above.
Gleb Lanbin
2017/01/24 04:38:02
Done.
| |
101 NGLogicalOffset(int inline_offset, int block_offset) | |
102 : inline_offset(LayoutUnit(inline_offset)), | |
103 block_offset(LayoutUnit(block_offset)) {} | |
90 }; | 104 }; |
91 | 105 |
92 CORE_EXPORT inline std::ostream& operator<<(std::ostream& os, | 106 CORE_EXPORT inline std::ostream& operator<<(std::ostream& os, |
93 const NGLogicalOffset& value) { | 107 const NGLogicalOffset& value) { |
94 return os << value.ToString(); | 108 return os << value.ToString(); |
95 } | 109 } |
96 | 110 |
97 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to | 111 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to |
98 // its parent rect in the physical coordinate system. | 112 // its parent rect in the physical coordinate system. |
99 struct NGPhysicalOffset { | 113 struct NGPhysicalOffset { |
100 NGPhysicalOffset() {} | 114 NGPhysicalOffset() {} |
101 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} | 115 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} |
102 | 116 |
103 LayoutUnit left; | 117 LayoutUnit left; |
104 LayoutUnit top; | 118 LayoutUnit top; |
105 | 119 |
106 NGPhysicalOffset operator+(const NGPhysicalOffset& other) const; | 120 NGPhysicalOffset operator+(const NGPhysicalOffset& other) const; |
107 NGPhysicalOffset& operator+=(const NGPhysicalOffset& other); | 121 NGPhysicalOffset& operator+=(const NGPhysicalOffset& other); |
122 | |
108 NGPhysicalOffset operator-(const NGPhysicalOffset& other) const; | 123 NGPhysicalOffset operator-(const NGPhysicalOffset& other) const; |
109 NGPhysicalOffset& operator-=(const NGPhysicalOffset& other); | 124 NGPhysicalOffset& operator-=(const NGPhysicalOffset& other); |
125 | |
126 String ToString() const { | |
127 return String::format("%dx%d", left.toInt(), top.toInt()); | |
128 } | |
110 }; | 129 }; |
111 | 130 |
112 struct NGPhysicalSize { | 131 struct NGPhysicalSize { |
113 NGPhysicalSize() {} | 132 NGPhysicalSize() {} |
114 NGPhysicalSize(LayoutUnit width, LayoutUnit height) | 133 NGPhysicalSize(LayoutUnit width, LayoutUnit height) |
115 : width(width), height(height) {} | 134 : width(width), height(height) {} |
116 | 135 |
117 LayoutUnit width; | 136 LayoutUnit width; |
118 LayoutUnit height; | 137 LayoutUnit height; |
119 | 138 |
(...skipping 12 matching lines...) Expand all Loading... | |
132 }; | 151 }; |
133 | 152 |
134 struct NGPhysicalRect { | 153 struct NGPhysicalRect { |
135 NGPhysicalOffset offset; | 154 NGPhysicalOffset offset; |
136 NGPhysicalSize size; | 155 NGPhysicalSize size; |
137 }; | 156 }; |
138 | 157 |
139 // TODO(glebl): move to a separate file in layout/ng/units. | 158 // TODO(glebl): move to a separate file in layout/ng/units. |
140 struct CORE_EXPORT NGLogicalRect { | 159 struct CORE_EXPORT NGLogicalRect { |
141 NGLogicalRect() {} | 160 NGLogicalRect() {} |
161 NGLogicalRect(const NGLogicalOffset& offset, const NGLogicalSize& size) | |
162 : offset(offset), size(size) {} | |
142 NGLogicalRect(LayoutUnit inline_offset, | 163 NGLogicalRect(LayoutUnit inline_offset, |
143 LayoutUnit block_offset, | 164 LayoutUnit block_offset, |
144 LayoutUnit inline_size, | 165 LayoutUnit inline_size, |
145 LayoutUnit block_size) | 166 LayoutUnit block_size) |
146 : offset(inline_offset, block_offset), size(inline_size, block_size) {} | 167 : offset(inline_offset, block_offset), size(inline_size, block_size) {} |
147 | 168 |
148 bool IsEmpty() const; | 169 bool IsEmpty() const; |
149 | 170 |
150 // Whether this rectangle is contained by the provided rectangle. | 171 // Whether this rectangle is contained by the provided rectangle. |
151 bool IsContained(const NGLogicalRect& other) const; | 172 bool IsContained(const NGLogicalRect& other) const; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 kFloatLeft = 1, | 211 kFloatLeft = 1, |
191 // Exclusion that is created by RIGHT float. | 212 // Exclusion that is created by RIGHT float. |
192 kFloatRight = 2 | 213 kFloatRight = 2 |
193 }; | 214 }; |
194 | 215 |
195 // Rectangle in logical coordinates the represents this exclusion. | 216 // Rectangle in logical coordinates the represents this exclusion. |
196 NGLogicalRect rect; | 217 NGLogicalRect rect; |
197 | 218 |
198 // Type of this exclusion. | 219 // Type of this exclusion. |
199 Type type; | 220 Type type; |
221 | |
222 bool operator==(const NGExclusion& other) const; | |
223 String ToString() const; | |
200 }; | 224 }; |
201 | 225 |
226 inline std::ostream& operator<<(std::ostream& stream, | |
227 const NGExclusion& value) { | |
228 return stream << value.ToString(); | |
229 } | |
230 | |
202 struct CORE_EXPORT NGExclusions { | 231 struct CORE_EXPORT NGExclusions { |
203 // Default constructor. | 232 // Default constructor. |
204 NGExclusions(); | 233 NGExclusions(); |
205 | 234 |
206 // Copy constructor. | 235 // Copy constructor. |
207 NGExclusions(const NGExclusions& other); | 236 NGExclusions(const NGExclusions& other); |
208 | 237 |
209 Vector<std::unique_ptr<const NGExclusion>> storage; | 238 Vector<std::unique_ptr<const NGExclusion>> storage; |
210 | 239 |
211 // Last left/right float exclusions are used to enforce the top edge alignment | 240 // Last left/right float exclusions are used to enforce the top edge alignment |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 return *this; | 288 return *this; |
260 } | 289 } |
261 | 290 |
262 NGBoxStrut operator+(const NGBoxStrut& other) { | 291 NGBoxStrut operator+(const NGBoxStrut& other) { |
263 NGBoxStrut result(*this); | 292 NGBoxStrut result(*this); |
264 result += other; | 293 result += other; |
265 return result; | 294 return result; |
266 } | 295 } |
267 | 296 |
268 bool operator==(const NGBoxStrut& other) const; | 297 bool operator==(const NGBoxStrut& other) const; |
298 | |
299 String ToString() const { | |
300 return String::format("Inline: (%d %d) Block: (%d %d)", | |
301 inline_start.toInt(), inline_end.toInt(), | |
302 block_start.toInt(), block_end.toInt()); | |
303 } | |
269 }; | 304 }; |
270 | 305 |
306 inline std::ostream& operator<<(std::ostream& stream, const NGBoxStrut& value) { | |
307 return stream << value.ToString(); | |
308 } | |
309 | |
271 // This struct is used for the margin collapsing calculation. | 310 // This struct is used for the margin collapsing calculation. |
272 struct CORE_EXPORT NGMarginStrut { | 311 // TODO(glebl): Deprecated. It's being replaced by NGMarginStrut |
312 struct CORE_EXPORT NGDeprecatedMarginStrut { | |
273 LayoutUnit margin_block_start; | 313 LayoutUnit margin_block_start; |
274 LayoutUnit margin_block_end; | 314 LayoutUnit margin_block_end; |
275 | 315 |
276 LayoutUnit negative_margin_block_start; | 316 LayoutUnit negative_margin_block_start; |
277 LayoutUnit negative_margin_block_end; | 317 LayoutUnit negative_margin_block_end; |
278 | 318 |
279 LayoutUnit BlockEndSum() const; | 319 LayoutUnit BlockEndSum() const; |
280 | 320 |
281 void AppendMarginBlockStart(const LayoutUnit& value); | 321 void AppendMarginBlockStart(const LayoutUnit& value); |
282 void AppendMarginBlockEnd(const LayoutUnit& value); | 322 void AppendMarginBlockEnd(const LayoutUnit& value); |
283 void SetMarginBlockStart(const LayoutUnit& value); | 323 void SetMarginBlockStart(const LayoutUnit& value); |
284 void SetMarginBlockEnd(const LayoutUnit& value); | 324 void SetMarginBlockEnd(const LayoutUnit& value); |
285 | 325 |
286 bool IsEmpty() const; | 326 bool IsEmpty() const; |
287 | 327 |
288 String ToString() const; | 328 String ToString() const; |
289 | 329 |
330 bool operator==(const NGDeprecatedMarginStrut& other) const; | |
331 }; | |
332 | |
333 // This struct is used for the margin collapsing calculation. | |
334 struct CORE_EXPORT NGMarginStrut { | |
335 LayoutUnit margin; | |
336 LayoutUnit negative_margin; | |
337 | |
290 bool operator==(const NGMarginStrut& other) const; | 338 bool operator==(const NGMarginStrut& other) const; |
339 | |
340 void Append(const LayoutUnit& value); | |
341 | |
342 LayoutUnit Collapse() const; | |
343 | |
344 LayoutUnit CollapseWith(const NGMarginStrut& other) const; | |
345 | |
346 String ToString() const; | |
291 }; | 347 }; |
292 | 348 |
293 inline std::ostream& operator<<(std::ostream& stream, | 349 inline std::ostream& operator<<(std::ostream& stream, |
294 const NGMarginStrut& value) { | 350 const NGMarginStrut& value) { |
295 return stream << value.ToString(); | 351 return stream << value.ToString(); |
296 } | 352 } |
297 | 353 |
298 // Struct to represent a simple edge that has start and end. | 354 // Struct to represent a simple edge that has start and end. |
299 struct NGEdge { | 355 struct NGEdge { |
300 LayoutUnit start; | 356 LayoutUnit start; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 if (position_matches) | 408 if (position_matches) |
353 return position; | 409 return position; |
354 else | 410 else |
355 return container_size - position - length - margin_start - margin_end; | 411 return container_size - position - length - margin_start - margin_end; |
356 } | 412 } |
357 }; | 413 }; |
358 | 414 |
359 } // namespace blink | 415 } // namespace blink |
360 | 416 |
361 #endif // NGUnits_h | 417 #endif // NGUnits_h |
OLD | NEW |