| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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) |
| 12 #include <gdk/gdk.h> |
| 11 #endif | 13 #endif |
| 12 | 14 |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 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) { |
| 18 if (*origin < dst_origin) { | 20 if (*origin < dst_origin) { |
| 19 *origin = dst_origin; | 21 *origin = dst_origin; |
| 20 *size = std::min(dst_size, *size); | 22 *size = std::min(dst_size, *size); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 set_width(r.size.width); | 63 set_width(r.size.width); |
| 62 set_height(r.size.height); | 64 set_height(r.size.height); |
| 63 } | 65 } |
| 64 | 66 |
| 65 Rect& Rect::operator=(const CGRect& r) { | 67 Rect& Rect::operator=(const CGRect& r) { |
| 66 origin_.SetPoint(r.origin.x, r.origin.y); | 68 origin_.SetPoint(r.origin.x, r.origin.y); |
| 67 set_width(r.size.width); | 69 set_width(r.size.width); |
| 68 set_height(r.size.height); | 70 set_height(r.size.height); |
| 69 return *this; | 71 return *this; |
| 70 } | 72 } |
| 73 #elif defined(OS_LINUX) |
| 74 Rect::Rect(const GdkRectangle& r) |
| 75 : origin_(r.x, r.y) { |
| 76 set_width(r.width); |
| 77 set_height(r.height); |
| 78 } |
| 79 |
| 80 Rect& Rect::operator=(const GdkRectangle& r) { |
| 81 origin_.SetPoint(r.x, r.y); |
| 82 set_width(r.width); |
| 83 set_height(r.height); |
| 84 return *this; |
| 85 } |
| 71 #endif | 86 #endif |
| 72 | 87 |
| 73 void Rect::set_width(int width) { | 88 void Rect::set_width(int width) { |
| 74 if (width < 0) { | 89 if (width < 0) { |
| 75 NOTREACHED(); | 90 NOTREACHED(); |
| 76 width = 0; | 91 width = 0; |
| 77 } | 92 } |
| 78 | 93 |
| 79 size_.set_width(width); | 94 size_.set_width(width); |
| 80 } | 95 } |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); | 224 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); |
| 210 return Rect(new_x, new_y, new_width, new_height); | 225 return Rect(new_x, new_y, new_width, new_height); |
| 211 } | 226 } |
| 212 | 227 |
| 213 Point Rect::CenterPoint() const { | 228 Point Rect::CenterPoint() const { |
| 214 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); | 229 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); |
| 215 } | 230 } |
| 216 | 231 |
| 217 } // namespace gfx | 232 } // namespace gfx |
| 218 | 233 |
| OLD | NEW |