| 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(TOOLKIT_GTK) | 11 #elif defined(OS_LINUX) |
| 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(TOOLKIT_GTK) | 77 #elif defined(OS_LINUX) |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 #if defined(OS_WIN) | 120 #if defined(OS_WIN) |
| 121 RECT Rect::ToRECT() const { | 121 RECT Rect::ToRECT() const { |
| 122 RECT r; | 122 RECT r; |
| 123 r.left = x(); | 123 r.left = x(); |
| 124 r.right = right(); | 124 r.right = right(); |
| 125 r.top = y(); | 125 r.top = y(); |
| 126 r.bottom = bottom(); | 126 r.bottom = bottom(); |
| 127 return r; | 127 return r; |
| 128 } | 128 } |
| 129 #elif defined(TOOLKIT_GTK) | 129 #elif defined(OS_LINUX) |
| 130 GdkRectangle Rect::ToGdkRectangle() const { | 130 GdkRectangle Rect::ToGdkRectangle() const { |
| 131 GdkRectangle r = {x(), y(), width(), height()}; | 131 GdkRectangle r = {x(), y(), width(), height()}; |
| 132 return r; | 132 return r; |
| 133 } | 133 } |
| 134 #elif defined(OS_MACOSX) | 134 #elif defined(OS_MACOSX) |
| 135 CGRect Rect::ToCGRect() const { | 135 CGRect Rect::ToCGRect() const { |
| 136 return CGRectMake(x(), y(), width(), height()); | 136 return CGRectMake(x(), y(), width(), height()); |
| 137 } | 137 } |
| 138 #endif | 138 #endif |
| 139 | 139 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width); | 217 AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width); |
| 218 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); | 218 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height); |
| 219 return Rect(new_x, new_y, new_width, new_height); | 219 return Rect(new_x, new_y, new_width, new_height); |
| 220 } | 220 } |
| 221 | 221 |
| 222 Point Rect::CenterPoint() const { | 222 Point Rect::CenterPoint() const { |
| 223 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); | 223 return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace gfx | 226 } // namespace gfx |
| OLD | NEW |