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 #ifndef UI_GFX_GEOMETRY_RECT_F_H_ | 5 #ifndef UI_GFX_GEOMETRY_RECT_F_H_ |
6 #define UI_GFX_GEOMETRY_RECT_F_H_ | 6 #define UI_GFX_GEOMETRY_RECT_F_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ui/gfx/geometry/point_f.h" | 11 #include "ui/gfx/geometry/point_f.h" |
| 12 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/geometry/size_f.h" | 13 #include "ui/gfx/geometry/size_f.h" |
13 #include "ui/gfx/geometry/vector2d_f.h" | 14 #include "ui/gfx/geometry/vector2d_f.h" |
14 | 15 |
15 #if defined(OS_MACOSX) | 16 #if defined(OS_MACOSX) |
16 typedef struct CGRect CGRect; | 17 typedef struct CGRect CGRect; |
17 #endif | 18 #endif |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 | 21 |
21 class InsetsF; | 22 class InsetsF; |
22 | 23 |
23 // A floating version of gfx::Rect. | 24 // A floating version of gfx::Rect. |
24 class GFX_EXPORT RectF { | 25 class GFX_EXPORT RectF { |
25 public: | 26 public: |
26 RectF() {} | 27 RectF() {} |
27 RectF(float width, float height) : size_(width, height) {} | 28 RectF(float width, float height) : size_(width, height) {} |
28 RectF(float x, float y, float width, float height) | 29 RectF(float x, float y, float width, float height) |
29 : origin_(x, y), size_(width, height) {} | 30 : origin_(x, y), size_(width, height) {} |
30 explicit RectF(const SizeF& size) : size_(size) {} | 31 explicit RectF(const SizeF& size) : size_(size) {} |
31 RectF(const PointF& origin, const SizeF& size) | 32 RectF(const PointF& origin, const SizeF& size) |
32 : origin_(origin), size_(size) {} | 33 : origin_(origin), size_(size) {} |
33 | 34 |
| 35 explicit RectF(const Rect& r) |
| 36 // TODO(danakj): Change these to checked_cast? |
| 37 : RectF(static_cast<float>(r.x()), |
| 38 static_cast<float>(r.y()), |
| 39 static_cast<float>(r.width()), |
| 40 static_cast<float>(r.height())) {} |
| 41 |
34 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
35 explicit RectF(const CGRect& r); | 43 explicit RectF(const CGRect& r); |
36 // Construct an equivalent CoreGraphics object. | 44 // Construct an equivalent CoreGraphics object. |
37 CGRect ToCGRect() const; | 45 CGRect ToCGRect() const; |
38 #endif | 46 #endif |
39 | 47 |
40 ~RectF() {} | 48 ~RectF() {} |
41 | 49 |
42 float x() const { return origin_.x(); } | 50 float x() const { return origin_.x(); } |
43 void set_x(float x) { origin_.set_x(x); } | 51 void set_x(float x) { origin_.set_x(x); } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 GFX_EXPORT RectF BoundingRect(const PointF& p1, const PointF& p2); | 235 GFX_EXPORT RectF BoundingRect(const PointF& p1, const PointF& p2); |
228 | 236 |
229 // This is declared here for use in gtest-based unit tests but is defined in | 237 // This is declared here for use in gtest-based unit tests but is defined in |
230 // the gfx_test_support target. Depend on that to use this in your unit test. | 238 // the gfx_test_support target. Depend on that to use this in your unit test. |
231 // This should not be used in production code - call ToString() instead. | 239 // This should not be used in production code - call ToString() instead. |
232 void PrintTo(const RectF& rect, ::std::ostream* os); | 240 void PrintTo(const RectF& rect, ::std::ostream* os); |
233 | 241 |
234 } // namespace gfx | 242 } // namespace gfx |
235 | 243 |
236 #endif // UI_GFX_GEOMETRY_RECT_F_H_ | 244 #endif // UI_GFX_GEOMETRY_RECT_F_H_ |
OLD | NEW |