tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / FractionalLayoutSize.h
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 #ifndef FractionalLayoutSize_h
32 #define FractionalLayoutSize_h
33
34 #include "FloatSize.h"
35 #include "FractionalLayoutUnit.h"
36 #include "IntSize.h"
37
38 #if PLATFORM(QT)
39 #include <qglobal.h>
40 QT_BEGIN_NAMESPACE
41 class QSize;
42 class QSizeF;
43 QT_END_NAMESPACE
44 #endif
45
46 namespace WebCore {
47
48 class FractionalLayoutPoint;
49
50 class FractionalLayoutSize {
51 public:
52     FractionalLayoutSize() : m_width(0), m_height(0) { }
53     FractionalLayoutSize(const IntSize& size) : m_width(size.width()), m_height(size.height()) { }
54     FractionalLayoutSize(FractionalLayoutUnit width, FractionalLayoutUnit height) : m_width(width), m_height(height) { }
55
56     explicit FractionalLayoutSize(const FloatSize& size) : m_width(size.width()), m_height(size.height()) { }
57     
58     FractionalLayoutUnit width() const { return m_width; }
59     FractionalLayoutUnit height() const { return m_height; }
60
61     void setWidth(FractionalLayoutUnit width) { m_width = width; }
62     void setHeight(FractionalLayoutUnit height) { m_height = height; }
63
64     bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
65     bool isZero() const { return !m_width && !m_height; }
66
67     float aspectRatio() const { return static_cast<float>(m_width) / static_cast<float>(m_height); }
68     
69     void expand(FractionalLayoutUnit width, FractionalLayoutUnit height)
70     {
71         m_width += width;
72         m_height += height;
73     }
74     
75     void scale(float scale)
76     {
77         m_width = static_cast<int>(static_cast<float>(m_width) * scale);
78         m_height = static_cast<int>(static_cast<float>(m_height) * scale);
79     }
80     
81     FractionalLayoutSize expandedTo(const FractionalLayoutSize& other) const
82     {
83         return FractionalLayoutSize(m_width > other.m_width ? m_width : other.m_width,
84             m_height > other.m_height ? m_height : other.m_height);
85     }
86
87     FractionalLayoutSize shrunkTo(const FractionalLayoutSize& other) const
88     {
89         return FractionalLayoutSize(m_width < other.m_width ? m_width : other.m_width,
90             m_height < other.m_height ? m_height : other.m_height);
91     }
92
93     void clampNegativeToZero()
94     {
95         *this = expandedTo(FractionalLayoutSize());
96     }
97
98     FractionalLayoutSize transposedSize() const
99     {
100         return FractionalLayoutSize(m_height, m_width);
101     }
102
103 #if PLATFORM(QT)
104     explicit FractionalLayoutSize(const QSize&);
105     explicit FractionalLayoutSize(const QSizeF&);
106     operator QSizeF() const;
107 #endif
108
109 private:
110     FractionalLayoutUnit m_width, m_height;
111 };
112
113 inline FractionalLayoutSize& operator+=(FractionalLayoutSize& a, const FractionalLayoutSize& b)
114 {
115     a.setWidth(a.width() + b.width());
116     a.setHeight(a.height() + b.height());
117     return a;
118 }
119
120 inline FractionalLayoutSize& operator-=(FractionalLayoutSize& a, const FractionalLayoutSize& b)
121 {
122     a.setWidth(a.width() - b.width());
123     a.setHeight(a.height() - b.height());
124     return a;
125 }
126
127 inline FractionalLayoutSize operator+(const FractionalLayoutSize& a, const FractionalLayoutSize& b)
128 {
129     return FractionalLayoutSize(a.width() + b.width(), a.height() + b.height());
130 }
131
132 inline FractionalLayoutSize operator-(const FractionalLayoutSize& a, const FractionalLayoutSize& b)
133 {
134     return FractionalLayoutSize(a.width() - b.width(), a.height() - b.height());
135 }
136
137 inline FractionalLayoutSize operator-(const FractionalLayoutSize& size)
138 {
139     return FractionalLayoutSize(-size.width(), -size.height());
140 }
141
142 inline bool operator==(const FractionalLayoutSize& a, const FractionalLayoutSize& b)
143 {
144     return a.width() == b.width() && a.height() == b.height();
145 }
146
147 inline bool operator!=(const FractionalLayoutSize& a, const FractionalLayoutSize& b)
148 {
149     return a.width() != b.width() || a.height() != b.height();
150 }
151
152 inline IntSize flooredIntSize(const FractionalLayoutSize& s)
153 {
154     return IntSize(s.width().toInt(), s.height().toInt());
155 }
156
157 inline IntSize roundedIntSize(const FractionalLayoutSize& s)
158 {
159     return IntSize(s.width().round(), s.height().round());
160 }
161
162 } // namespace WebCore
163
164 #endif // FractionalLayoutSize_h