2 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
30 typedef struct CGSize CGSize;
34 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
35 typedef struct CGSize NSSize;
37 typedef struct _NSSize NSSize;
42 typedef struct tagSIZE SIZE;
57 typedef struct AEESize AEESize;
64 IntSize() : m_width(0), m_height(0) { }
65 IntSize(int width, int height) : m_width(width), m_height(height) { }
67 int width() const { return m_width; }
68 int height() const { return m_height; }
70 void setWidth(int width) { m_width = width; }
71 void setHeight(int height) { m_height = height; }
73 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
74 bool isZero() const { return !m_width && !m_height; }
76 float aspectRatio() const { return static_cast<float>(m_width) / static_cast<float>(m_height); }
78 void expand(int width, int height)
84 void scale(float scale)
86 m_width = static_cast<int>(static_cast<float>(m_width) * scale);
87 m_height = static_cast<int>(static_cast<float>(m_height) * scale);
90 IntSize expandedTo(const IntSize& other) const
92 return IntSize(m_width > other.m_width ? m_width : other.m_width,
93 m_height > other.m_height ? m_height : other.m_height);
96 IntSize shrunkTo(const IntSize& other) const
98 return IntSize(m_width < other.m_width ? m_width : other.m_width,
99 m_height < other.m_height ? m_height : other.m_height);
102 void clampNegativeToZero()
104 *this = expandedTo(IntSize());
107 IntSize transposedSize() const
109 return IntSize(m_height, m_width);
112 #if USE(CG) || USE(SKIA_ON_MAC_CHROME)
113 explicit IntSize(const CGSize&); // don't do this implicitly since it's lossy
114 operator CGSize() const;
117 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
118 explicit IntSize(const NSSize &); // don't do this implicitly since it's lossy
119 operator NSSize() const;
123 IntSize(const SIZE&);
124 operator SIZE() const;
128 IntSize(const QSize&);
129 operator QSize() const;
133 explicit IntSize(const BSize&);
134 operator BSize() const;
138 IntSize(const wxSize&);
139 operator wxSize() const;
143 IntSize(const AEESize&);
144 operator AEESize() const;
148 int m_width, m_height;
151 inline IntSize& operator+=(IntSize& a, const IntSize& b)
153 a.setWidth(a.width() + b.width());
154 a.setHeight(a.height() + b.height());
158 inline IntSize& operator-=(IntSize& a, const IntSize& b)
160 a.setWidth(a.width() - b.width());
161 a.setHeight(a.height() - b.height());
165 inline IntSize operator+(const IntSize& a, const IntSize& b)
167 return IntSize(a.width() + b.width(), a.height() + b.height());
170 inline IntSize operator-(const IntSize& a, const IntSize& b)
172 return IntSize(a.width() - b.width(), a.height() - b.height());
175 inline IntSize operator-(const IntSize& size)
177 return IntSize(-size.width(), -size.height());
180 inline bool operator==(const IntSize& a, const IntSize& b)
182 return a.width() == b.width() && a.height() == b.height();
185 inline bool operator!=(const IntSize& a, const IntSize& b)
187 return a.width() != b.width() || a.height() != b.height();
190 } // namespace WebCore