| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Defines a simple integer rectangle class. The containment semantics | 5 // Defines a simple integer rectangle class. The containment semantics |
| 6 // are array-like; that is, the coordinate (x, y) is considered to be | 6 // are array-like; that is, the coordinate (x, y) is considered to be |
| 7 // contained by the rectangle, but the coordinate (x + width, y) is not. | 7 // contained by the rectangle, but the coordinate (x + width, y) is not. |
| 8 // The class will happily let you create malformed rectangles (that is, | 8 // The class will happily let you create malformed rectangles (that is, |
| 9 // rectangles with negative width and/or height), but there will be assertions | 9 // rectangles with negative width and/or height), but there will be assertions |
| 10 // in the operations (such as Contains()) to complain in this case. | 10 // in the operations (such as Contains()) to complain in this case. |
| 11 | 11 |
| 12 #ifndef UI_GFX_GEOMETRY_RECT_H_ | 12 #ifndef UI_GFX_GEOMETRY_RECT_H_ |
| 13 #define UI_GFX_GEOMETRY_RECT_H_ | 13 #define UI_GFX_GEOMETRY_RECT_H_ |
| 14 | 14 |
| 15 #include <cmath> | 15 #include <cmath> |
| 16 #include <iosfwd> | 16 #include <iosfwd> |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/rect_f.h" | |
| 22 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 23 #include "ui/gfx/geometry/vector2d.h" | 22 #include "ui/gfx/geometry/vector2d.h" |
| 24 | 23 |
| 25 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 26 typedef struct tagRECT RECT; | 25 typedef struct tagRECT RECT; |
| 27 #elif defined(OS_MACOSX) | 26 #elif defined(OS_MACOSX) |
| 28 typedef struct CGRect CGRect; | 27 typedef struct CGRect CGRect; |
| 29 #endif | 28 #endif |
| 30 | 29 |
| 31 namespace gfx { | 30 namespace gfx { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 ~Rect() {} | 49 ~Rect() {} |
| 51 | 50 |
| 52 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 53 // Construct an equivalent Win32 RECT object. | 52 // Construct an equivalent Win32 RECT object. |
| 54 RECT ToRECT() const; | 53 RECT ToRECT() const; |
| 55 #elif defined(OS_MACOSX) | 54 #elif defined(OS_MACOSX) |
| 56 // Construct an equivalent CoreGraphics object. | 55 // Construct an equivalent CoreGraphics object. |
| 57 CGRect ToCGRect() const; | 56 CGRect ToCGRect() const; |
| 58 #endif | 57 #endif |
| 59 | 58 |
| 60 operator RectF() const { | |
| 61 return RectF(static_cast<float>(x()), static_cast<float>(y()), | |
| 62 static_cast<float>(width()), static_cast<float>(height())); | |
| 63 } | |
| 64 | |
| 65 int x() const { return origin_.x(); } | 59 int x() const { return origin_.x(); } |
| 66 void set_x(int x) { origin_.set_x(x); } | 60 void set_x(int x) { origin_.set_x(x); } |
| 67 | 61 |
| 68 int y() const { return origin_.y(); } | 62 int y() const { return origin_.y(); } |
| 69 void set_y(int y) { origin_.set_y(y); } | 63 void set_y(int y) { origin_.set_y(y); } |
| 70 | 64 |
| 71 int width() const { return size_.width(); } | 65 int width() const { return size_.width(); } |
| 72 void set_width(int width) { size_.set_width(width); } | 66 void set_width(int width) { size_.set_width(width); } |
| 73 | 67 |
| 74 int height() const { return size_.height(); } | 68 int height() const { return size_.height(); } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 268 } |
| 275 | 269 |
| 276 // This is declared here for use in gtest-based unit tests but is defined in | 270 // This is declared here for use in gtest-based unit tests but is defined in |
| 277 // the gfx_test_support target. Depend on that to use this in your unit test. | 271 // the gfx_test_support target. Depend on that to use this in your unit test. |
| 278 // This should not be used in production code - call ToString() instead. | 272 // This should not be used in production code - call ToString() instead. |
| 279 void PrintTo(const Rect& rect, ::std::ostream* os); | 273 void PrintTo(const Rect& rect, ::std::ostream* os); |
| 280 | 274 |
| 281 } // namespace gfx | 275 } // namespace gfx |
| 282 | 276 |
| 283 #endif // UI_GFX_GEOMETRY_RECT_H_ | 277 #endif // UI_GFX_GEOMETRY_RECT_H_ |
| OLD | NEW |