OLD | NEW |
1 // Copyright (c) 2006-2008 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(TOOLKIT_GTK) |
12 #include <gdk/gdk.h> | 12 #include <gdk/gdk.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { | 19 void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { |
20 if (*origin < dst_origin) { | 20 if (*origin < dst_origin) { |
21 *origin = dst_origin; | 21 *origin = dst_origin; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 set_width(r.size.width); | 67 set_width(r.size.width); |
68 set_height(r.size.height); | 68 set_height(r.size.height); |
69 } | 69 } |
70 | 70 |
71 Rect& Rect::operator=(const CGRect& r) { | 71 Rect& Rect::operator=(const CGRect& r) { |
72 origin_.SetPoint(r.origin.x, r.origin.y); | 72 origin_.SetPoint(r.origin.x, r.origin.y); |
73 set_width(r.size.width); | 73 set_width(r.size.width); |
74 set_height(r.size.height); | 74 set_height(r.size.height); |
75 return *this; | 75 return *this; |
76 } | 76 } |
77 #elif defined(OS_LINUX) | 77 #elif defined(TOOLKIT_GTK) |
78 Rect::Rect(const GdkRectangle& r) | 78 Rect::Rect(const GdkRectangle& r) |
79 : origin_(r.x, r.y) { | 79 : origin_(r.x, r.y) { |
80 set_width(r.width); | 80 set_width(r.width); |
81 set_height(r.height); | 81 set_height(r.height); |
82 } | 82 } |
83 | 83 |
84 Rect& Rect::operator=(const GdkRectangle& r) { | 84 Rect& Rect::operator=(const GdkRectangle& r) { |
85 origin_.SetPoint(r.x, r.y); | 85 origin_.SetPoint(r.x, r.y); |
86 set_width(r.width); | 86 set_width(r.width); |
87 set_height(r.height); | 87 set_height(r.height); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
135 RECT Rect::ToRECT() const { | 135 RECT Rect::ToRECT() const { |
136 RECT r; | 136 RECT r; |
137 r.left = x(); | 137 r.left = x(); |
138 r.right = right(); | 138 r.right = right(); |
139 r.top = y(); | 139 r.top = y(); |
140 r.bottom = bottom(); | 140 r.bottom = bottom(); |
141 return r; | 141 return r; |
142 } | 142 } |
143 #elif defined(OS_LINUX) | 143 #elif defined(TOOLKIT_GTK) |
144 GdkRectangle Rect::ToGdkRectangle() const { | 144 GdkRectangle Rect::ToGdkRectangle() const { |
145 GdkRectangle r = {x(), y(), width(), height()}; | 145 GdkRectangle r = {x(), y(), width(), height()}; |
146 return r; | 146 return r; |
147 } | 147 } |
148 #elif defined(OS_MACOSX) | 148 #elif defined(OS_MACOSX) |
149 CGRect Rect::ToCGRect() const { | 149 CGRect Rect::ToCGRect() const { |
150 return CGRectMake(x(), y(), width(), height()); | 150 return CGRectMake(x(), y(), width(), height()); |
151 } | 151 } |
152 #endif | 152 #endif |
153 | 153 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width); | 231 AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width); |
232 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); | 232 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); |
233 return Rect(new_x, new_y, new_width, new_height); | 233 return Rect(new_x, new_y, new_width, new_height); |
234 } | 234 } |
235 | 235 |
236 Point Rect::CenterPoint() const { | 236 Point Rect::CenterPoint() const { |
237 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); | 237 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); |
238 } | 238 } |
239 | 239 |
240 } // namespace gfx | 240 } // namespace gfx |
OLD | NEW |