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 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const { | 11 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const { |
12 DCHECK_GE(max_content, min_content); | 12 DCHECK_GE(max_content, min_content); |
13 return std::min(max_content, std::max(min_content, available_size)); | 13 return std::min(max_content, std::max(min_content, available_size)); |
14 } | 14 } |
15 | 15 |
16 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { | 16 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { |
17 return mode == HorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) | 17 return mode == kHorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) |
18 : NGPhysicalSize(block_size, inline_size); | 18 : NGPhysicalSize(block_size, inline_size); |
19 } | 19 } |
20 | 20 |
21 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { | 21 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { |
22 return std::tie(other.inline_size, other.block_size) == | 22 return std::tie(other.inline_size, other.block_size) == |
23 std::tie(inline_size, block_size); | 23 std::tie(inline_size, block_size); |
24 } | 24 } |
25 | 25 |
26 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const { | 26 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const { |
27 return mode == HorizontalTopBottom ? NGLogicalSize(width, height) | 27 return mode == kHorizontalTopBottom ? NGLogicalSize(width, height) |
28 : NGLogicalSize(height, width); | 28 : NGLogicalSize(height, width); |
29 } | 29 } |
30 | 30 |
31 bool NGLogicalRect::IsEmpty() const { | 31 bool NGLogicalRect::IsEmpty() const { |
32 // TODO(layout-dev): equality check shouldn't allocate an object each time. | 32 // TODO(layout-dev): equality check shouldn't allocate an object each time. |
33 return *this == NGLogicalRect(); | 33 return *this == NGLogicalRect(); |
34 } | 34 } |
35 | 35 |
36 bool NGLogicalRect::IsContained(const NGLogicalRect& other) const { | 36 bool NGLogicalRect::IsContained(const NGLogicalRect& other) const { |
37 return !(InlineEndOffset() <= other.InlineStartOffset() || | 37 return !(InlineEndOffset() <= other.InlineStartOffset() || |
38 BlockEndOffset() <= other.BlockStartOffset() || | 38 BlockEndOffset() <= other.BlockStartOffset() || |
(...skipping 12 matching lines...) Expand all Loading... |
51 size.inline_size.toString().ascii().data(), | 51 size.inline_size.toString().ascii().data(), |
52 size.block_size.toString().ascii().data()); | 52 size.block_size.toString().ascii().data()); |
53 } | 53 } |
54 | 54 |
55 NGPhysicalOffset NGLogicalOffset::ConvertToPhysical( | 55 NGPhysicalOffset NGLogicalOffset::ConvertToPhysical( |
56 NGWritingMode mode, | 56 NGWritingMode mode, |
57 TextDirection direction, | 57 TextDirection direction, |
58 NGPhysicalSize outer_size, | 58 NGPhysicalSize outer_size, |
59 NGPhysicalSize inner_size) const { | 59 NGPhysicalSize inner_size) const { |
60 switch (mode) { | 60 switch (mode) { |
61 case HorizontalTopBottom: | 61 case kHorizontalTopBottom: |
62 if (direction == LTR) | 62 if (direction == LTR) |
63 return NGPhysicalOffset(inline_offset, block_offset); | 63 return NGPhysicalOffset(inline_offset, block_offset); |
64 else | 64 else |
65 return NGPhysicalOffset( | 65 return NGPhysicalOffset( |
66 outer_size.width - inline_offset - inner_size.width, block_offset); | 66 outer_size.width - inline_offset - inner_size.width, block_offset); |
67 case VerticalRightLeft: | 67 case kVerticalRightLeft: |
68 case SidewaysRightLeft: | 68 case kSidewaysRightLeft: |
69 if (direction == LTR) | 69 if (direction == LTR) |
70 return NGPhysicalOffset( | 70 return NGPhysicalOffset( |
71 outer_size.width - block_offset - inner_size.width, inline_offset); | 71 outer_size.width - block_offset - inner_size.width, inline_offset); |
72 else | 72 else |
73 return NGPhysicalOffset( | 73 return NGPhysicalOffset( |
74 outer_size.width - block_offset - inner_size.width, | 74 outer_size.width - block_offset - inner_size.width, |
75 outer_size.height - inline_offset - inner_size.height); | 75 outer_size.height - inline_offset - inner_size.height); |
76 case VerticalLeftRight: | 76 case kVerticalLeftRight: |
77 if (direction == LTR) | 77 if (direction == LTR) |
78 return NGPhysicalOffset(block_offset, inline_offset); | 78 return NGPhysicalOffset(block_offset, inline_offset); |
79 else | 79 else |
80 return NGPhysicalOffset( | 80 return NGPhysicalOffset( |
81 block_offset, | 81 block_offset, |
82 outer_size.height - inline_offset - inner_size.height); | 82 outer_size.height - inline_offset - inner_size.height); |
83 case SidewaysLeftRight: | 83 case kSidewaysLeftRight: |
84 if (direction == LTR) | 84 if (direction == LTR) |
85 return NGPhysicalOffset( | 85 return NGPhysicalOffset( |
86 block_offset, | 86 block_offset, |
87 outer_size.height - inline_offset - inner_size.height); | 87 outer_size.height - inline_offset - inner_size.height); |
88 else | 88 else |
89 return NGPhysicalOffset(block_offset, inline_offset); | 89 return NGPhysicalOffset(block_offset, inline_offset); |
90 default: | 90 default: |
91 ASSERT_NOT_REACHED(); | 91 ASSERT_NOT_REACHED(); |
92 return NGPhysicalOffset(); | 92 return NGPhysicalOffset(); |
93 } | 93 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 other.block_end) == | 143 other.block_end) == |
144 std::tie(inline_start, inline_end, block_start, block_end); | 144 std::tie(inline_start, inline_end, block_start, block_end); |
145 } | 145 } |
146 | 146 |
147 // Converts physical dimensions to logical ones per | 147 // Converts physical dimensions to logical ones per |
148 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical | 148 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
149 NGBoxStrut NGPhysicalBoxStrut::ConvertToLogical(NGWritingMode writing_mode, | 149 NGBoxStrut NGPhysicalBoxStrut::ConvertToLogical(NGWritingMode writing_mode, |
150 TextDirection direction) const { | 150 TextDirection direction) const { |
151 NGBoxStrut strut; | 151 NGBoxStrut strut; |
152 switch (writing_mode) { | 152 switch (writing_mode) { |
153 case HorizontalTopBottom: | 153 case kHorizontalTopBottom: |
154 strut = {left, right, top, bottom}; | 154 strut = {left, right, top, bottom}; |
155 break; | 155 break; |
156 case VerticalRightLeft: | 156 case kVerticalRightLeft: |
157 case SidewaysRightLeft: | 157 case kSidewaysRightLeft: |
158 strut = {top, bottom, right, left}; | 158 strut = {top, bottom, right, left}; |
159 break; | 159 break; |
160 case VerticalLeftRight: | 160 case kVerticalLeftRight: |
161 strut = {top, bottom, left, right}; | 161 strut = {top, bottom, left, right}; |
162 break; | 162 break; |
163 case SidewaysLeftRight: | 163 case kSidewaysLeftRight: |
164 strut = {bottom, top, left, right}; | 164 strut = {bottom, top, left, right}; |
165 break; | 165 break; |
166 } | 166 } |
167 if (direction == RTL) | 167 if (direction == RTL) |
168 std::swap(strut.inline_start, strut.inline_end); | 168 std::swap(strut.inline_start, strut.inline_end); |
169 return strut; | 169 return strut; |
170 } | 170 } |
171 | 171 |
172 LayoutUnit NGMarginStrut::BlockEndSum() const { | 172 LayoutUnit NGMarginStrut::BlockEndSum() const { |
173 return margin_block_end + negative_margin_block_end; | 173 return margin_block_end + negative_margin_block_end; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { | 221 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { |
222 return std::tie(other.margin_block_start, other.margin_block_end, | 222 return std::tie(other.margin_block_start, other.margin_block_end, |
223 other.negative_margin_block_start, | 223 other.negative_margin_block_start, |
224 other.negative_margin_block_end) == | 224 other.negative_margin_block_end) == |
225 std::tie(margin_block_start, margin_block_end, | 225 std::tie(margin_block_start, margin_block_end, |
226 negative_margin_block_start, negative_margin_block_end); | 226 negative_margin_block_start, negative_margin_block_end); |
227 } | 227 } |
228 | 228 |
229 } // namespace blink | 229 } // namespace blink |
OLD | NEW |