]> git.saurik.com Git - iphone-api.git/blob - WebCore/IntSize.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / 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 #include <wtf/Platform.h>
30
31 #include <CoreGraphics/CoreGraphics.h>
32
33 #if PLATFORM(CG)
34 typedef struct CGSize CGSize;
35 #endif
36
37
38 #ifndef NSSize
39 #define NSSize CGSize
40 #endif
41
42
43 #if PLATFORM(WIN)
44 typedef struct tagSIZE SIZE;
45 #elif PLATFORM(QT)
46 #include <qglobal.h>
47 QT_BEGIN_NAMESPACE
48 class QSize;
49 QT_END_NAMESPACE
50 #endif
51 #if PLATFORM(SYMBIAN)
52 class TSize;
53 #endif
54
55 namespace WebCore {
56
57 class IntSize {
58 public:
59 IntSize() : m_width(0), m_height(0) { }
60 IntSize(int width, int height) : m_width(width), m_height(height) { }
61
62 int width() const { return m_width; }
63 int height() const { return m_height; }
64
65 void setWidth(int width) { m_width = width; }
66 void setHeight(int height) { m_height = height; }
67
68 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
69
70 void expand(int width, int height)
71 {
72 m_width += width;
73 m_height += height;
74 }
75
76 IntSize expandedTo(const IntSize& other) const
77 {
78 return IntSize(m_width > other.m_width ? m_width : other.m_width,
79 m_height > other.m_height ? m_height : other.m_height);
80 }
81
82 IntSize shrunkTo(const IntSize& other) const
83 {
84 return IntSize(m_width < other.m_width ? m_width : other.m_width,
85 m_height < other.m_height ? m_height : other.m_height);
86 }
87
88 void clampNegativeToZero()
89 {
90 *this = expandedTo(IntSize());
91 }
92
93 #if PLATFORM(CG)
94 explicit IntSize(const CGSize&); // don't do this implicitly since it's lossy
95 operator CGSize() const;
96 #endif
97
98
99 #if PLATFORM(WIN)
100 IntSize(const SIZE&);
101 operator SIZE() const;
102 #endif
103
104 #if PLATFORM(QT)
105 IntSize(const QSize&);
106 operator QSize() const;
107 #endif
108 #if PLATFORM(SYMBIAN)
109 IntSize(const TSize&);
110 operator TSize() const;
111 #endif
112
113
114 private:
115 int m_width, m_height;
116 };
117
118 inline IntSize& operator+=(IntSize& a, const IntSize& b)
119 {
120 a.setWidth(a.width() + b.width());
121 a.setHeight(a.height() + b.height());
122 return a;
123 }
124
125 inline IntSize& operator-=(IntSize& a, const IntSize& b)
126 {
127 a.setWidth(a.width() - b.width());
128 a.setHeight(a.height() - b.height());
129 return a;
130 }
131
132 inline IntSize operator+(const IntSize& a, const IntSize& b)
133 {
134 return IntSize(a.width() + b.width(), a.height() + b.height());
135 }
136
137 inline IntSize operator-(const IntSize& a, const IntSize& b)
138 {
139 return IntSize(a.width() - b.width(), a.height() - b.height());
140 }
141
142 inline IntSize operator-(const IntSize& size)
143 {
144 return IntSize(-size.width(), -size.height());
145 }
146
147 inline bool operator==(const IntSize& a, const IntSize& b)
148 {
149 return a.width() == b.width() && a.height() == b.height();
150 }
151
152 inline bool operator!=(const IntSize& a, const IntSize& b)
153 {
154 return a.width() != b.width() || a.height() != b.height();
155 }
156
157 } // namespace WebCore
158
159 #endif // IntSize_h