OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/rect.h" | 5 #include "ui/gfx/rect.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_MACOSX) | 9 #elif defined(OS_MACOSX) |
10 #include <CoreGraphics/CGGeometry.h> | 10 #include <CoreGraphics/CGGeometry.h> |
11 #elif defined(OS_POSIX) | 11 #elif defined(USE_X11) |
12 #include <gdk/gdk.h> | 12 #include <gdk/gdk.h> |
13 #endif | 13 #endif |
| 14 #if defined(USE_WAYLAND) |
| 15 #include <cairo.h> |
| 16 #endif |
14 | 17 |
15 #include <ostream> | 18 #include <ostream> |
16 | 19 |
17 #include "ui/gfx/insets.h" | 20 #include "ui/gfx/insets.h" |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 24 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { |
22 if (*origin < dst_origin) { | 25 if (*origin < dst_origin) { |
23 *origin = dst_origin; | 26 *origin = dst_origin; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 set_width(r.size.width); | 73 set_width(r.size.width); |
71 set_height(r.size.height); | 74 set_height(r.size.height); |
72 } | 75 } |
73 | 76 |
74 Rect& Rect::operator=(const CGRect& r) { | 77 Rect& Rect::operator=(const CGRect& r) { |
75 origin_.SetPoint(r.origin.x, r.origin.y); | 78 origin_.SetPoint(r.origin.x, r.origin.y); |
76 set_width(r.size.width); | 79 set_width(r.size.width); |
77 set_height(r.size.height); | 80 set_height(r.size.height); |
78 return *this; | 81 return *this; |
79 } | 82 } |
80 #elif defined(OS_POSIX) | 83 #elif defined(USE_X11) |
81 Rect::Rect(const GdkRectangle& r) | 84 Rect::Rect(const GdkRectangle& r) |
82 : origin_(r.x, r.y) { | 85 : origin_(r.x, r.y) { |
83 set_width(r.width); | 86 set_width(r.width); |
84 set_height(r.height); | 87 set_height(r.height); |
85 } | 88 } |
86 | 89 |
87 Rect& Rect::operator=(const GdkRectangle& r) { | 90 Rect& Rect::operator=(const GdkRectangle& r) { |
88 origin_.SetPoint(r.x, r.y); | 91 origin_.SetPoint(r.x, r.y); |
89 set_width(r.width); | 92 set_width(r.width); |
90 set_height(r.height); | 93 set_height(r.height); |
91 return *this; | 94 return *this; |
92 } | 95 } |
93 #endif | 96 #endif |
| 97 #if defined(USE_WAYLAND) |
| 98 Rect::Rect(const cairo_rectangle_int_t& r) |
| 99 : origin_(r.x, r.y) { |
| 100 set_width(r.width); |
| 101 set_height(r.height); |
| 102 } |
| 103 |
| 104 Rect& Rect::operator=(const cairo_rectangle_int_t& r) { |
| 105 origin_.SetPoint(r.x, r.y); |
| 106 set_width(r.width); |
| 107 set_height(r.height); |
| 108 return *this; |
| 109 } |
| 110 #endif |
94 | 111 |
| 112 |
95 void Rect::SetRect(int x, int y, int width, int height) { | 113 void Rect::SetRect(int x, int y, int width, int height) { |
96 origin_.SetPoint(x, y); | 114 origin_.SetPoint(x, y); |
97 set_width(width); | 115 set_width(width); |
98 set_height(height); | 116 set_height(height); |
99 } | 117 } |
100 | 118 |
101 void Rect::Inset(const gfx::Insets& insets) { | 119 void Rect::Inset(const gfx::Insets& insets) { |
102 Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); | 120 Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); |
103 } | 121 } |
104 | 122 |
(...skipping 29 matching lines...) Expand all Loading... |
134 r.left = x(); | 152 r.left = x(); |
135 r.right = right(); | 153 r.right = right(); |
136 r.top = y(); | 154 r.top = y(); |
137 r.bottom = bottom(); | 155 r.bottom = bottom(); |
138 return r; | 156 return r; |
139 } | 157 } |
140 #elif defined(OS_MACOSX) | 158 #elif defined(OS_MACOSX) |
141 CGRect Rect::ToCGRect() const { | 159 CGRect Rect::ToCGRect() const { |
142 return CGRectMake(x(), y(), width(), height()); | 160 return CGRectMake(x(), y(), width(), height()); |
143 } | 161 } |
144 #elif defined(OS_POSIX) | 162 #elif defined(USE_X11) |
145 GdkRectangle Rect::ToGdkRectangle() const { | 163 GdkRectangle Rect::ToGdkRectangle() const { |
146 GdkRectangle r = {x(), y(), width(), height()}; | 164 GdkRectangle r = {x(), y(), width(), height()}; |
147 return r; | 165 return r; |
148 } | 166 } |
149 #endif | 167 #endif |
| 168 #if defined(USE_WAYLAND) |
| 169 cairo_rectangle_int_t Rect::ToCairoRectangle() const { |
| 170 cairo_rectangle_int_t r = {x(), y(), width(), height()}; |
| 171 return r; |
| 172 } |
| 173 #endif |
150 | 174 |
151 bool Rect::Contains(int point_x, int point_y) const { | 175 bool Rect::Contains(int point_x, int point_y) const { |
152 return (point_x >= x()) && (point_x < right()) && | 176 return (point_x >= x()) && (point_x < right()) && |
153 (point_y >= y()) && (point_y < bottom()); | 177 (point_y >= y()) && (point_y < bottom()); |
154 } | 178 } |
155 | 179 |
156 bool Rect::Contains(const Rect& rect) const { | 180 bool Rect::Contains(const Rect& rect) const { |
157 return (rect.x() >= x() && rect.right() <= right() && | 181 return (rect.x() >= x() && rect.right() <= right() && |
158 rect.y() >= y() && rect.bottom() <= bottom()); | 182 rect.y() >= y() && rect.bottom() <= bottom()); |
159 } | 183 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 (x() == rect.right() || right() == rect.x())) || | 271 (x() == rect.right() || right() == rect.x())) || |
248 (x() == rect.x() && width() == rect.width() && | 272 (x() == rect.x() && width() == rect.width() && |
249 (y() == rect.bottom() || bottom() == rect.y())); | 273 (y() == rect.bottom() || bottom() == rect.y())); |
250 } | 274 } |
251 | 275 |
252 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { | 276 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { |
253 return out << r.origin() << " " << r.size(); | 277 return out << r.origin() << " " << r.size(); |
254 } | 278 } |
255 | 279 |
256 } // namespace gfx | 280 } // namespace gfx |
OLD | NEW |