• 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
FloatRect.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3  * Copyright (C) 2005 Nokia. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef FloatRect_h
28 #define FloatRect_h
29 
30 #include "FloatPoint.h"
31 #include "IntRect.h"
32 
33 #if PLATFORM(CG)
34 typedef struct CGRect CGRect;
35 #endif
36 
37 #if PLATFORM(MAC)
38 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
39 typedef struct CGRect NSRect;
40 #else
41 typedef struct _NSRect NSRect;
42 #endif
43 #endif
44 
45 #if PLATFORM(QT)
46 QT_BEGIN_NAMESPACE
47 class QRectF;
48 QT_END_NAMESPACE
49 #endif
50 
51 #if PLATFORM(WX) && USE(WXGC)
52 class wxRect2DDouble;
53 #endif
54 
55 namespace WebCore {
56 
57 class IntRect;
58 
59 class FloatRect {
60 public:
61  FloatRect() { }
62  FloatRect(const FloatPoint& location, const FloatSize& size)
63  : m_location(location), m_size(size) { }
64  FloatRect(float x, float y, float width, float height)
65  : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
66  FloatRect(const IntRect&);
67 
68  static FloatRect narrowPrecision(double x, double y, double width, double height);
69 
70  FloatPoint location() const { return m_location; }
71  FloatSize size() const { return m_size; }
72 
73  void setLocation(const FloatPoint& location) { m_location = location; }
74  void setSize(const FloatSize& size) { m_size = size; }
75 
76  float x() const { return m_location.x(); }
77  float y() const { return m_location.y(); }
78  float width() const { return m_size.width(); }
79  float height() const { return m_size.height(); }
80 
81  void setX(float x) { m_location.setX(x); }
82  void setY(float y) { m_location.setY(y); }
83  void setWidth(float width) { m_size.setWidth(width); }
84  void setHeight(float height) { m_size.setHeight(height); }
85 
86  bool isEmpty() const { return m_size.isEmpty(); }
87 
88  float right() const { return x() + width(); }
89  float bottom() const { return y() + height(); }
90 
91  void move(const FloatSize& delta) { m_location += delta; }
92  void move(float dx, float dy) { m_location.move(dx, dy); }
93 
94  bool intersects(const FloatRect&) const;
95  bool contains(const FloatRect&) const;
96 
97  void intersect(const FloatRect&);
98  void unite(const FloatRect&);
99 
100  // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
101  // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.
102  bool contains(float px, float py) const
103  { return px >= x() && px <= right() && py >= y() && py <= bottom(); }
104  bool contains(const FloatPoint& point) const { return contains(point.x(), point.y()); }
105 
106 
107  void inflateX(float dx) {
108  m_location.setX(m_location.x() - dx);
109  m_size.setWidth(m_size.width() + dx + dx);
110  }
111  void inflateY(float dy) {
112  m_location.setY(m_location.y() - dy);
113  m_size.setHeight(m_size.height() + dy + dy);
114  }
115  void inflate(float d) { inflateX(d); inflateY(d); }
116  void scale(float s);
117 
118 #if PLATFORM(CG)
119  FloatRect(const CGRect&);
120  operator CGRect() const;
121 #endif
122 
123 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
124  FloatRect(const NSRect&);
125  operator NSRect() const;
126 #endif
127 
128 #if PLATFORM(QT)
129  FloatRect(const QRectF&);
130  operator QRectF() const;
131 #endif
132 #if PLATFORM(SYMBIAN)
133  FloatRect(const TRect&);
134  operator TRect() const;
135  TRect rect() const;
136 #endif
137 
138 #if PLATFORM(WX) && USE(WXGC)
139  FloatRect(const wxRect2DDouble&);
140  operator wxRect2DDouble() const;
141 #endif
142 
143 private:
144  FloatPoint m_location;
145  FloatSize m_size;
146 };
147 
148 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
149 {
150  FloatRect c = a;
151  c.intersect(b);
152  return c;
153 }
154 
155 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
156 {
157  FloatRect c = a;
158  c.unite(b);
159  return c;
160 }
161 
162 inline bool operator==(const FloatRect& a, const FloatRect& b)
163 {
164  return a.location() == b.location() && a.size() == b.size();
165 }
166 
167 inline bool operator!=(const FloatRect& a, const FloatRect& b)
168 {
169  return a.location() != b.location() || a.size() != b.size();
170 }
171 
172 IntRect enclosingIntRect(const FloatRect&);
173 
174 }
175 
176 #endif
WebCore::FloatRect
Definition: FloatRect.h:59
WebCore::FloatSize::width
float width() const
Definition: FloatSize.h:56
WebCore::IntRect
Definition: IntRect.h:65
WebCore::FloatRect::width
float width() const
Definition: FloatRect.h:78
WebCore::FloatRect::height
float height() const
Definition: FloatRect.h:79
WebCore::enclosingIntRect
IntRect enclosingIntRect(const FloatRect &rect)
Definition: FloatRect.cpp:112
WebCore::FloatRect::setY
void setY(float y)
Definition: FloatRect.h:82
WebCore::FloatRect::setHeight
void setHeight(float height)
Definition: FloatRect.h:84
WebCore::FloatSize::setHeight
void setHeight(float height)
Definition: FloatSize.h:60
WebCore::FloatRect::x
float x() const
Definition: FloatRect.h:76
WebCore::FloatRect::setLocation
void setLocation(const FloatPoint &location)
Definition: FloatRect.h:73
d
#define d
Definition: khtmlfind.cpp:42
WebCore::FloatRect::setWidth
void setWidth(float width)
Definition: FloatRect.h:83
WebCore::FloatSize::height
float height() const
Definition: FloatSize.h:57
WebCore::FloatSize
Definition: FloatSize.h:48
WebCore::FloatPoint::setX
void setX(float x)
Definition: FloatPoint.h:72
WebCore::FloatRect::narrowPrecision
static FloatRect narrowPrecision(double x, double y, double width, double height)
Definition: FloatRect.cpp:43
WebCore::FloatRect::move
void move(const FloatSize &delta)
Definition: FloatRect.h:91
IntRect.h
WebCore::intersection
FloatRect intersection(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:148
WebCore::FloatPoint::move
void move(float dx, float dy)
Definition: FloatPoint.h:74
WebCore::FloatRect::scale
void scale(float s)
Definition: FloatRect.cpp:104
WebCore::FloatRect::FloatRect
FloatRect(const FloatPoint &location, const FloatSize &size)
Definition: FloatRect.h:62
WebCore::FloatRect::unite
void unite(const FloatRect &)
Definition: FloatRect.cpp:83
WebCore::FloatRect::inflateX
void inflateX(float dx)
Definition: FloatRect.h:107
WebCore::FloatRect::contains
bool contains(const FloatPoint &point) const
Definition: FloatRect.h:104
WebCore::FloatRect::FloatRect
FloatRect(float x, float y, float width, float height)
Definition: FloatRect.h:64
WebCore::FloatRect::isEmpty
bool isEmpty() const
Definition: FloatRect.h:86
WebCore::FloatRect::inflateY
void inflateY(float dy)
Definition: FloatRect.h:111
WebCore::operator!=
bool operator!=(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:135
WebCore::FloatPoint
Definition: FloatPoint.h:61
WebCore::FloatRect::y
float y() const
Definition: FloatRect.h:77
WebCore::FloatRect::setX
void setX(float x)
Definition: FloatRect.h:81
WebCore::FloatRect::contains
bool contains(const FloatRect &) const
Definition: FloatRect.cpp:56
WebCore::FloatSize::isEmpty
bool isEmpty() const
Definition: FloatSize.h:62
FloatPoint.h
WebCore::operator==
bool operator==(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:130
WebCore::FloatRect::intersect
void intersect(const FloatRect &)
Definition: FloatRect.cpp:62
WebCore::FloatRect::contains
bool contains(float px, float py) const
Definition: FloatRect.h:102
WebCore::FloatPoint::y
float y() const
Definition: FloatPoint.h:70
WebCore::FloatRect::bottom
float bottom() const
Definition: FloatRect.h:89
WebCore::FloatPoint::x
float x() const
Definition: FloatPoint.h:69
WebCore::FloatPoint::setY
void setY(float y)
Definition: FloatPoint.h:73
WebCore::FloatRect::setSize
void setSize(const FloatSize &size)
Definition: FloatRect.h:74
WebCore::FloatRect::right
float right() const
Definition: FloatRect.h:88
WebCore::FloatRect::FloatRect
FloatRect()
Definition: FloatRect.h:61
WebCore::FloatRect::inflate
void inflate(float d)
Definition: FloatRect.h:115
WebCore::FloatRect::intersects
bool intersects(const FloatRect &) const
Definition: FloatRect.cpp:48
WebCore::FloatSize::setWidth
void setWidth(float width)
Definition: FloatSize.h:59
WebCore::FloatRect::size
FloatSize size() const
Definition: FloatRect.h:71
WebCore::FloatRect::move
void move(float dx, float dy)
Definition: FloatRect.h:92
WebCore::FloatRect::location
FloatPoint location() const
Definition: FloatRect.h:70
WebCore::unionRect
FloatRect unionRect(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:155
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:20 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