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

KHTML

IntRect.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 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 IntRect_h
00027 #define IntRect_h
00028 
00029 #include "IntPoint.h"
00030 #include <wtf/Platform.h>
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGRect CGRect;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGRect NSRect;
00039 #else
00040 typedef struct _NSRect NSRect;
00041 #endif
00042 #endif
00043 
00044 #if PLATFORM(WIN)
00045 typedef struct tagRECT RECT;
00046 #elif PLATFORM(QT)
00047 QT_BEGIN_NAMESPACE
00048 class QRect;
00049 QT_END_NAMESPACE
00050 #elif PLATFORM(GTK)
00051 typedef struct _GdkRectangle GdkRectangle;
00052 #endif
00053 #if PLATFORM(SYMBIAN)
00054 class TRect;
00055 #endif
00056 
00057 #if PLATFORM(WX)
00058 class wxRect;
00059 #endif
00060 
00061 namespace WebCore {
00062 
00063 class FloatRect;
00064 
00065 class IntRect {
00066 public:
00067     IntRect() { }
00068     IntRect(const IntPoint& location, const IntSize& size)
00069         : m_location(location), m_size(size) { }
00070     IntRect(int x, int y, int width, int height)
00071         : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
00072 
00073     explicit IntRect(const FloatRect& rect); // don't do this implicitly since it's lossy
00074         
00075     IntPoint location() const { return m_location; }
00076     IntSize size() const { return m_size; }
00077 
00078     void setLocation(const IntPoint& location) { m_location = location; }
00079     void setSize(const IntSize& size) { m_size = size; }
00080 
00081     int x() const { return m_location.x(); }
00082     int y() const { return m_location.y(); }
00083     int width() const { return m_size.width(); }
00084     int height() const { return m_size.height(); }
00085 
00086     void setX(int x) { m_location.setX(x); }
00087     void setY(int y) { m_location.setY(y); }
00088     void setWidth(int width) { m_size.setWidth(width); }
00089     void setHeight(int height) { m_size.setHeight(height); }
00090 
00091     // Be careful with these functions.  The point is considered to be to the right and below.  These are not
00092     // substitutes for right() and bottom().
00093     IntPoint topLeft() const { return m_location; }
00094     IntPoint topRight() const { return IntPoint(right() - 1, y()); }
00095     IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
00096     IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
00097 
00098     bool isEmpty() const { return m_size.isEmpty(); }
00099 
00100     int right() const { return x() + width(); }
00101     int bottom() const { return y() + height(); }
00102 
00103     void move(const IntSize& s) { m_location += s; } 
00104     void move(int dx, int dy) { m_location.move(dx, dy); } 
00105 
00106     bool intersects(const IntRect&) const;
00107     bool contains(const IntRect&) const;
00108 
00109     // This checks to see if the rect contains x,y in the traditional sense.
00110     // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
00111     bool contains(int px, int py) const
00112         { return px >= x() && px < right() && py >= y() && py < bottom(); }
00113     bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
00114 
00115     void intersect(const IntRect&);
00116     void unite(const IntRect&);
00117 
00118     void inflateX(int dx)
00119     {
00120         m_location.setX(m_location.x() - dx);
00121         m_size.setWidth(m_size.width() + dx + dx);
00122     }
00123     void inflateY(int dy)
00124     {
00125         m_location.setY(m_location.y() - dy);
00126         m_size.setHeight(m_size.height() + dy + dy);
00127     }
00128     void inflate(int d) { inflateX(d); inflateY(d); }
00129     void scale(float s);
00130 
00131 #if PLATFORM(WX)
00132     IntRect(const wxRect&);
00133     operator wxRect() const;
00134 #endif
00135 
00136 #if PLATFORM(WIN)
00137     IntRect(const RECT&);
00138     operator RECT() const;
00139 #elif PLATFORM(QT)
00140     IntRect(const QRect&);
00141     operator QRect() const;
00142 #elif PLATFORM(GTK)
00143     IntRect(const GdkRectangle&);
00144     operator GdkRectangle() const;
00145 #endif
00146 #if PLATFORM(SYMBIAN)
00147     IntRect(const TRect&);
00148     operator TRect() const;
00149     TRect Rect() const;
00150 #endif
00151 
00152 #if PLATFORM(CG)
00153     operator CGRect() const;
00154 #endif
00155 
00156 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00157     operator NSRect() const;
00158 #endif
00159 
00160 private:
00161     IntPoint m_location;
00162     IntSize m_size;
00163 };
00164 
00165 inline IntRect intersection(const IntRect& a, const IntRect& b)
00166 {
00167     IntRect c = a;
00168     c.intersect(b);
00169     return c;
00170 }
00171 
00172 inline IntRect unionRect(const IntRect& a, const IntRect& b)
00173 {
00174     IntRect c = a;
00175     c.unite(b);
00176     return c;
00177 }
00178 
00179 inline bool operator==(const IntRect& a, const IntRect& b)
00180 {
00181     return a.location() == b.location() && a.size() == b.size();
00182 }
00183 
00184 inline bool operator!=(const IntRect& a, const IntRect& b)
00185 {
00186     return a.location() != b.location() || a.size() != b.size();
00187 }
00188 
00189 #if PLATFORM(CG)
00190 IntRect enclosingIntRect(const CGRect&);
00191 #endif
00192 
00193 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00194 IntRect enclosingIntRect(const NSRect&);
00195 #endif
00196 
00197 } // namespace WebCore
00198 
00199 #endif // IntRect_h

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal