KHtml

IntSize.h
1 /*
2  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef IntSize_h
27 #define IntSize_h
28 
29 #include <wtf/Platform.h>
30 
31 #if PLATFORM(CG)
32 typedef struct CGSize CGSize;
33 #endif
34 
35 #if PLATFORM(MAC)
36 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
37 typedef struct CGSize NSSize;
38 #else
39 typedef struct _NSSize NSSize;
40 #endif
41 #endif
42 
43 #if PLATFORM(WIN)
44 typedef struct tagSIZE SIZE;
45 #elif PLATFORM(QT)
46 #include <qglobal.h>
47 QT_BEGIN_NAMESPACE
48 class QSize;
49 QT_END_NAMESPACE
50 #endif
51 #if PLATFORM(SYMBIAN)
52 class TSize;
53 #endif
54 
55 namespace WebCore
56 {
57 
58 class IntSize
59 {
60 public:
61  IntSize() : m_width(0), m_height(0) { }
62  IntSize(int width, int height) : m_width(width), m_height(height) { }
63 
64  int width() const
65  {
66  return m_width;
67  }
68  int height() const
69  {
70  return m_height;
71  }
72 
73  void setWidth(int width)
74  {
75  m_width = width;
76  }
77  void setHeight(int height)
78  {
79  m_height = height;
80  }
81 
82  bool isEmpty() const
83  {
84  return m_width <= 0 || m_height <= 0;
85  }
86 
87  IntSize expandedTo(const IntSize &other) const
88  {
89  return IntSize(m_width > other.m_width ? m_width : other.m_width,
90  m_height > other.m_height ? m_height : other.m_height);
91  }
92 
93  IntSize shrunkTo(const IntSize &other) const
94  {
95  return IntSize(m_width < other.m_width ? m_width : other.m_width,
96  m_height < other.m_height ? m_height : other.m_height);
97  }
98 
99  void clampNegativeToZero()
100  {
101  *this = expandedTo(IntSize());
102  }
103 
104 #if PLATFORM(CG)
105  explicit IntSize(const CGSize &); // don't do this implicitly since it's lossy
106  operator CGSize() const;
107 #endif
108 
109 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
110  explicit IntSize(const NSSize &); // don't do this implicitly since it's lossy
111  operator NSSize() const;
112 #endif
113 
114 #if PLATFORM(WIN)
115  IntSize(const SIZE &);
116  operator SIZE() const;
117 #endif
118 
119 #if PLATFORM(QT)
120  IntSize(const QSize &);
121  operator QSize() const;
122 #endif
123 #if PLATFORM(SYMBIAN)
124  IntSize(const TSize &);
125  operator TSize() const;
126 #endif
127 
128 private:
129  int m_width, m_height;
130 };
131 
132 inline IntSize &operator+=(IntSize &a, const IntSize &b)
133 {
134  a.setWidth(a.width() + b.width());
135  a.setHeight(a.height() + b.height());
136  return a;
137 }
138 
139 inline IntSize &operator-=(IntSize &a, const IntSize &b)
140 {
141  a.setWidth(a.width() - b.width());
142  a.setHeight(a.height() - b.height());
143  return a;
144 }
145 
146 inline IntSize operator+(const IntSize &a, const IntSize &b)
147 {
148  return IntSize(a.width() + b.width(), a.height() + b.height());
149 }
150 
151 inline IntSize operator-(const IntSize &a, const IntSize &b)
152 {
153  return IntSize(a.width() - b.width(), a.height() - b.height());
154 }
155 
156 inline IntSize operator-(const IntSize &size)
157 {
158  return IntSize(-size.width(), -size.height());
159 }
160 
161 inline bool operator==(const IntSize &a, const IntSize &b)
162 {
163  return a.width() == b.width() && a.height() == b.height();
164 }
165 
166 inline bool operator!=(const IntSize &a, const IntSize &b)
167 {
168  return a.width() != b.width() || a.height() != b.height();
169 }
170 
171 } // namespace WebCore
172 
173 #endif // IntSize_h
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
QCA_EXPORT const SecureArray operator+(const SecureArray &a, const SecureArray &b)
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:48:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.