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" |
| 9 #include "core/layout/ng/ng_direction.h" |
| 10 #include "core/layout/ng/ng_writing_mode.h" |
8 #include "platform/LayoutUnit.h" | 11 #include "platform/LayoutUnit.h" |
9 | 12 |
10 namespace blink { | 13 namespace blink { |
11 | 14 |
12 class LayoutUnit; | 15 class LayoutUnit; |
| 16 struct NGPhysicalOffset; |
| 17 struct NGPhysicalSize; |
13 | 18 |
14 struct NGLogicalSize { | 19 struct NGLogicalSize { |
15 NGLogicalSize() {} | 20 NGLogicalSize() {} |
16 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) | 21 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) |
17 : inline_size(inline_size), block_size(block_size) {} | 22 : inline_size(inline_size), block_size(block_size) {} |
18 | 23 |
19 LayoutUnit inline_size; | 24 LayoutUnit inline_size; |
20 LayoutUnit block_size; | 25 LayoutUnit block_size; |
| 26 |
| 27 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; |
21 }; | 28 }; |
22 | 29 |
| 30 // NGLogicalOffset is the position of a rect (typically a fragment) relative to |
| 31 // its parent rect in the logical coordinate system. |
23 struct NGLogicalOffset { | 32 struct NGLogicalOffset { |
| 33 NGLogicalOffset() {} |
| 34 NGLogicalOffset(LayoutUnit inline_offset, LayoutUnit block_offset) |
| 35 : inline_offset(inline_offset), block_offset(block_offset) {} |
| 36 |
24 LayoutUnit inline_offset; | 37 LayoutUnit inline_offset; |
25 LayoutUnit block_offset; | 38 LayoutUnit block_offset; |
| 39 |
| 40 // Converts a logical offset to a physical offset. See: |
| 41 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
| 42 // @param container_size the size of the rect (typically a fragment). |
| 43 // @param inner_size the size of the inner rect (typically a child fragment). |
| 44 CORE_EXPORT NGPhysicalOffset |
| 45 ConvertToPhysical(NGWritingMode mode, |
| 46 NGDirection direction, |
| 47 NGPhysicalSize container_size, |
| 48 NGPhysicalSize inner_size) const; |
| 49 }; |
| 50 |
| 51 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to |
| 52 // its parent rect in the physical coordinate system. |
| 53 struct NGPhysicalOffset { |
| 54 NGPhysicalOffset() {} |
| 55 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} |
| 56 |
| 57 LayoutUnit left; |
| 58 LayoutUnit top; |
26 }; | 59 }; |
27 | 60 |
28 struct NGPhysicalSize { | 61 struct NGPhysicalSize { |
29 NGPhysicalSize() {} | 62 NGPhysicalSize() {} |
30 NGPhysicalSize(LayoutUnit width, LayoutUnit height) | 63 NGPhysicalSize(LayoutUnit width, LayoutUnit height) |
31 : width(width), height(height) {} | 64 : width(width), height(height) {} |
32 | 65 |
33 LayoutUnit width; | 66 LayoutUnit width; |
34 LayoutUnit height; | 67 LayoutUnit height; |
| 68 |
| 69 NGLogicalSize ConvertToLogical(NGWritingMode mode) const; |
35 }; | 70 }; |
36 | 71 |
| 72 // NGPhysicalLocation is the position of a rect (typically a fragment) relative |
| 73 // to the root document. |
37 struct NGPhysicalLocation { | 74 struct NGPhysicalLocation { |
| 75 LayoutUnit left; |
38 LayoutUnit top; | 76 LayoutUnit top; |
39 LayoutUnit left; | |
40 }; | 77 }; |
41 | 78 |
42 struct NGPhysicalRect { | 79 struct NGPhysicalRect { |
43 NGPhysicalSize size; | 80 NGPhysicalSize size; |
44 NGPhysicalLocation location; | 81 NGPhysicalLocation location; |
45 }; | 82 }; |
46 | 83 |
47 struct NGPixelSnappedPhysicalRect { | 84 struct NGPixelSnappedPhysicalRect { |
48 int top; | 85 int top; |
49 int left; | 86 int left; |
50 int width; | 87 int width; |
51 int height; | 88 int height; |
52 }; | 89 }; |
53 | 90 |
54 // This struct is used for storing margins, borders or padding of a box on all | 91 // This struct is used for storing margins, borders or padding of a box on all |
55 // four edges. | 92 // four edges. |
56 struct NGBoxStrut { | 93 struct NGBoxStrut { |
57 LayoutUnit inline_start; | 94 LayoutUnit inline_start; |
58 LayoutUnit inline_end; | 95 LayoutUnit inline_end; |
59 LayoutUnit block_start; | 96 LayoutUnit block_start; |
60 LayoutUnit block_end; | 97 LayoutUnit block_end; |
61 | 98 |
62 LayoutUnit InlineSum() const { return inline_start + inline_end; } | 99 LayoutUnit InlineSum() const { return inline_start + inline_end; } |
63 LayoutUnit BlockSum() const { return block_start + block_end; } | 100 LayoutUnit BlockSum() const { return block_start + block_end; } |
64 }; | 101 }; |
65 | 102 |
66 } // namespace blink | 103 } // namespace blink |
67 | 104 |
68 #endif // NGUnits_h | 105 #endif // NGUnits_h |
OLD | NEW |