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" |
11 #include "platform/LayoutUnit.h" | 11 #include "platform/LayoutUnit.h" |
12 #include "wtf/text/WTFString.h" | 12 #include "wtf/text/WTFString.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class LayoutUnit; | 16 class LayoutUnit; |
17 struct NGPhysicalOffset; | 17 struct NGPhysicalOffset; |
18 struct NGPhysicalSize; | 18 struct NGPhysicalSize; |
19 | 19 |
20 struct NGLogicalSize { | 20 struct NGLogicalSize { |
21 NGLogicalSize() {} | 21 NGLogicalSize() {} |
22 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) | 22 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) |
23 : inline_size(inline_size), block_size(block_size) {} | 23 : inline_size(inline_size), block_size(block_size) {} |
24 | 24 |
25 LayoutUnit inline_size; | 25 LayoutUnit inline_size; |
26 LayoutUnit block_size; | 26 LayoutUnit block_size; |
27 | 27 |
28 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; | 28 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; |
| 29 bool operator==(const NGLogicalSize& other) const; |
29 }; | 30 }; |
30 | 31 |
31 // NGLogicalOffset is the position of a rect (typically a fragment) relative to | 32 // NGLogicalOffset is the position of a rect (typically a fragment) relative to |
32 // its parent rect in the logical coordinate system. | 33 // its parent rect in the logical coordinate system. |
33 struct NGLogicalOffset { | 34 struct NGLogicalOffset { |
34 NGLogicalOffset() {} | 35 NGLogicalOffset() {} |
35 NGLogicalOffset(LayoutUnit inline_offset, LayoutUnit block_offset) | 36 NGLogicalOffset(LayoutUnit inline_offset, LayoutUnit block_offset) |
36 : inline_offset(inline_offset), block_offset(block_offset) {} | 37 : inline_offset(inline_offset), block_offset(block_offset) {} |
37 | 38 |
38 LayoutUnit inline_offset; | 39 LayoutUnit inline_offset; |
39 LayoutUnit block_offset; | 40 LayoutUnit block_offset; |
40 | 41 |
41 // Converts a logical offset to a physical offset. See: | 42 // Converts a logical offset to a physical offset. See: |
42 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical | 43 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
43 // @param container_size the size of the rect (typically a fragment). | 44 // @param container_size the size of the rect (typically a fragment). |
44 // @param inner_size the size of the inner rect (typically a child fragment). | 45 // @param inner_size the size of the inner rect (typically a child fragment). |
45 CORE_EXPORT NGPhysicalOffset | 46 CORE_EXPORT NGPhysicalOffset |
46 ConvertToPhysical(NGWritingMode mode, | 47 ConvertToPhysical(NGWritingMode mode, |
47 NGDirection direction, | 48 NGDirection direction, |
48 NGPhysicalSize container_size, | 49 NGPhysicalSize container_size, |
49 NGPhysicalSize inner_size) const; | 50 NGPhysicalSize inner_size) const; |
| 51 bool operator==(const NGLogicalOffset& other) const; |
50 }; | 52 }; |
51 | 53 |
52 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to | 54 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to |
53 // its parent rect in the physical coordinate system. | 55 // its parent rect in the physical coordinate system. |
54 struct NGPhysicalOffset { | 56 struct NGPhysicalOffset { |
55 NGPhysicalOffset() {} | 57 NGPhysicalOffset() {} |
56 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} | 58 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} |
57 | 59 |
58 LayoutUnit left; | 60 LayoutUnit left; |
59 LayoutUnit top; | 61 LayoutUnit top; |
(...skipping 15 matching lines...) Expand all Loading... |
75 }; | 77 }; |
76 | 78 |
77 // NGPhysicalLocation is the position of a rect (typically a fragment) relative | 79 // NGPhysicalLocation is the position of a rect (typically a fragment) relative |
78 // to the root document. | 80 // to the root document. |
79 struct NGPhysicalLocation { | 81 struct NGPhysicalLocation { |
80 LayoutUnit left; | 82 LayoutUnit left; |
81 LayoutUnit top; | 83 LayoutUnit top; |
82 }; | 84 }; |
83 | 85 |
84 struct NGPhysicalRect { | 86 struct NGPhysicalRect { |
| 87 NGPhysicalOffset offset; |
85 NGPhysicalSize size; | 88 NGPhysicalSize size; |
86 NGPhysicalLocation location; | |
87 }; | 89 }; |
88 | 90 |
| 91 struct CORE_EXPORT NGLogicalRect { |
| 92 NGLogicalRect() {} |
| 93 NGLogicalRect(LayoutUnit inline_offset, |
| 94 LayoutUnit block_offset, |
| 95 LayoutUnit inline_size, |
| 96 LayoutUnit block_size) |
| 97 : offset(inline_offset, block_offset), size(inline_size, block_size) {} |
| 98 |
| 99 bool IsEmpty() const; |
| 100 String ToString() const; |
| 101 bool operator==(const NGLogicalRect& other) const; |
| 102 |
| 103 NGLogicalOffset offset; |
| 104 NGLogicalSize size; |
| 105 }; |
| 106 |
| 107 inline std::ostream& operator<<(std::ostream& stream, |
| 108 const NGLogicalRect& value) { |
| 109 return stream << value.ToString(); |
| 110 } |
| 111 |
89 struct NGPixelSnappedPhysicalRect { | 112 struct NGPixelSnappedPhysicalRect { |
90 int top; | 113 int top; |
91 int left; | 114 int left; |
92 int width; | 115 int width; |
93 int height; | 116 int height; |
94 }; | 117 }; |
95 | 118 |
96 // Struct to store physical dimensions, independent of writing mode and | 119 // Struct to store physical dimensions, independent of writing mode and |
97 // direction. | 120 // direction. |
98 // See https://drafts.csswg.org/css-writing-modes-3/#abstract-box | 121 // See https://drafts.csswg.org/css-writing-modes-3/#abstract-box |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 187 |
165 // Struct to represent a simple edge that has start and end. | 188 // Struct to represent a simple edge that has start and end. |
166 struct NGEdge { | 189 struct NGEdge { |
167 LayoutUnit start; | 190 LayoutUnit start; |
168 LayoutUnit end; | 191 LayoutUnit end; |
169 }; | 192 }; |
170 | 193 |
171 } // namespace blink | 194 } // namespace blink |
172 | 195 |
173 #endif // NGUnits_h | 196 #endif // NGUnits_h |
OLD | NEW |