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 #include "core/layout/ng/ng_units.h" | 5 #include "core/layout/ng/ng_units.h" |
6 | 6 |
7 #include "core/layout/ng/ng_writing_mode.h" | 7 #include "core/layout/ng/ng_writing_mode.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { | 11 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { |
12 return mode == HorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) | 12 return mode == HorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) |
13 : NGPhysicalSize(block_size, inline_size); | 13 : NGPhysicalSize(block_size, inline_size); |
14 } | 14 } |
15 | 15 |
| 16 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { |
| 17 return std::tie(other.inline_size, other.block_size) == |
| 18 std::tie(inline_size, block_size); |
| 19 } |
| 20 |
16 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const { | 21 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const { |
17 return mode == HorizontalTopBottom ? NGLogicalSize(width, height) | 22 return mode == HorizontalTopBottom ? NGLogicalSize(width, height) |
18 : NGLogicalSize(height, width); | 23 : NGLogicalSize(height, width); |
19 } | 24 } |
20 | 25 |
| 26 bool NGLogicalRect::IsEmpty() const { |
| 27 // TODO(layout-dev): equality check shouldn't allocate an object each time. |
| 28 return *this == NGLogicalRect(); |
| 29 } |
| 30 |
| 31 bool NGLogicalRect::operator==(const NGLogicalRect& other) const { |
| 32 return std::tie(other.offset, other.size) == std::tie(offset, size); |
| 33 } |
| 34 |
| 35 String NGLogicalRect::ToString() const { |
| 36 return String::format("%s,%s %sx%s", |
| 37 offset.inline_offset.toString().ascii().data(), |
| 38 offset.block_offset.toString().ascii().data(), |
| 39 size.inline_size.toString().ascii().data(), |
| 40 size.block_size.toString().ascii().data()); |
| 41 } |
| 42 |
21 NGPhysicalOffset NGLogicalOffset::ConvertToPhysical( | 43 NGPhysicalOffset NGLogicalOffset::ConvertToPhysical( |
22 NGWritingMode mode, | 44 NGWritingMode mode, |
23 NGDirection direction, | 45 NGDirection direction, |
24 NGPhysicalSize container_size, | 46 NGPhysicalSize container_size, |
25 NGPhysicalSize inner_size) const { | 47 NGPhysicalSize inner_size) const { |
26 switch (mode) { | 48 switch (mode) { |
27 case HorizontalTopBottom: | 49 case HorizontalTopBottom: |
28 if (direction == LeftToRight) | 50 if (direction == LeftToRight) |
29 return NGPhysicalOffset(inline_offset, block_offset); | 51 return NGPhysicalOffset(inline_offset, block_offset); |
30 else | 52 else |
(...skipping 23 matching lines...) Expand all Loading... |
54 block_offset, | 76 block_offset, |
55 container_size.height - inline_offset - inner_size.height); | 77 container_size.height - inline_offset - inner_size.height); |
56 else | 78 else |
57 return NGPhysicalOffset(block_offset, inline_offset); | 79 return NGPhysicalOffset(block_offset, inline_offset); |
58 default: | 80 default: |
59 ASSERT_NOT_REACHED(); | 81 ASSERT_NOT_REACHED(); |
60 return NGPhysicalOffset(); | 82 return NGPhysicalOffset(); |
61 } | 83 } |
62 } | 84 } |
63 | 85 |
| 86 bool NGLogicalOffset::operator==(const NGLogicalOffset& other) const { |
| 87 return std::tie(other.inline_offset, other.block_offset) == |
| 88 std::tie(inline_offset, block_offset); |
| 89 } |
| 90 |
64 bool NGBoxStrut::IsEmpty() const { | 91 bool NGBoxStrut::IsEmpty() const { |
65 return *this == NGBoxStrut(); | 92 return *this == NGBoxStrut(); |
66 } | 93 } |
67 | 94 |
68 bool NGBoxStrut::operator==(const NGBoxStrut& other) const { | 95 bool NGBoxStrut::operator==(const NGBoxStrut& other) const { |
69 return std::tie(other.inline_start, other.inline_end, other.block_start, | 96 return std::tie(other.inline_start, other.inline_end, other.block_start, |
70 other.block_end) == | 97 other.block_end) == |
71 std::tie(inline_start, inline_end, block_start, block_end); | 98 std::tie(inline_start, inline_end, block_start, block_end); |
72 } | 99 } |
73 | 100 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 149 |
123 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { | 150 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { |
124 return std::tie(other.margin_block_start, other.margin_block_end, | 151 return std::tie(other.margin_block_start, other.margin_block_end, |
125 other.negative_margin_block_start, | 152 other.negative_margin_block_start, |
126 other.negative_margin_block_end) == | 153 other.negative_margin_block_end) == |
127 std::tie(margin_block_start, margin_block_end, | 154 std::tie(margin_block_start, margin_block_end, |
128 negative_margin_block_start, negative_margin_block_end); | 155 negative_margin_block_start, negative_margin_block_end); |
129 } | 156 } |
130 | 157 |
131 } // namespace blink | 158 } // namespace blink |
OLD | NEW |