• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • platform
  • graphics
IntRect.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003, 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 IntRect_h
27 #define IntRect_h
28 
29 #include "IntPoint.h"
30 #include <wtf/Platform.h>
31 
32 #if PLATFORM(CG)
33 typedef struct CGRect CGRect;
34 #endif
35 
36 #if PLATFORM(MAC)
37 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
38 typedef struct CGRect NSRect;
39 #else
40 typedef struct _NSRect NSRect;
41 #endif
42 #endif
43 
44 #if PLATFORM(WIN)
45 typedef struct tagRECT RECT;
46 #elif PLATFORM(QT)
47 QT_BEGIN_NAMESPACE
48 class QRect;
49 QT_END_NAMESPACE
50 #elif PLATFORM(GTK)
51 typedef struct _GdkRectangle GdkRectangle;
52 #endif
53 #if PLATFORM(SYMBIAN)
54 class TRect;
55 #endif
56 
57 #if PLATFORM(WX)
58 class wxRect;
59 #endif
60 
61 namespace WebCore {
62 
63 class FloatRect;
64 
65 class IntRect {
66 public:
67  IntRect() { }
68  IntRect(const IntPoint& location, const IntSize& size)
69  : m_location(location), m_size(size) { }
70  IntRect(int x, int y, int width, int height)
71  : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
72 
73  explicit IntRect(const FloatRect& rect); // don't do this implicitly since it's lossy
74 
75  IntPoint location() const { return m_location; }
76  IntSize size() const { return m_size; }
77 
78  void setLocation(const IntPoint& location) { m_location = location; }
79  void setSize(const IntSize& size) { m_size = size; }
80 
81  int x() const { return m_location.x(); }
82  int y() const { return m_location.y(); }
83  int width() const { return m_size.width(); }
84  int height() const { return m_size.height(); }
85 
86  void setX(int x) { m_location.setX(x); }
87  void setY(int y) { m_location.setY(y); }
88  void setWidth(int width) { m_size.setWidth(width); }
89  void setHeight(int height) { m_size.setHeight(height); }
90 
91  // Be careful with these functions. The point is considered to be to the right and below. These are not
92  // substitutes for right() and bottom().
93  IntPoint topLeft() const { return m_location; }
94  IntPoint topRight() const { return IntPoint(right() - 1, y()); }
95  IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
96  IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
97 
98  bool isEmpty() const { return m_size.isEmpty(); }
99 
100  int right() const { return x() + width(); }
101  int bottom() const { return y() + height(); }
102 
103  void move(const IntSize& s) { m_location += s; }
104  void move(int dx, int dy) { m_location.move(dx, dy); }
105 
106  bool intersects(const IntRect&) const;
107  bool contains(const IntRect&) const;
108 
109  // This checks to see if the rect contains x,y in the traditional sense.
110  // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
111  bool contains(int px, int py) const
112  { return px >= x() && px < right() && py >= y() && py < bottom(); }
113  bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
114 
115  void intersect(const IntRect&);
116  void unite(const IntRect&);
117 
118  void inflateX(int dx)
119  {
120  m_location.setX(m_location.x() - dx);
121  m_size.setWidth(m_size.width() + dx + dx);
122  }
123  void inflateY(int dy)
124  {
125  m_location.setY(m_location.y() - dy);
126  m_size.setHeight(m_size.height() + dy + dy);
127  }
128  void inflate(int d) { inflateX(d); inflateY(d); }
129  void scale(float s);
130 
131 #if PLATFORM(WX)
132  IntRect(const wxRect&);
133  operator wxRect() const;
134 #endif
135 
136 #if PLATFORM(WIN)
137  IntRect(const RECT&);
138  operator RECT() const;
139 #elif PLATFORM(QT)
140  IntRect(const QRect&);
141  operator QRect() const;
142 #elif PLATFORM(GTK)
143  IntRect(const GdkRectangle&);
144  operator GdkRectangle() const;
145 #endif
146 #if PLATFORM(SYMBIAN)
147  IntRect(const TRect&);
148  operator TRect() const;
149  TRect Rect() const;
150 #endif
151 
152 #if PLATFORM(CG)
153  operator CGRect() const;
154 #endif
155 
156 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
157  operator NSRect() const;
158 #endif
159 
160 private:
161  IntPoint m_location;
162  IntSize m_size;
163 };
164 
165 inline IntRect intersection(const IntRect& a, const IntRect& b)
166 {
167  IntRect c = a;
168  c.intersect(b);
169  return c;
170 }
171 
172 inline IntRect unionRect(const IntRect& a, const IntRect& b)
173 {
174  IntRect c = a;
175  c.unite(b);
176  return c;
177 }
178 
179 inline bool operator==(const IntRect& a, const IntRect& b)
180 {
181  return a.location() == b.location() && a.size() == b.size();
182 }
183 
184 inline bool operator!=(const IntRect& a, const IntRect& b)
185 {
186  return a.location() != b.location() || a.size() != b.size();
187 }
188 
189 #if PLATFORM(CG)
190 IntRect enclosingIntRect(const CGRect&);
191 #endif
192 
193 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
194 IntRect enclosingIntRect(const NSRect&);
195 #endif
196 
197 } // namespace WebCore
198 
199 #endif // IntRect_h
WebCore::IntPoint::move
void move(int dx, int dy)
Definition: IntPoint.h:75
WebCore::IntRect::IntRect
IntRect(int x, int y, int width, int height)
Definition: IntRect.h:70
WebCore::IntRect::topRight
IntPoint topRight() const
Definition: IntRect.h:94
WebCore::FloatRect
Definition: FloatRect.h:59
WebCore::IntRect::move
void move(int dx, int dy)
Definition: IntRect.h:104
WebCore::IntSize::height
int height() const
Definition: IntSize.h:63
WebCore::IntRect
Definition: IntRect.h:65
WebCore::enclosingIntRect
IntRect enclosingIntRect(const FloatRect &rect)
Definition: FloatRect.cpp:112
WebCore::IntRect::inflateY
void inflateY(int dy)
Definition: IntRect.h:123
WebCore::IntRect::setSize
void setSize(const IntSize &size)
Definition: IntRect.h:79
d
#define d
Definition: khtmlfind.cpp:42
WebCore::IntRect::setX
void setX(int x)
Definition: IntRect.h:86
WebCore::IntRect::move
void move(const IntSize &s)
Definition: IntRect.h:103
WebCore::IntRect::scale
void scale(float s)
Definition: IntRect.cpp:99
WebCore::IntPoint::setY
void setY(int y)
Definition: IntPoint.h:73
WebCore::IntRect::contains
bool contains(const IntRect &) const
Definition: IntRect.cpp:51
WebCore::intersection
FloatRect intersection(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:148
WebCore::IntSize
Definition: IntSize.h:57
WebCore::IntRect::bottom
int bottom() const
Definition: IntRect.h:101
WebCore::IntPoint::y
int y() const
Definition: IntPoint.h:70
WebCore::IntRect::setHeight
void setHeight(int height)
Definition: IntRect.h:89
WebCore::IntRect::contains
bool contains(int px, int py) const
Definition: IntRect.h:111
WebCore::IntRect::setY
void setY(int y)
Definition: IntRect.h:87
WebCore::operator!=
bool operator!=(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:135
WebCore::IntRect::inflate
void inflate(int d)
Definition: IntRect.h:128
WebCore::IntRect::y
int y() const
Definition: IntRect.h:82
WebCore::IntPoint::x
int x() const
Definition: IntPoint.h:69
WebCore::IntRect::location
IntPoint location() const
Definition: IntRect.h:75
WebCore::IntRect::isEmpty
bool isEmpty() const
Definition: IntRect.h:98
WebCore::IntPoint::setX
void setX(int x)
Definition: IntPoint.h:72
WebCore::IntRect::setWidth
void setWidth(int width)
Definition: IntRect.h:88
WebCore::IntRect::width
int width() const
Definition: IntRect.h:83
WebCore::IntRect::right
int right() const
Definition: IntRect.h:100
WebCore::operator==
bool operator==(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:130
WebCore::IntRect::height
int height() const
Definition: IntRect.h:84
WebCore::IntRect::intersect
void intersect(const IntRect &)
Definition: IntRect.cpp:57
WebCore::IntSize::width
int width() const
Definition: IntSize.h:62
WebCore::IntSize::isEmpty
bool isEmpty() const
Definition: IntSize.h:68
WebCore::IntRect::bottomLeft
IntPoint bottomLeft() const
Definition: IntRect.h:95
WebCore::IntRect::setLocation
void setLocation(const IntPoint &location)
Definition: IntRect.h:78
WebCore::IntRect::contains
bool contains(const IntPoint &point) const
Definition: IntRect.h:113
QRect
WebCore::IntRect::IntRect
IntRect(const IntPoint &location, const IntSize &size)
Definition: IntRect.h:68
WebCore::IntRect::x
int x() const
Definition: IntRect.h:81
WebCore::IntRect::size
IntSize size() const
Definition: IntRect.h:76
WebCore::IntRect::intersects
bool intersects(const IntRect &) const
Definition: IntRect.cpp:43
WebCore::IntPoint
Definition: IntPoint.h:64
WebCore::IntSize::setHeight
void setHeight(int height)
Definition: IntSize.h:66
WebCore::IntRect::topLeft
IntPoint topLeft() const
Definition: IntRect.h:93
WebCore::IntRect::bottomRight
IntPoint bottomRight() const
Definition: IntRect.h:96
WebCore::IntRect::inflateX
void inflateX(int dx)
Definition: IntRect.h:118
WebCore::IntRect::unite
void unite(const IntRect &)
Definition: IntRect.cpp:78
WebCore::IntSize::setWidth
void setWidth(int width)
Definition: IntSize.h:65
IntPoint.h
WebCore::unionRect
FloatRect unionRect(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:155
WebCore::IntRect::IntRect
IntRect()
Definition: IntRect.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal