2 * Copyright (C) 2003, 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.
30 #include <wtf/Platform.h>
32 #include <CoreGraphics/CGGeometry.h>
35 typedef struct CGRect CGRect
;
45 typedef struct tagRECT RECT
;
51 typedef struct _GdkRectangle GdkRectangle
;
73 IntRect(const IntPoint
& location
, const IntSize
& size
)
74 : m_location(location
), m_size(size
) { }
75 IntRect(int x
, int y
, int width
, int height
)
76 : m_location(IntPoint(x
, y
)), m_size(IntSize(width
, height
)) { }
78 explicit IntRect(const FloatRect
& rect
); // don't do this implicitly since it's lossy
80 IntPoint
location() const { return m_location
; }
81 IntSize
size() const { return m_size
; }
83 void setLocation(const IntPoint
& location
) { m_location
= location
; }
84 void setSize(const IntSize
& size
) { m_size
= size
; }
86 int x() const { return m_location
.x(); }
87 int y() const { return m_location
.y(); }
88 int width() const { return m_size
.width(); }
89 int height() const { return m_size
.height(); }
91 void setX(int x
) { m_location
.setX(x
); }
92 void setY(int y
) { m_location
.setY(y
); }
93 void setWidth(int width
) { m_size
.setWidth(width
); }
94 void setHeight(int height
) { m_size
.setHeight(height
); }
96 // Be careful with these functions. The point is considered to be to the right and below. These are not
97 // substitutes for right() and bottom().
98 IntPoint
topLeft() const { return m_location
; }
99 IntPoint
topRight() const { return IntPoint(right() - 1, y()); }
100 IntPoint
bottomLeft() const { return IntPoint(x(), bottom() - 1); }
101 IntPoint
bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
103 bool isEmpty() const { return m_size
.isEmpty(); }
105 int right() const { return x() + width(); }
106 int bottom() const { return y() + height(); }
108 void move(const IntSize
& s
) { m_location
+= s
; }
109 void move(int dx
, int dy
) { m_location
.move(dx
, dy
); }
111 bool intersects(const IntRect
&) const;
112 bool contains(const IntRect
&) const;
114 // This checks to see if the rect contains x,y in the traditional sense.
115 // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
116 bool contains(int px
, int py
) const
117 { return px
>= x() && px
< right() && py
>= y() && py
< bottom(); }
118 bool contains(const IntPoint
& point
) const { return contains(point
.x(), point
.y()); }
120 void intersect(const IntRect
&);
121 void unite(const IntRect
&);
123 void inflateX(int dx
)
125 m_location
.setX(m_location
.x() - dx
);
126 m_size
.setWidth(m_size
.width() + dx
+ dx
);
128 void inflateY(int dy
)
130 m_location
.setY(m_location
.y() - dy
);
131 m_size
.setHeight(m_size
.height() + dy
+ dy
);
133 void inflate(int d
) { inflateX(d
); inflateY(d
); }
137 IntRect(const wxRect
&);
138 operator wxRect() const;
142 IntRect(const RECT
&);
143 operator RECT() const;
145 IntRect(const QRect
&);
146 operator QRect() const;
148 IntRect(const GdkRectangle
&);
149 operator GdkRectangle() const;
151 #if PLATFORM(SYMBIAN)
152 IntRect(const TRect
&);
153 operator TRect() const;
158 operator CGRect() const;
162 IntRect(const SkIRect
&);
163 operator SkRect() const;
164 operator SkIRect() const;
173 inline IntRect
intersection(const IntRect
& a
, const IntRect
& b
)
180 inline IntRect
unionRect(const IntRect
& a
, const IntRect
& b
)
187 inline bool operator==(const IntRect
& a
, const IntRect
& b
)
189 return a
.location() == b
.location() && a
.size() == b
.size();
192 inline bool operator!=(const IntRect
& a
, const IntRect
& b
)
194 return a
.location() != b
.location() || a
.size() != b
.size();
198 IntRect
enclosingIntRect(const CGRect
&);
202 } // namespace WebCore