]> git.saurik.com Git - iphone-api.git/blob - WebCore/FloatSize.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / FloatSize.h
1 /*
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2005 Nokia. All rights reserved.
4 * 2008 Eric Seidel <eric@webkit.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef FloatSize_h
29 #define FloatSize_h
30
31 #include <wtf/Platform.h>
32
33 #include <CoreGraphics/CoreGraphics.h>
34
35 #if PLATFORM(CG)
36 typedef struct CGSize CGSize;
37 #endif
38
39
40 #ifndef NSSize
41 #define NSSize CGSize
42 #endif
43
44
45 namespace WebCore {
46
47 class IntSize;
48
49 class FloatSize {
50 public:
51 FloatSize() : m_width(0), m_height(0) { }
52 FloatSize(float width, float height) : m_width(width), m_height(height) { }
53 FloatSize(const IntSize&);
54
55 static FloatSize narrowPrecision(double width, double height);
56
57 float width() const { return m_width; }
58 float height() const { return m_height; }
59
60 void setWidth(float width) { m_width = width; }
61 void setHeight(float height) { m_height = height; }
62
63 bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
64
65 FloatSize expandedTo(const FloatSize& other) const
66 {
67 return FloatSize(m_width > other.m_width ? m_width : other.m_width,
68 m_height > other.m_height ? m_height : other.m_height);
69 }
70
71 FloatSize shrunkTo(const FloatSize& other) const
72 {
73 return FloatSize(m_width < other.m_width ? m_width : other.m_width,
74 m_height < other.m_height ? m_height : other.m_height);
75 }
76
77 #if PLATFORM(CG)
78 explicit FloatSize(const CGSize&); // don't do this implicitly since it's lossy
79 operator CGSize() const;
80 #endif
81
82
83 private:
84 float m_width, m_height;
85 };
86
87 inline FloatSize& operator+=(FloatSize& a, const FloatSize& b)
88 {
89 a.setWidth(a.width() + b.width());
90 a.setHeight(a.height() + b.height());
91 return a;
92 }
93
94 inline FloatSize& operator-=(FloatSize& a, const FloatSize& b)
95 {
96 a.setWidth(a.width() - b.width());
97 a.setHeight(a.height() - b.height());
98 return a;
99 }
100
101 inline FloatSize operator+(const FloatSize& a, const FloatSize& b)
102 {
103 return FloatSize(a.width() + b.width(), a.height() + b.height());
104 }
105
106 inline FloatSize operator-(const FloatSize& a, const FloatSize& b)
107 {
108 return FloatSize(a.width() - b.width(), a.height() - b.height());
109 }
110
111 inline FloatSize operator-(const FloatSize& size)
112 {
113 return FloatSize(-size.width(), -size.height());
114 }
115
116 inline bool operator==(const FloatSize& a, const FloatSize& b)
117 {
118 return a.width() == b.width() && a.height() == b.height();
119 }
120
121 inline bool operator!=(const FloatSize& a, const FloatSize& b)
122 {
123 return a.width() != b.width() || a.height() != b.height();
124 }
125
126 } // namespace WebCore
127
128 #endif // FloatSize_h