OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/LengthBox.h" | 31 #include "platform/LengthBox.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
| 35 const Length& LengthBox::logicalLeft(WritingMode writingMode, |
| 36 const Length& left, |
| 37 const Length& top) { |
| 38 return isHorizontalWritingMode(writingMode) ? left : top; |
| 39 } |
| 40 |
| 41 const Length& LengthBox::logicalRight(WritingMode writingMode, |
| 42 const Length& right, |
| 43 const Length& bottom) { |
| 44 return isHorizontalWritingMode(writingMode) ? right : bottom; |
| 45 } |
| 46 |
| 47 const Length& LengthBox::before(WritingMode writingMode, |
| 48 const Length& top, |
| 49 const Length& left, |
| 50 const Length& right) { |
| 51 switch (writingMode) { |
| 52 case WritingMode::kHorizontalTb: |
| 53 return top; |
| 54 case WritingMode::kVerticalLr: |
| 55 return left; |
| 56 case WritingMode::kVerticalRl: |
| 57 return right; |
| 58 } |
| 59 NOTREACHED(); |
| 60 return top; |
| 61 } |
| 62 |
| 63 const Length& LengthBox::after(WritingMode writingMode, |
| 64 const Length& bottom, |
| 65 const Length& left, |
| 66 const Length& right) { |
| 67 switch (writingMode) { |
| 68 case WritingMode::kHorizontalTb: |
| 69 return bottom; |
| 70 case WritingMode::kVerticalLr: |
| 71 return right; |
| 72 case WritingMode::kVerticalRl: |
| 73 return left; |
| 74 } |
| 75 NOTREACHED(); |
| 76 return bottom; |
| 77 } |
| 78 |
35 const Length& LengthBox::logicalLeft(WritingMode writingMode) const { | 79 const Length& LengthBox::logicalLeft(WritingMode writingMode) const { |
36 return isHorizontalWritingMode(writingMode) ? m_left : m_top; | 80 return LengthBox::logicalLeft(writingMode, m_left, m_top); |
37 } | 81 } |
38 | 82 |
39 const Length& LengthBox::logicalRight(WritingMode writingMode) const { | 83 const Length& LengthBox::logicalRight(WritingMode writingMode) const { |
40 return isHorizontalWritingMode(writingMode) ? m_right : m_bottom; | 84 return LengthBox::logicalRight(writingMode, m_right, m_bottom); |
41 } | 85 } |
42 | 86 |
43 const Length& LengthBox::before(WritingMode writingMode) const { | 87 const Length& LengthBox::before(WritingMode writingMode) const { |
44 switch (writingMode) { | 88 return LengthBox::before(writingMode, m_top, m_left, m_right); |
45 case WritingMode::kHorizontalTb: | |
46 return m_top; | |
47 case WritingMode::kVerticalLr: | |
48 return m_left; | |
49 case WritingMode::kVerticalRl: | |
50 return m_right; | |
51 } | |
52 ASSERT_NOT_REACHED(); | |
53 return m_top; | |
54 } | 89 } |
55 | 90 |
56 const Length& LengthBox::after(WritingMode writingMode) const { | 91 const Length& LengthBox::after(WritingMode writingMode) const { |
57 switch (writingMode) { | 92 return LengthBox::after(writingMode, m_bottom, m_left, m_right); |
58 case WritingMode::kHorizontalTb: | |
59 return m_bottom; | |
60 case WritingMode::kVerticalLr: | |
61 return m_right; | |
62 case WritingMode::kVerticalRl: | |
63 return m_left; | |
64 } | |
65 ASSERT_NOT_REACHED(); | |
66 return m_bottom; | |
67 } | 93 } |
68 | 94 |
69 const Length& LengthBox::start(WritingMode writingMode, | 95 const Length& LengthBox::start(WritingMode writingMode, |
70 TextDirection direction) const { | 96 TextDirection direction) const { |
71 if (isHorizontalWritingMode(writingMode)) | 97 if (isHorizontalWritingMode(writingMode)) |
72 return isLeftToRightDirection(direction) ? m_left : m_right; | 98 return isLeftToRightDirection(direction) ? m_left : m_right; |
73 return isLeftToRightDirection(direction) ? m_top : m_bottom; | 99 return isLeftToRightDirection(direction) ? m_top : m_bottom; |
74 } | 100 } |
75 | 101 |
76 const Length& LengthBox::end(WritingMode writingMode, | 102 const Length& LengthBox::end(WritingMode writingMode, |
77 TextDirection direction) const { | 103 TextDirection direction) const { |
78 if (isHorizontalWritingMode(writingMode)) | 104 if (isHorizontalWritingMode(writingMode)) |
79 return isLeftToRightDirection(direction) ? m_right : m_left; | 105 return isLeftToRightDirection(direction) ? m_right : m_left; |
80 return isLeftToRightDirection(direction) ? m_bottom : m_top; | 106 return isLeftToRightDirection(direction) ? m_bottom : m_top; |
81 } | 107 } |
82 | 108 |
83 const Length& LengthBox::over(WritingMode writingMode) const { | 109 const Length& LengthBox::over(WritingMode writingMode) const { |
84 return isHorizontalWritingMode(writingMode) ? m_top : m_right; | 110 return isHorizontalWritingMode(writingMode) ? m_top : m_right; |
85 } | 111 } |
86 | 112 |
87 const Length& LengthBox::under(WritingMode writingMode) const { | 113 const Length& LengthBox::under(WritingMode writingMode) const { |
88 return isHorizontalWritingMode(writingMode) ? m_bottom : m_left; | 114 return isHorizontalWritingMode(writingMode) ? m_bottom : m_left; |
89 } | 115 } |
90 | 116 |
91 } // namespace blink | 117 } // namespace blink |
OLD | NEW |