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