OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google 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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef WebRect_h | |
32 #define WebRect_h | |
33 | |
34 #include "WebCommon.h" | |
35 | |
36 #if WEBKIT_IMPLEMENTATION | |
37 #include "IntRect.h" | |
38 #else | |
39 #include <base/gfx/rect.h> | |
40 #endif | |
41 | |
42 namespace WebKit { | |
43 | |
44 struct WebRect { | |
45 int x; | |
46 int y; | |
47 int width; | |
48 int height; | |
49 | |
50 bool isEmpty() const { return width <= 0 || height <= 0; } | |
51 | |
52 WebRect() | |
53 : x(0) | |
54 , y(0) | |
55 , width(0) | |
56 , height(0) | |
57 { | |
58 } | |
59 | |
60 WebRect(int x, int y, int width, int height) | |
61 : x(x) | |
62 , y(y) | |
63 , width(width) | |
64 , height(height) | |
65 { | |
66 } | |
67 | |
68 #if WEBKIT_IMPLEMENTATION | |
69 WebRect(const WebCore::IntRect& r) | |
70 : x(r.x()) | |
71 , y(r.y()) | |
72 , width(r.width()) | |
73 , height(r.height()) | |
74 { | |
75 } | |
76 | |
77 WebRect& operator=(const WebCore::IntRect& r) | |
78 { | |
79 x = r.x(); | |
80 y = r.y(); | |
81 width = r.width(); | |
82 height = r.height(); | |
83 return *this; | |
84 } | |
85 | |
86 operator WebCore::IntRect() const | |
87 { | |
88 return WebCore::IntRect(x, y, width, height); | |
89 } | |
90 #else | |
91 WebRect(const gfx::Rect& r) | |
92 : x(r.x()) | |
93 , y(r.y()) | |
94 , width(r.width()) | |
95 , height(r.height()) | |
96 { | |
97 } | |
98 | |
99 WebRect& operator=(const gfx::Rect& r) | |
100 { | |
101 x = r.x(); | |
102 y = r.y(); | |
103 width = r.width(); | |
104 height = r.height(); | |
105 return *this; | |
106 } | |
107 | |
108 operator gfx::Rect() const | |
109 { | |
110 return gfx::Rect(x, y, width, height); | |
111 } | |
112 #endif | |
113 }; | |
114 | |
115 inline bool operator==(const WebRect& a, const WebRect& b) | |
116 { | |
117 return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; | |
118 } | |
119 | |
120 inline bool operator!=(const WebRect& a, const WebRect& b) | |
121 { | |
122 return !(a == b); | |
123 } | |
124 | |
125 } // namespace WebKit | |
126 | |
127 #endif | |
OLD | NEW |