Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ui/gfx/geometry/rect_f.h

Issue 2051343002: Make various gfx classes more amenable to use as compile-time constants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete destructor Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/size.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "build/build_config.h" 11 #include "build/build_config.h"
12 #include "ui/gfx/geometry/point_f.h" 12 #include "ui/gfx/geometry/point_f.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size_f.h" 14 #include "ui/gfx/geometry/size_f.h"
15 #include "ui/gfx/geometry/vector2d_f.h" 15 #include "ui/gfx/geometry/vector2d_f.h"
16 16
17 #if defined(OS_MACOSX) 17 #if defined(OS_MACOSX)
18 typedef struct CGRect CGRect; 18 typedef struct CGRect CGRect;
19 #endif 19 #endif
20 20
21 namespace gfx { 21 namespace gfx {
22 22
23 class InsetsF; 23 class InsetsF;
24 24
25 // A floating version of gfx::Rect. 25 // A floating version of gfx::Rect.
26 class GFX_EXPORT RectF { 26 class GFX_EXPORT RectF {
27 public: 27 public:
28 RectF() {} 28 constexpr RectF() = default;
29 RectF(float width, float height) : size_(width, height) {} 29 constexpr RectF(float width, float height) : size_(width, height) {}
30 RectF(float x, float y, float width, float height) 30 constexpr RectF(float x, float y, float width, float height)
31 : origin_(x, y), size_(width, height) {} 31 : origin_(x, y), size_(width, height) {}
32 explicit RectF(const SizeF& size) : size_(size) {} 32 constexpr explicit RectF(const SizeF& size) : size_(size) {}
33 RectF(const PointF& origin, const SizeF& size) 33 constexpr RectF(const PointF& origin, const SizeF& size)
34 : origin_(origin), size_(size) {} 34 : origin_(origin), size_(size) {}
35 35
36 explicit RectF(const Rect& r) 36 constexpr explicit RectF(const Rect& r)
37 : RectF(static_cast<float>(r.x()), 37 : RectF(static_cast<float>(r.x()),
38 static_cast<float>(r.y()), 38 static_cast<float>(r.y()),
39 static_cast<float>(r.width()), 39 static_cast<float>(r.width()),
40 static_cast<float>(r.height())) {} 40 static_cast<float>(r.height())) {}
41 41
42 #if defined(OS_MACOSX) 42 #if defined(OS_MACOSX)
43 explicit RectF(const CGRect& r); 43 explicit RectF(const CGRect& r);
44 // Construct an equivalent CoreGraphics object. 44 // Construct an equivalent CoreGraphics object.
45 CGRect ToCGRect() const; 45 CGRect ToCGRect() const;
46 #endif 46 #endif
47 47
48 ~RectF() {} 48 constexpr float x() const { return origin_.x(); }
49
50 float x() const { return origin_.x(); }
51 void set_x(float x) { origin_.set_x(x); } 49 void set_x(float x) { origin_.set_x(x); }
52 50
53 float y() const { return origin_.y(); } 51 constexpr float y() const { return origin_.y(); }
54 void set_y(float y) { origin_.set_y(y); } 52 void set_y(float y) { origin_.set_y(y); }
55 53
56 float width() const { return size_.width(); } 54 constexpr float width() const { return size_.width(); }
57 void set_width(float width) { size_.set_width(width); } 55 void set_width(float width) { size_.set_width(width); }
58 56
59 float height() const { return size_.height(); } 57 constexpr float height() const { return size_.height(); }
60 void set_height(float height) { size_.set_height(height); } 58 void set_height(float height) { size_.set_height(height); }
61 59
62 const PointF& origin() const { return origin_; } 60 constexpr const PointF& origin() const { return origin_; }
63 void set_origin(const PointF& origin) { origin_ = origin; } 61 void set_origin(const PointF& origin) { origin_ = origin; }
64 62
65 const SizeF& size() const { return size_; } 63 constexpr const SizeF& size() const { return size_; }
66 void set_size(const SizeF& size) { size_ = size; } 64 void set_size(const SizeF& size) { size_ = size; }
67 65
68 float right() const { return x() + width(); } 66 constexpr float right() const { return x() + width(); }
69 float bottom() const { return y() + height(); } 67 constexpr float bottom() const { return y() + height(); }
70 68
71 PointF top_right() const { return PointF(right(), y()); } 69 constexpr PointF top_right() const { return PointF(right(), y()); }
72 PointF bottom_left() const { return PointF(x(), bottom()); } 70 constexpr PointF bottom_left() const { return PointF(x(), bottom()); }
73 PointF bottom_right() const { return PointF(right(), bottom()); } 71 constexpr PointF bottom_right() const { return PointF(right(), bottom()); }
74 72
75 Vector2dF OffsetFromOrigin() const { return Vector2dF(x(), y()); } 73 Vector2dF OffsetFromOrigin() const { return Vector2dF(x(), y()); }
76 74
77 void SetRect(float x, float y, float width, float height) { 75 void SetRect(float x, float y, float width, float height) {
78 origin_.SetPoint(x, y); 76 origin_.SetPoint(x, y);
79 size_.SetSize(width, height); 77 size_.SetSize(width, height);
80 } 78 }
81 79
82 // Shrink the rectangle by a horizontal and vertical distance on all sides. 80 // Shrink the rectangle by a horizontal and vertical distance on all sides.
83 void Inset(float horizontal, float vertical) { 81 void Inset(float horizontal, float vertical) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 GFX_EXPORT RectF BoundingRect(const PointF& p1, const PointF& p2); 233 GFX_EXPORT RectF BoundingRect(const PointF& p1, const PointF& p2);
236 234
237 // This is declared here for use in gtest-based unit tests but is defined in 235 // This is declared here for use in gtest-based unit tests but is defined in
238 // the gfx_test_support target. Depend on that to use this in your unit test. 236 // the gfx_test_support target. Depend on that to use this in your unit test.
239 // This should not be used in production code - call ToString() instead. 237 // This should not be used in production code - call ToString() instead.
240 void PrintTo(const RectF& rect, ::std::ostream* os); 238 void PrintTo(const RectF& rect, ::std::ostream* os);
241 239
242 } // namespace gfx 240 } // namespace gfx
243 241
244 #endif // UI_GFX_GEOMETRY_RECT_F_H_ 242 #endif // UI_GFX_GEOMETRY_RECT_F_H_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/rect.h ('k') | ui/gfx/geometry/size.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698