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

KHTML

FloatSize.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2006 Apple Computer, Inc.  All rights reserved.
00003  * Copyright (C) 2005 Nokia.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00015  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00018  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 
00027 #ifndef FloatSize_h
00028 #define FloatSize_h
00029 
00030 #include <wtf/Platform.h>
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGSize CGSize;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGSize NSSize;
00039 #else
00040 typedef struct _NSSize NSSize;
00041 #endif
00042 #endif
00043 
00044 namespace WebCore {
00045 
00046 class IntSize;
00047 
00048 class FloatSize {
00049 public:
00050     FloatSize() : m_width(0), m_height(0) { }
00051     FloatSize(float width, float height) : m_width(width), m_height(height) { }
00052     FloatSize(const IntSize&);
00053 
00054     static FloatSize narrowPrecision(double width, double height);
00055 
00056     float width() const { return m_width; }
00057     float height() const { return m_height; }
00058 
00059     void setWidth(float width) { m_width = width; }
00060     void setHeight(float height) { m_height = height; }
00061 
00062     bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
00063 
00064     FloatSize expandedTo(const FloatSize& other) const
00065     {
00066         return FloatSize(m_width > other.m_width ? m_width : other.m_width,
00067             m_height > other.m_height ? m_height : other.m_height);
00068     }
00069 
00070 #if PLATFORM(CG)
00071     explicit FloatSize(const CGSize&); // don't do this implicitly since it's lossy
00072     operator CGSize() const;
00073 #endif
00074 
00075 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00076     explicit FloatSize(const NSSize &); // don't do this implicitly since it's lossy
00077     operator NSSize() const;
00078 #endif
00079 
00080 private:
00081     float m_width, m_height;
00082 };
00083 
00084 inline FloatSize& operator+=(FloatSize& a, const FloatSize& b)
00085 {
00086     a.setWidth(a.width() + b.width());
00087     a.setHeight(a.height() + b.height());
00088     return a;
00089 }
00090 
00091 inline FloatSize& operator-=(FloatSize& a, const FloatSize& b)
00092 {
00093     a.setWidth(a.width() - b.width());
00094     a.setHeight(a.height() - b.height());
00095     return a;
00096 }
00097 
00098 inline FloatSize operator+(const FloatSize& a, const FloatSize& b)
00099 {
00100     return FloatSize(a.width() + b.width(), a.height() + b.height());
00101 }
00102 
00103 inline FloatSize operator-(const FloatSize& a, const FloatSize& b)
00104 {
00105     return FloatSize(a.width() - b.width(), a.height() - b.height());
00106 }
00107 
00108 inline FloatSize operator-(const FloatSize& size)
00109 {
00110     return FloatSize(-size.width(), -size.height());
00111 }
00112 
00113 inline bool operator==(const FloatSize& a, const FloatSize& b)
00114 {
00115     return a.width() == b.width() && a.height() == b.height();
00116 }
00117 
00118 inline bool operator!=(const FloatSize& a, const FloatSize& b)
00119 {
00120     return a.width() != b.width() || a.height() != b.height();
00121 }
00122 
00123 } // namespace WebCore
00124 
00125 #endif // FloatSize_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