tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / FractionalLayoutBoxExtent.cpp
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 "FractionalLayoutBoxExtent.h"
33
34 #include "RenderStyle.h"
35
36 namespace WebCore {
37
38 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalTop(const RenderStyle* style) const
39 {
40     return style->isHorizontalWritingMode() ? m_top : m_left;
41 }
42
43 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalBottom(const RenderStyle* style) const
44 {
45     return style->isHorizontalWritingMode() ? m_bottom : m_right;
46 }
47
48 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalLeft(const RenderStyle* style) const
49 {
50     return style->isHorizontalWritingMode() ? m_left : m_top;
51 }
52
53 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalRight(const RenderStyle* style) const
54 {
55     return style->isHorizontalWritingMode() ? m_right : m_bottom;
56 }
57
58 FractionalLayoutUnit FractionalLayoutBoxExtent::before(const RenderStyle* style) const
59 {
60     switch (style->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 FractionalLayoutUnit FractionalLayoutBoxExtent::after(const RenderStyle* style) const
75 {
76     switch (style->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 FractionalLayoutUnit FractionalLayoutBoxExtent::start(const RenderStyle* style) const
91 {
92     if (style->isHorizontalWritingMode())
93         return style->isLeftToRightDirection() ? m_left : m_right;
94     return style->isLeftToRightDirection() ? m_top : m_bottom;
95 }
96
97 FractionalLayoutUnit FractionalLayoutBoxExtent::end(const RenderStyle* style) const
98 {
99     if (style->isHorizontalWritingMode())
100         return style->isLeftToRightDirection() ? m_right : m_left;
101     return style->isLeftToRightDirection() ? m_bottom : m_top;
102 }
103
104 void FractionalLayoutBoxExtent::setBefore(const RenderStyle* style, FractionalLayoutUnit value)
105 {
106     switch (style->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 FractionalLayoutBoxExtent::setAfter(const RenderStyle* style, FractionalLayoutUnit value)
126 {
127     switch (style->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 FractionalLayoutBoxExtent::setStart(const RenderStyle* style, FractionalLayoutUnit value)
147 {
148     if (style->isHorizontalWritingMode()) {
149         if (style->isLeftToRightDirection())
150             m_left = value;
151         else
152             m_right = value;
153     } else {
154         if (style->isLeftToRightDirection())
155             m_top = value;
156         else
157             m_bottom = value;
158     }
159 }
160
161 void FractionalLayoutBoxExtent::setEnd(const RenderStyle* style, FractionalLayoutUnit value)
162 {
163     if (style->isHorizontalWritingMode()) {
164         if (style->isLeftToRightDirection())
165             m_right = value;
166         else
167             m_left = value;
168     } else {
169         if (style->isLeftToRightDirection())
170             m_bottom = value;
171         else
172             m_top = value;
173     }
174 }
175
176 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalLeft(const RenderStyle* style)
177 {
178     return style->isHorizontalWritingMode() ? m_left : m_top;
179 }
180
181 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalRight(const RenderStyle* style)
182 {
183     return style->isHorizontalWritingMode() ? m_right : m_bottom;
184 }
185
186 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableBefore(const RenderStyle* style)
187 {
188     return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_bottom : m_top) :
189                                               (style->isFlippedBlocksWritingMode() ? m_right: m_left);
190 }
191
192 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableAfter(const RenderStyle* style)
193 {
194     return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_top : m_bottom) :
195                                               (style->isFlippedBlocksWritingMode() ? m_left: m_right);
196 }
197
198 } // namespace WebCore