OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012, Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "core/platform/graphics/LayoutBoxExtent.h" | |
33 | |
34 #include "wtf/Assertions.h" | |
35 | |
36 namespace WebCore { | |
37 | |
38 LayoutUnit LayoutBoxExtent::logicalTop(WritingMode writingMode) const | |
39 { | |
40 return isHorizontalWritingMode(writingMode) ? m_top : m_left; | |
41 } | |
42 | |
43 LayoutUnit LayoutBoxExtent::logicalBottom(WritingMode writingMode) const | |
44 { | |
45 return isHorizontalWritingMode(writingMode) ? m_bottom : m_right; | |
46 } | |
47 | |
48 LayoutUnit LayoutBoxExtent::logicalLeft(WritingMode writingMode) const | |
49 { | |
50 return isHorizontalWritingMode(writingMode) ? m_left : m_top; | |
51 } | |
52 | |
53 LayoutUnit LayoutBoxExtent::logicalRight(WritingMode writingMode) const | |
54 { | |
55 return isHorizontalWritingMode(writingMode) ? m_right : m_bottom; | |
56 } | |
57 | |
58 LayoutUnit LayoutBoxExtent::before(WritingMode writingMode) const | |
59 { | |
60 switch (writingMode) { | |
61 case TopToBottomWritingMode: | |
62 return m_top; | |
63 case BottomToTopWritingMode: | |
64 return m_bottom; | |
65 case LeftToRightWritingMode: | |
66 return m_left; | |
67 case RightToLeftWritingMode: | |
68 return m_right; | |
69 } | |
70 ASSERT_NOT_REACHED(); | |
71 return m_top; | |
72 } | |
73 | |
74 LayoutUnit LayoutBoxExtent::after(WritingMode writingMode) const | |
75 { | |
76 switch (writingMode) { | |
77 case TopToBottomWritingMode: | |
78 return m_bottom; | |
79 case BottomToTopWritingMode: | |
80 return m_top; | |
81 case LeftToRightWritingMode: | |
82 return m_right; | |
83 case RightToLeftWritingMode: | |
84 return m_left; | |
85 } | |
86 ASSERT_NOT_REACHED(); | |
87 return m_bottom; | |
88 } | |
89 | |
90 LayoutUnit LayoutBoxExtent::start(WritingMode writingMode, TextDirection directi
on) const | |
91 { | |
92 if (isHorizontalWritingMode(writingMode)) | |
93 return isLeftToRightDirection(direction) ? m_left : m_right; | |
94 return isLeftToRightDirection(direction) ? m_top : m_bottom; | |
95 } | |
96 | |
97 LayoutUnit LayoutBoxExtent::end(WritingMode writingMode, TextDirection direction
) const | |
98 { | |
99 if (isHorizontalWritingMode(writingMode)) | |
100 return isLeftToRightDirection(direction) ? m_right : m_left; | |
101 return isLeftToRightDirection(direction) ? m_bottom : m_top; | |
102 } | |
103 | |
104 void LayoutBoxExtent::setBefore(WritingMode writingMode, LayoutUnit value) | |
105 { | |
106 switch (writingMode) { | |
107 case TopToBottomWritingMode: | |
108 m_top = value; | |
109 break; | |
110 case BottomToTopWritingMode: | |
111 m_bottom = value; | |
112 break; | |
113 case LeftToRightWritingMode: | |
114 m_left = value; | |
115 break; | |
116 case RightToLeftWritingMode: | |
117 m_right = value; | |
118 break; | |
119 default: | |
120 ASSERT_NOT_REACHED(); | |
121 m_top = value; | |
122 } | |
123 } | |
124 | |
125 void LayoutBoxExtent::setAfter(WritingMode writingMode, LayoutUnit value) | |
126 { | |
127 switch (writingMode) { | |
128 case TopToBottomWritingMode: | |
129 m_bottom = value; | |
130 break; | |
131 case BottomToTopWritingMode: | |
132 m_top = value; | |
133 break; | |
134 case LeftToRightWritingMode: | |
135 m_right = value; | |
136 break; | |
137 case RightToLeftWritingMode: | |
138 m_left = value; | |
139 break; | |
140 default: | |
141 ASSERT_NOT_REACHED(); | |
142 m_bottom = value; | |
143 } | |
144 } | |
145 | |
146 void LayoutBoxExtent::setStart(WritingMode writingMode, TextDirection direction,
LayoutUnit value) | |
147 { | |
148 if (isHorizontalWritingMode(writingMode)) { | |
149 if (isLeftToRightDirection(direction)) | |
150 m_left = value; | |
151 else | |
152 m_right = value; | |
153 } else { | |
154 if (isLeftToRightDirection(direction)) | |
155 m_top = value; | |
156 else | |
157 m_bottom = value; | |
158 } | |
159 } | |
160 | |
161 void LayoutBoxExtent::setEnd(WritingMode writingMode, TextDirection direction, L
ayoutUnit value) | |
162 { | |
163 if (isHorizontalWritingMode(writingMode)) { | |
164 if (isLeftToRightDirection(direction)) | |
165 m_right = value; | |
166 else | |
167 m_left = value; | |
168 } else { | |
169 if (isLeftToRightDirection(direction)) | |
170 m_bottom = value; | |
171 else | |
172 m_top = value; | |
173 } | |
174 } | |
175 | |
176 LayoutUnit& LayoutBoxExtent::mutableLogicalLeft(WritingMode writingMode) | |
177 { | |
178 return isHorizontalWritingMode(writingMode) ? m_left : m_top; | |
179 } | |
180 | |
181 LayoutUnit& LayoutBoxExtent::mutableLogicalRight(WritingMode writingMode) | |
182 { | |
183 return isHorizontalWritingMode(writingMode) ? m_right : m_bottom; | |
184 } | |
185 | |
186 LayoutUnit& LayoutBoxExtent::mutableBefore(WritingMode writingMode) | |
187 { | |
188 return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(wr
itingMode) ? m_bottom : m_top) : | |
189 (isFlippedBlocksWritingMode(wr
itingMode) ? m_right: m_left); | |
190 } | |
191 | |
192 LayoutUnit& LayoutBoxExtent::mutableAfter(WritingMode writingMode) | |
193 { | |
194 return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(wr
itingMode) ? m_top : m_bottom) : | |
195 (isFlippedBlocksWritingMode(wr
itingMode) ? m_left: m_right); | |
196 } | |
197 | |
198 } // namespace WebCore | |
OLD | NEW |