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 IntSize_h
00027 #define IntSize_h
00028
00029 #include <wtf/Platform.h>
00030
00031 #if PLATFORM(CG)
00032 typedef struct CGSize CGSize;
00033 #endif
00034
00035 #if PLATFORM(MAC)
00036 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00037 typedef struct CGSize NSSize;
00038 #else
00039 typedef struct _NSSize NSSize;
00040 #endif
00041 #endif
00042
00043 #if PLATFORM(WIN)
00044 typedef struct tagSIZE SIZE;
00045 #elif PLATFORM(QT)
00046 class QSize;
00047 #endif
00048 #if PLATFORM(SYMBIAN)
00049 class TSize;
00050 #endif
00051
00052 namespace WebCore {
00053
00054 class IntSize {
00055 public:
00056 IntSize() : m_width(0), m_height(0) { }
00057 IntSize(int width, int height) : m_width(width), m_height(height) { }
00058
00059 int width() const { return m_width; }
00060 int height() const { return m_height; }
00061
00062 void setWidth(int width) { m_width = width; }
00063 void setHeight(int height) { m_height = height; }
00064
00065 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
00066
00067 IntSize expandedTo(const IntSize& other) const
00068 {
00069 return IntSize(m_width > other.m_width ? m_width : other.m_width,
00070 m_height > other.m_height ? m_height : other.m_height);
00071 }
00072
00073 IntSize shrunkTo(const IntSize& other) const
00074 {
00075 return IntSize(m_width < other.m_width ? m_width : other.m_width,
00076 m_height < other.m_height ? m_height : other.m_height);
00077 }
00078
00079 void clampNegativeToZero()
00080 {
00081 *this = expandedTo(IntSize());
00082 }
00083
00084 #if PLATFORM(CG)
00085 explicit IntSize(const CGSize&);
00086 operator CGSize() const;
00087 #endif
00088
00089 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00090 explicit IntSize(const NSSize &);
00091 operator NSSize() const;
00092 #endif
00093
00094 #if PLATFORM(WIN)
00095 IntSize(const SIZE&);
00096 operator SIZE() const;
00097 #endif
00098
00099 #if PLATFORM(QT)
00100 IntSize(const QSize&);
00101 operator QSize() const;
00102 #endif
00103 #if PLATFORM(SYMBIAN)
00104 IntSize(const TSize&);
00105 operator TSize() const;
00106 #endif
00107
00108
00109 private:
00110 int m_width, m_height;
00111 };
00112
00113 inline IntSize& operator+=(IntSize& a, const IntSize& b)
00114 {
00115 a.setWidth(a.width() + b.width());
00116 a.setHeight(a.height() + b.height());
00117 return a;
00118 }
00119
00120 inline IntSize& operator-=(IntSize& a, const IntSize& b)
00121 {
00122 a.setWidth(a.width() - b.width());
00123 a.setHeight(a.height() - b.height());
00124 return a;
00125 }
00126
00127 inline IntSize operator+(const IntSize& a, const IntSize& b)
00128 {
00129 return IntSize(a.width() + b.width(), a.height() + b.height());
00130 }
00131
00132 inline IntSize operator-(const IntSize& a, const IntSize& b)
00133 {
00134 return IntSize(a.width() - b.width(), a.height() - b.height());
00135 }
00136
00137 inline IntSize operator-(const IntSize& size)
00138 {
00139 return IntSize(-size.width(), -size.height());
00140 }
00141
00142 inline bool operator==(const IntSize& a, const IntSize& b)
00143 {
00144 return a.width() == b.width() && a.height() == b.height();
00145 }
00146
00147 inline bool operator!=(const IntSize& a, const IntSize& b)
00148 {
00149 return a.width() != b.width() || a.height() != b.height();
00150 }
00151
00152 }
00153
00154 #endif // IntSize_h