OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/gfx/rect.h" | 5 #include "base/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_LINUX) | 11 #elif defined(OS_POSIX) |
12 #include <gdk/gdk.h> | 12 #include <gdk/gdk.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <iostream> | 15 #include <iostream> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 21 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 set_width(r.size.width); | 69 set_width(r.size.width); |
70 set_height(r.size.height); | 70 set_height(r.size.height); |
71 } | 71 } |
72 | 72 |
73 Rect& Rect::operator=(const CGRect& r) { | 73 Rect& Rect::operator=(const CGRect& r) { |
74 origin_.SetPoint(r.origin.x, r.origin.y); | 74 origin_.SetPoint(r.origin.x, r.origin.y); |
75 set_width(r.size.width); | 75 set_width(r.size.width); |
76 set_height(r.size.height); | 76 set_height(r.size.height); |
77 return *this; | 77 return *this; |
78 } | 78 } |
79 #elif defined(OS_LINUX) | 79 #elif defined(OS_POSIX) |
80 Rect::Rect(const GdkRectangle& r) | 80 Rect::Rect(const GdkRectangle& r) |
81 : origin_(r.x, r.y) { | 81 : origin_(r.x, r.y) { |
82 set_width(r.width); | 82 set_width(r.width); |
83 set_height(r.height); | 83 set_height(r.height); |
84 } | 84 } |
85 | 85 |
86 Rect& Rect::operator=(const GdkRectangle& r) { | 86 Rect& Rect::operator=(const GdkRectangle& r) { |
87 origin_.SetPoint(r.x, r.y); | 87 origin_.SetPoint(r.x, r.y); |
88 set_width(r.width); | 88 set_width(r.width); |
89 set_height(r.height); | 89 set_height(r.height); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
123 RECT Rect::ToRECT() const { | 123 RECT Rect::ToRECT() const { |
124 RECT r; | 124 RECT r; |
125 r.left = x(); | 125 r.left = x(); |
126 r.right = right(); | 126 r.right = right(); |
127 r.top = y(); | 127 r.top = y(); |
128 r.bottom = bottom(); | 128 r.bottom = bottom(); |
129 return r; | 129 return r; |
130 } | 130 } |
131 #elif defined(OS_LINUX) | |
132 GdkRectangle Rect::ToGdkRectangle() const { | |
133 GdkRectangle r = {x(), y(), width(), height()}; | |
134 return r; | |
135 } | |
136 #elif defined(OS_MACOSX) | 131 #elif defined(OS_MACOSX) |
137 CGRect Rect::ToCGRect() const { | 132 CGRect Rect::ToCGRect() const { |
138 return CGRectMake(x(), y(), width(), height()); | 133 return CGRectMake(x(), y(), width(), height()); |
139 } | 134 } |
| 135 #elif defined(OS_POSIX) |
| 136 GdkRectangle Rect::ToGdkRectangle() const { |
| 137 GdkRectangle r = {x(), y(), width(), height()}; |
| 138 return r; |
| 139 } |
140 #endif | 140 #endif |
141 | 141 |
142 bool Rect::Contains(int point_x, int point_y) const { | 142 bool Rect::Contains(int point_x, int point_y) const { |
143 return (point_x >= x()) && (point_x < right()) && | 143 return (point_x >= x()) && (point_x < right()) && |
144 (point_y >= y()) && (point_y < bottom()); | 144 (point_y >= y()) && (point_y < bottom()); |
145 } | 145 } |
146 | 146 |
147 bool Rect::Contains(const Rect& rect) const { | 147 bool Rect::Contains(const Rect& rect) const { |
148 return (rect.x() >= x() && rect.right() <= right() && | 148 return (rect.x() >= x() && rect.right() <= right() && |
149 rect.y() >= y() && rect.bottom() <= bottom()); | 149 rect.y() >= y() && rect.bottom() <= bottom()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 (x() == rect.right() || right() == rect.x())) || | 230 (x() == rect.right() || right() == rect.x())) || |
231 (x() == rect.x() && width() == rect.width() && | 231 (x() == rect.x() && width() == rect.width() && |
232 (y() == rect.bottom() || bottom() == rect.y())); | 232 (y() == rect.bottom() || bottom() == rect.y())); |
233 } | 233 } |
234 | 234 |
235 } // namespace gfx | 235 } // namespace gfx |
236 | 236 |
237 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { | 237 std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) { |
238 return out << r.origin() << " " << r.size(); | 238 return out << r.origin() << " " << r.size(); |
239 } | 239 } |
OLD | NEW |