00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef IntRect_h
00027 #define IntRect_h
00028
00029 #include "IntPoint.h"
00030 #include <wtf/Platform.h>
00031
00032 #if PLATFORM(CG)
00033 typedef struct CGRect CGRect;
00034 #endif
00035
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGRect NSRect;
00039 #else
00040 typedef struct _NSRect NSRect;
00041 #endif
00042 #endif
00043
00044 #if PLATFORM(WIN)
00045 typedef struct tagRECT RECT;
00046 #elif PLATFORM(QT)
00047 class QRect;
00048 #endif
00049 #if PLATFORM(SYMBIAN)
00050 class TRect;
00051 #endif
00052
00053 namespace WebCore {
00054
00055 class FloatRect;
00056
00057 class IntRect {
00058 public:
00059 IntRect() { }
00060 IntRect(const IntPoint& location, const IntSize& size)
00061 : m_location(location), m_size(size) { }
00062 IntRect(int x, int y, int width, int height)
00063 : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
00064
00065 explicit IntRect(const FloatRect& rect);
00066
00067 IntPoint location() const { return m_location; }
00068 IntSize size() const { return m_size; }
00069
00070 void setLocation(const IntPoint& location) { m_location = location; }
00071 void setSize(const IntSize& size) { m_size = size; }
00072
00073 int x() const { return m_location.x(); }
00074 int y() const { return m_location.y(); }
00075 int width() const { return m_size.width(); }
00076 int height() const { return m_size.height(); }
00077
00078 void setX(int x) { m_location.setX(x); }
00079 void setY(int y) { m_location.setY(y); }
00080 void setWidth(int width) { m_size.setWidth(width); }
00081 void setHeight(int height) { m_size.setHeight(height); }
00082
00083
00084
00085 IntPoint topLeft() const { return m_location; }
00086 IntPoint topRight() const { return IntPoint(right() - 1, y()); }
00087 IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
00088 IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
00089
00090 bool isEmpty() const { return m_size.isEmpty(); }
00091
00092 int right() const { return x() + width(); }
00093 int bottom() const { return y() + height(); }
00094
00095 void move(const IntSize& s) { m_location += s; }
00096 void move(int dx, int dy) { m_location.move(dx, dy); }
00097
00098 bool intersects(const IntRect&) const;
00099 bool contains(const IntRect&) const;
00100
00101
00102
00103 bool contains(int px, int py) const
00104 { return px >= x() && px < right() && py >= y() && py < bottom(); }
00105 bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
00106
00107 void intersect(const IntRect&);
00108 void unite(const IntRect&);
00109
00110 void inflateX(int dx)
00111 {
00112 m_location.setX(m_location.x() - dx);
00113 m_size.setWidth(m_size.width() + dx + dx);
00114 }
00115 void inflateY(int dy)
00116 {
00117 m_location.setY(m_location.y() - dy);
00118 m_size.setHeight(m_size.height() + dy + dy);
00119 }
00120 void inflate(int d) { inflateX(d); inflateY(d); }
00121 void scale(float s);
00122
00123 #if PLATFORM(WIN)
00124 IntRect(const RECT&);
00125 operator RECT() const;
00126 #elif PLATFORM(QT)
00127 IntRect(const QRect&);
00128 operator QRect() const;
00129 #endif
00130 #if PLATFORM(SYMBIAN)
00131 IntRect(const TRect&);
00132 operator TRect() const;
00133 TRect Rect() const;
00134 #endif
00135
00136 #if PLATFORM(CG)
00137 operator CGRect() const;
00138 #endif
00139
00140 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00141 operator NSRect() const;
00142 #endif
00143
00144 private:
00145 IntPoint m_location;
00146 IntSize m_size;
00147 };
00148
00149 inline IntRect intersection(const IntRect& a, const IntRect& b)
00150 {
00151 IntRect c = a;
00152 c.intersect(b);
00153 return c;
00154 }
00155
00156 inline IntRect unionRect(const IntRect& a, const IntRect& b)
00157 {
00158 IntRect c = a;
00159 c.unite(b);
00160 return c;
00161 }
00162
00163 inline bool operator==(const IntRect& a, const IntRect& b)
00164 {
00165 return a.location() == b.location() && a.size() == b.size();
00166 }
00167
00168 inline bool operator!=(const IntRect& a, const IntRect& b)
00169 {
00170 return a.location() != b.location() || a.size() != b.size();
00171 }
00172
00173 #if PLATFORM(CG)
00174 IntRect enclosingIntRect(const CGRect&);
00175 #endif
00176
00177 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00178 IntRect enclosingIntRect(const NSRect&);
00179 #endif
00180
00181 }
00182
00183 #endif // IntRect_h