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 11 matching lines...) Expand all Loading... |
71 }; | 73 }; |
72 | 74 |
73 // NGPhysicalLocation is the position of a rect (typically a fragment) relative | 75 // NGPhysicalLocation is the position of a rect (typically a fragment) relative |
74 // to the root document. | 76 // to the root document. |
75 struct NGPhysicalLocation { | 77 struct NGPhysicalLocation { |
76 LayoutUnit left; | 78 LayoutUnit left; |
77 LayoutUnit top; | 79 LayoutUnit top; |
78 }; | 80 }; |
79 | 81 |
80 struct NGPhysicalRect { | 82 struct NGPhysicalRect { |
| 83 NGPhysicalOffset offset; |
81 NGPhysicalSize size; | 84 NGPhysicalSize size; |
82 NGPhysicalLocation location; | |
83 }; | 85 }; |
84 | 86 |
| 87 struct CORE_EXPORT NGLogicalRect { |
| 88 NGLogicalRect() {} |
| 89 NGLogicalRect(LayoutUnit inline_offset, |
| 90 LayoutUnit block_offset, |
| 91 LayoutUnit inline_size, |
| 92 LayoutUnit block_size) |
| 93 : offset(inline_offset, block_offset), size(inline_size, block_size) {} |
| 94 |
| 95 bool IsEmpty() const; |
| 96 String ToString() const; |
| 97 bool operator==(const NGLogicalRect& other) const; |
| 98 |
| 99 NGLogicalOffset offset; |
| 100 NGLogicalSize size; |
| 101 }; |
| 102 |
| 103 inline std::ostream& operator<<(std::ostream& stream, |
| 104 const NGLogicalRect& value) { |
| 105 return stream << value.ToString(); |
| 106 } |
| 107 |
85 struct NGPixelSnappedPhysicalRect { | 108 struct NGPixelSnappedPhysicalRect { |
86 int top; | 109 int top; |
87 int left; | 110 int left; |
88 int width; | 111 int width; |
89 int height; | 112 int height; |
90 }; | 113 }; |
91 | 114 |
92 // Struct to store physical dimensions, independent of writing mode and | 115 // Struct to store physical dimensions, independent of writing mode and |
93 // direction. | 116 // direction. |
94 // See https://drafts.csswg.org/css-writing-modes-3/#abstract-box | 117 // See https://drafts.csswg.org/css-writing-modes-3/#abstract-box |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 183 |
161 // Struct to represent a simple edge that has start and end. | 184 // Struct to represent a simple edge that has start and end. |
162 struct NGEdge { | 185 struct NGEdge { |
163 LayoutUnit start; | 186 LayoutUnit start; |
164 LayoutUnit end; | 187 LayoutUnit end; |
165 }; | 188 }; |
166 | 189 |
167 } // namespace blink | 190 } // namespace blink |
168 | 191 |
169 #endif // NGUnits_h | 192 #endif // NGUnits_h |
OLD | NEW |