OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/geometry/ng_border_edges.h" | 5 #include "core/layout/ng/geometry/ng_border_edges.h" |
6 | 6 |
7 namespace blink { | 7 namespace blink { |
8 | 8 |
9 namespace NGBorderEdges { | 9 NGBorderEdges NGBorderEdges::FromPhysical(unsigned physical_edges, |
10 | 10 NGWritingMode writing_mode) { |
11 Physical ToPhysical(Logical logical_edges, NGWritingMode writing_mode) { | 11 if (writing_mode == kHorizontalTopBottom) { |
12 static_assert(kBlockStart == static_cast<Logical>(kTop) && | 12 return NGBorderEdges(physical_edges & kTop, physical_edges & kRight, |
13 kBlockEnd == static_cast<Logical>(kBottom) && | 13 physical_edges & kBottom, physical_edges & kLeft); |
14 kLineLeft == static_cast<Logical>(kLeft) && | 14 } |
15 kLineRight == static_cast<Logical>(kRight), | |
16 "Physical and Logical must match"); | |
17 | |
18 if (writing_mode == kHorizontalTopBottom || logical_edges == kAll) | |
19 return static_cast<Physical>(logical_edges); | |
20 | |
21 if (writing_mode != kSidewaysLeftRight) { | 15 if (writing_mode != kSidewaysLeftRight) { |
22 return static_cast<Physical>((logical_edges & kBlockStart ? kRight : 0) | | 16 return NGBorderEdges(physical_edges & kRight, physical_edges & kBottom, |
23 (logical_edges & kBlockEnd ? kLeft : 0) | | 17 physical_edges & kLeft, physical_edges & kTop); |
24 (logical_edges & kLineLeft ? kTop : 0) | | |
25 (logical_edges & kLineRight ? kBottom : 0)); | |
26 } | 18 } |
27 return static_cast<Physical>((logical_edges & kBlockStart ? kLeft : 0) | | 19 return NGBorderEdges(physical_edges & kLeft, physical_edges & kTop, |
28 (logical_edges & kBlockEnd ? kRight : 0) | | 20 physical_edges & kRight, physical_edges & kBottom); |
29 (logical_edges & kLineLeft ? kBottom : 0) | | |
30 (logical_edges & kLineRight ? kTop : 0)); | |
31 } | 21 } |
32 | 22 |
33 Logical ToLogical(Physical physical_edges, NGWritingMode writing_mode) { | 23 unsigned NGBorderEdges::ToPhysical(NGWritingMode writing_mode) const { |
34 if (writing_mode == kHorizontalTopBottom || | 24 if (writing_mode == kHorizontalTopBottom) { |
35 physical_edges == static_cast<Physical>(kAll)) | 25 return (block_start ? kTop : 0) | (line_right ? kRight : 0) | |
36 return static_cast<Logical>(physical_edges); | 26 (block_end ? kBottom : 0) | (line_left ? kLeft : 0); |
37 | 27 } |
38 if (writing_mode != kSidewaysLeftRight) { | 28 if (writing_mode != kSidewaysLeftRight) { |
39 return static_cast<Logical>((physical_edges & kTop ? kLineLeft : 0) | | 29 return (block_start ? kRight : 0) | (line_right ? kBottom : 0) | |
40 (physical_edges & kBottom ? kLineRight : 0) | | 30 (block_end ? kLeft : 0) | (line_left ? kTop : 0); |
41 (physical_edges & kLeft ? kBlockEnd : 0) | | |
42 (physical_edges & kRight ? kBlockStart : 0)); | |
43 } | 31 } |
44 return static_cast<Logical>((physical_edges & kTop ? kLineRight : 0) | | 32 return (block_start ? kLeft : 0) | (line_right ? kTop : 0) | |
45 (physical_edges & kBottom ? kLineLeft : 0) | | 33 (block_end ? kRight : 0) | (line_left ? kBottom : 0); |
46 (physical_edges & kLeft ? kBlockStart : 0) | | |
47 (physical_edges & kRight ? kBlockEnd : 0)); | |
48 } | 34 } |
49 | 35 |
50 } // namespace NGBorderEdges | |
51 | |
52 } // namespace blink | 36 } // namespace blink |
OLD | NEW |