tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / IntSize.h
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef IntSize_h
27 #define IntSize_h
28
29 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
30 typedef struct CGSize CGSize;
31 #endif
32
33 #if PLATFORM(MAC) || (PLATFORM(QT) && USE(QTKIT))
34 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
35 typedef struct CGSize NSSize;
36 #else
37 typedef struct _NSSize NSSize;
38 #endif
39 #endif
40
41 #if PLATFORM(WIN)
42 typedef struct tagSIZE SIZE;
43 #elif PLATFORM(QT)
44 #include <qglobal.h>
45 QT_BEGIN_NAMESPACE
46 class QSize;
47 QT_END_NAMESPACE
48 #elif PLATFORM(BLACKBERRY)
49 namespace BlackBerry {
50 namespace Platform {
51 class IntSize;
52 }
53 }
54 #endif
55
56 #if PLATFORM(WX)
57 class wxSize;
58 #endif
59
60 namespace WebCore {
61
62 class IntSize {
63 public:
64     IntSize() : m_width(0), m_height(0) { }
65     IntSize(int width, int height) : m_width(width), m_height(height) { }
66     
67     int width() const { return m_width; }
68     int height() const { return m_height; }
69
70     void setWidth(int width) { m_width = width; }
71     void setHeight(int height) { m_height = height; }
72
73     bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
74     bool isZero() const { return !m_width && !m_height; }
75
76     float aspectRatio() const { return static_cast<float>(m_width) / static_cast<float>(m_height); }
77     
78     void expand(int width, int height)
79     {
80         m_width += width;
81         m_height += height;
82     }
83
84     void scale(float widthScale, float heightScale)
85     {
86         m_width = static_cast<int>(static_cast<float>(m_width) * widthScale);
87         m_height = static_cast<int>(static_cast<float>(m_height) * heightScale);
88     }
89     
90     void scale(float scale)
91     {
92         this->scale(scale, scale);
93     }
94
95     IntSize expandedTo(const IntSize& other) const
96     {
97         return IntSize(m_width > other.m_width ? m_width : other.m_width,
98             m_height > other.m_height ? m_height : other.m_height);
99     }
100
101     IntSize shrunkTo(const IntSize& other) const
102     {
103         return IntSize(m_width < other.m_width ? m_width : other.m_width,
104             m_height < other.m_height ? m_height : other.m_height);
105     }
106
107     void clampNegativeToZero()
108     {
109         *this = expandedTo(IntSize());
110     }
111
112     void clampToMinimumSize(const IntSize& minimumSize)
113     {
114         if (m_width < minimumSize.width())
115             m_width = minimumSize.width();
116         if (m_height < minimumSize.height())
117             m_height = minimumSize.height();
118     }
119
120     int area() const
121     {
122         return m_width * m_height;
123     }
124
125     int diagonalLengthSquared() const
126     {
127         return m_width * m_width + m_height * m_height;
128     }
129
130     IntSize transposedSize() const
131     {
132         return IntSize(m_height, m_width);
133     }
134
135 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
136     explicit IntSize(const CGSize&); // don't do this implicitly since it's lossy
137     operator CGSize() const;
138 #endif
139
140 #if (PLATFORM(MAC) || (PLATFORM(QT) && USE(QTKIT))) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
141     explicit IntSize(const NSSize &); // don't do this implicitly since it's lossy
142     operator NSSize() const;
143 #endif
144
145 #if PLATFORM(WIN)
146     IntSize(const SIZE&);
147     operator SIZE() const;
148 #endif
149
150 #if PLATFORM(QT)
151     IntSize(const QSize&);
152     operator QSize() const;
153 #endif
154
155 #if PLATFORM(WX)
156     IntSize(const wxSize&);
157     operator wxSize() const;
158 #endif
159
160 #if PLATFORM(BLACKBERRY)
161     IntSize(const BlackBerry::Platform::IntSize&);
162     operator BlackBerry::Platform::IntSize() const;
163 #endif
164
165 private:
166     int m_width, m_height;
167 };
168
169 inline IntSize& operator+=(IntSize& a, const IntSize& b)
170 {
171     a.setWidth(a.width() + b.width());
172     a.setHeight(a.height() + b.height());
173     return a;
174 }
175
176 inline IntSize& operator-=(IntSize& a, const IntSize& b)
177 {
178     a.setWidth(a.width() - b.width());
179     a.setHeight(a.height() - b.height());
180     return a;
181 }
182
183 inline IntSize operator+(const IntSize& a, const IntSize& b)
184 {
185     return IntSize(a.width() + b.width(), a.height() + b.height());
186 }
187
188 inline IntSize operator-(const IntSize& a, const IntSize& b)
189 {
190     return IntSize(a.width() - b.width(), a.height() - b.height());
191 }
192
193 inline IntSize operator-(const IntSize& size)
194 {
195     return IntSize(-size.width(), -size.height());
196 }
197
198 inline bool operator==(const IntSize& a, const IntSize& b)
199 {
200     return a.width() == b.width() && a.height() == b.height();
201 }
202
203 inline bool operator!=(const IntSize& a, const IntSize& b)
204 {
205     return a.width() != b.width() || a.height() != b.height();
206 }
207
208 } // namespace WebCore
209
210 #endif // IntSize_h