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
00027 #ifndef FloatRect_h
00028 #define FloatRect_h
00029
00030 #include "FloatPoint.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(QT)
00045 class QRectF;
00046 #endif
00047
00048 namespace WebCore {
00049
00050 class IntRect;
00051
00052 class FloatRect {
00053 public:
00054 FloatRect() { }
00055 FloatRect(const FloatPoint& location, const FloatSize& size)
00056 : m_location(location), m_size(size) { }
00057 FloatRect(float x, float y, float width, float height)
00058 : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
00059 FloatRect(const IntRect&);
00060
00061 static FloatRect narrowPrecision(double x, double y, double width, double height);
00062
00063 FloatPoint location() const { return m_location; }
00064 FloatSize size() const { return m_size; }
00065
00066 void setLocation(const FloatPoint& location) { m_location = location; }
00067 void setSize(const FloatSize& size) { m_size = size; }
00068
00069 float x() const { return m_location.x(); }
00070 float y() const { return m_location.y(); }
00071 float width() const { return m_size.width(); }
00072 float height() const { return m_size.height(); }
00073
00074 void setX(float x) { m_location.setX(x); }
00075 void setY(float y) { m_location.setY(y); }
00076 void setWidth(float width) { m_size.setWidth(width); }
00077 void setHeight(float height) { m_size.setHeight(height); }
00078
00079 bool isEmpty() const { return m_size.isEmpty(); }
00080
00081 float right() const { return x() + width(); }
00082 float bottom() const { return y() + height(); }
00083
00084 void move(const FloatSize& delta) { m_location += delta; }
00085 void move(float dx, float dy) { m_location.move(dx, dy); }
00086
00087 bool intersects(const FloatRect&) const;
00088 bool contains(const FloatRect&) const;
00089
00090 void intersect(const FloatRect&);
00091 void unite(const FloatRect&);
00092
00093
00094
00095 bool contains(float px, float py) const
00096 { return px >= x() && px <= right() && py >= y() && py <= bottom(); }
00097 bool contains(const FloatPoint& point) const { return contains(point.x(), point.y()); }
00098
00099
00100 void inflateX(float dx) {
00101 m_location.setX(m_location.x() - dx);
00102 m_size.setWidth(m_size.width() + dx + dx);
00103 }
00104 void inflateY(float dy) {
00105 m_location.setY(m_location.y() - dy);
00106 m_size.setHeight(m_size.height() + dy + dy);
00107 }
00108 void inflate(float d) { inflateX(d); inflateY(d); }
00109 void scale(float s);
00110
00111 #if PLATFORM(CG)
00112 FloatRect(const CGRect&);
00113 operator CGRect() const;
00114 #endif
00115
00116 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00117 FloatRect(const NSRect&);
00118 operator NSRect() const;
00119 #endif
00120
00121 #if PLATFORM(QT)
00122 FloatRect(const QRectF&);
00123 operator QRectF() const;
00124 #endif
00125 #if PLATFORM(SYMBIAN)
00126 FloatRect(const TRect&);
00127 operator TRect() const;
00128 TRect rect() const;
00129 #endif
00130
00131 private:
00132 FloatPoint m_location;
00133 FloatSize m_size;
00134 };
00135
00136 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
00137 {
00138 FloatRect c = a;
00139 c.intersect(b);
00140 return c;
00141 }
00142
00143 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
00144 {
00145 FloatRect c = a;
00146 c.unite(b);
00147 return c;
00148 }
00149
00150 inline bool operator==(const FloatRect& a, const FloatRect& b)
00151 {
00152 return a.location() == b.location() && a.size() == b.size();
00153 }
00154
00155 inline bool operator!=(const FloatRect& a, const FloatRect& b)
00156 {
00157 return a.location() != b.location() || a.size() != b.size();
00158 }
00159
00160 IntRect enclosingIntRect(const FloatRect&);
00161
00162 }
00163
00164 #endif