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 FloatSize_h
00028 #define FloatSize_h
00029
00030 #include <wtf/Platform.h>
00031
00032 #if PLATFORM(CG)
00033 typedef struct CGSize CGSize;
00034 #endif
00035
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGSize NSSize;
00039 #else
00040 typedef struct _NSSize NSSize;
00041 #endif
00042 #endif
00043
00044 namespace WebCore {
00045
00046 class IntSize;
00047
00048 class FloatSize {
00049 public:
00050 FloatSize() : m_width(0), m_height(0) { }
00051 FloatSize(float width, float height) : m_width(width), m_height(height) { }
00052 FloatSize(const IntSize&);
00053
00054 static FloatSize narrowPrecision(double width, double height);
00055
00056 float width() const { return m_width; }
00057 float height() const { return m_height; }
00058
00059 void setWidth(float width) { m_width = width; }
00060 void setHeight(float height) { m_height = height; }
00061
00062 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
00063
00064 FloatSize expandedTo(const FloatSize& other) const
00065 {
00066 return FloatSize(m_width > other.m_width ? m_width : other.m_width,
00067 m_height > other.m_height ? m_height : other.m_height);
00068 }
00069
00070 #if PLATFORM(CG)
00071 explicit FloatSize(const CGSize&);
00072 operator CGSize() const;
00073 #endif
00074
00075 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00076 explicit FloatSize(const NSSize &);
00077 operator NSSize() const;
00078 #endif
00079
00080 private:
00081 float m_width, m_height;
00082 };
00083
00084 inline FloatSize& operator+=(FloatSize& a, const FloatSize& b)
00085 {
00086 a.setWidth(a.width() + b.width());
00087 a.setHeight(a.height() + b.height());
00088 return a;
00089 }
00090
00091 inline FloatSize& operator-=(FloatSize& a, const FloatSize& b)
00092 {
00093 a.setWidth(a.width() - b.width());
00094 a.setHeight(a.height() - b.height());
00095 return a;
00096 }
00097
00098 inline FloatSize operator+(const FloatSize& a, const FloatSize& b)
00099 {
00100 return FloatSize(a.width() + b.width(), a.height() + b.height());
00101 }
00102
00103 inline FloatSize operator-(const FloatSize& a, const FloatSize& b)
00104 {
00105 return FloatSize(a.width() - b.width(), a.height() - b.height());
00106 }
00107
00108 inline FloatSize operator-(const FloatSize& size)
00109 {
00110 return FloatSize(-size.width(), -size.height());
00111 }
00112
00113 inline bool operator==(const FloatSize& a, const FloatSize& b)
00114 {
00115 return a.width() == b.width() && a.height() == b.height();
00116 }
00117
00118 inline bool operator!=(const FloatSize& a, const FloatSize& b)
00119 {
00120 return a.width() != b.width() || a.height() != b.height();
00121 }
00122
00123 }
00124
00125 #endif // FloatSize_h