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. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
62 // Construct an equivalent Win32 RECT object. | 62 // Construct an equivalent Win32 RECT object. |
63 RECT ToRECT() const; | 63 RECT ToRECT() const; |
64 #elif defined(TOOLKIT_GTK) | 64 #elif defined(TOOLKIT_GTK) |
65 GdkRectangle ToGdkRectangle() const; | 65 GdkRectangle ToGdkRectangle() const; |
66 #elif defined(OS_MACOSX) | 66 #elif defined(OS_MACOSX) |
67 // Construct an equivalent CoreGraphics object. | 67 // Construct an equivalent CoreGraphics object. |
68 CGRect ToCGRect() const; | 68 CGRect ToCGRect() const; |
69 #endif | 69 #endif |
70 | 70 |
71 RectF ToRectF() const { | 71 operator RectF() const { |
72 return RectF(origin().x(), origin().y(), size().width(), size().height()); | 72 return RectF(origin().x(), origin().y(), size().width(), size().height()); |
73 } | 73 } |
74 | 74 |
75 RectF Scale(float scale) const WARN_UNUSED_RESULT { | 75 RectF Scale(float scale) const WARN_UNUSED_RESULT { |
76 return Scale(scale, scale); | 76 return Scale(scale, scale); |
77 } | 77 } |
78 | 78 |
79 RectF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT { | 79 RectF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT { |
80 return ToRectF().Scale(x_scale, y_scale); | 80 RectF original = *this; |
| 81 return original.Scale(x_scale, y_scale); |
81 } | 82 } |
82 | 83 |
83 std::string ToString() const; | 84 std::string ToString() const; |
84 }; | 85 }; |
85 | 86 |
| 87 inline bool operator==(const Rect& lhs, const Rect& rhs) { |
| 88 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size(); |
| 89 } |
| 90 |
| 91 inline bool operator!=(const Rect& lhs, const Rect& rhs) { |
| 92 return !(lhs == rhs); |
| 93 } |
| 94 |
86 #if !defined(COMPILER_MSVC) | 95 #if !defined(COMPILER_MSVC) |
87 extern template class RectBase<Rect, Point, Size, Insets, int>; | 96 extern template class RectBase<Rect, Point, Size, Insets, int>; |
88 #endif | 97 #endif |
89 | 98 |
90 } // namespace gfx | 99 } // namespace gfx |
91 | 100 |
92 #endif // UI_GFX_RECT_H_ | 101 #endif // UI_GFX_RECT_H_ |
OLD | NEW |