KHTML
IntSize.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 1. Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * 2. Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * 00013 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 00014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 00017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00018 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00019 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00020 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00021 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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&); // don't do this implicitly since it's lossy 00089 operator CGSize() const; 00090 #endif 00091 00092 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) 00093 explicit IntSize(const NSSize &); // don't do this implicitly since it's lossy 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 } // namespace WebCore 00156 00157 #endif // IntSize_h
KDE 4.6 API Reference