| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RECT_H_ | 12 #ifndef UI_GFX_RECT_H_ |
| 13 #define UI_GFX_RECT_H_ | 13 #define UI_GFX_RECT_H_ |
| 14 #pragma once | 14 #pragma once |
| 15 | 15 |
| 16 #include <iosfwd> | 16 #include <iosfwd> |
| 17 | 17 |
| 18 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
| 19 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 20 | 20 |
| 21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 22 typedef struct tagRECT RECT; | 22 typedef struct tagRECT RECT; |
| 23 #elif defined(USE_X11) | 23 #elif defined(USE_X11) |
| 24 typedef struct _GdkRectangle GdkRectangle; | 24 typedef struct _GdkRectangle GdkRectangle; |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 #if defined(USE_WAYLAND) |
| 28 typedef struct _cairo_rectangle_int cairo_rectangle_int_t; |
| 29 #endif |
| 30 |
| 27 namespace gfx { | 31 namespace gfx { |
| 28 | 32 |
| 29 class Insets; | 33 class Insets; |
| 30 | 34 |
| 31 class UI_EXPORT Rect { | 35 class UI_EXPORT Rect { |
| 32 public: | 36 public: |
| 33 Rect(); | 37 Rect(); |
| 34 Rect(int width, int height); | 38 Rect(int width, int height); |
| 35 Rect(int x, int y, int width, int height); | 39 Rect(int x, int y, int width, int height); |
| 36 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 37 explicit Rect(const RECT& r); | 41 explicit Rect(const RECT& r); |
| 38 #elif defined(OS_MACOSX) | 42 #elif defined(OS_MACOSX) |
| 39 explicit Rect(const CGRect& r); | 43 explicit Rect(const CGRect& r); |
| 40 #elif defined(USE_X11) | 44 #elif defined(USE_X11) |
| 41 explicit Rect(const GdkRectangle& r); | 45 explicit Rect(const GdkRectangle& r); |
| 42 #endif | 46 #endif |
| 47 #if defined(USE_WAYLAND) |
| 48 explicit Rect(const cairo_rectangle_int_t& r); |
| 49 #endif |
| 43 explicit Rect(const gfx::Size& size); | 50 explicit Rect(const gfx::Size& size); |
| 44 Rect(const gfx::Point& origin, const gfx::Size& size); | 51 Rect(const gfx::Point& origin, const gfx::Size& size); |
| 45 | 52 |
| 46 ~Rect() {} | 53 ~Rect() {} |
| 47 | 54 |
| 48 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 49 Rect& operator=(const RECT& r); | 56 Rect& operator=(const RECT& r); |
| 50 #elif defined(OS_MACOSX) | 57 #elif defined(OS_MACOSX) |
| 51 Rect& operator=(const CGRect& r); | 58 Rect& operator=(const CGRect& r); |
| 52 #elif defined(USE_X11) | 59 #elif defined(USE_X11) |
| 53 Rect& operator=(const GdkRectangle& r); | 60 Rect& operator=(const GdkRectangle& r); |
| 54 #endif | 61 #endif |
| 62 #if defined(USE_WAYLAND) |
| 63 Rect& operator=(const cairo_rectangle_int_t& r); |
| 64 #endif |
| 55 | 65 |
| 56 int x() const { return origin_.x(); } | 66 int x() const { return origin_.x(); } |
| 57 void set_x(int x) { origin_.set_x(x); } | 67 void set_x(int x) { origin_.set_x(x); } |
| 58 | 68 |
| 59 int y() const { return origin_.y(); } | 69 int y() const { return origin_.y(); } |
| 60 void set_y(int y) { origin_.set_y(y); } | 70 void set_y(int y) { origin_.set_y(y); } |
| 61 | 71 |
| 62 int width() const { return size_.width(); } | 72 int width() const { return size_.width(); } |
| 63 void set_width(int width) { size_.set_width(width); } | 73 void set_width(int width) { size_.set_width(width); } |
| 64 | 74 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 122 |
| 113 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
| 114 // Construct an equivalent Win32 RECT object. | 124 // Construct an equivalent Win32 RECT object. |
| 115 RECT ToRECT() const; | 125 RECT ToRECT() const; |
| 116 #elif defined(USE_X11) | 126 #elif defined(USE_X11) |
| 117 GdkRectangle ToGdkRectangle() const; | 127 GdkRectangle ToGdkRectangle() const; |
| 118 #elif defined(OS_MACOSX) | 128 #elif defined(OS_MACOSX) |
| 119 // Construct an equivalent CoreGraphics object. | 129 // Construct an equivalent CoreGraphics object. |
| 120 CGRect ToCGRect() const; | 130 CGRect ToCGRect() const; |
| 121 #endif | 131 #endif |
| 132 #if defined(USE_WAYLAND) |
| 133 cairo_rectangle_int_t ToCairoRectangle() const; |
| 134 #endif |
| 122 | 135 |
| 123 // Returns true if the point identified by point_x and point_y falls inside | 136 // Returns true if the point identified by point_x and point_y falls inside |
| 124 // this rectangle. The point (x, y) is inside the rectangle, but the | 137 // this rectangle. The point (x, y) is inside the rectangle, but the |
| 125 // point (x + width, y + height) is not. | 138 // point (x + width, y + height) is not. |
| 126 bool Contains(int point_x, int point_y) const; | 139 bool Contains(int point_x, int point_y) const; |
| 127 | 140 |
| 128 // Returns true if the specified point is contained by this rectangle. | 141 // Returns true if the specified point is contained by this rectangle. |
| 129 bool Contains(const gfx::Point& point) const { | 142 bool Contains(const gfx::Point& point) const { |
| 130 return Contains(point.x(), point.y()); | 143 return Contains(point.x(), point.y()); |
| 131 } | 144 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 private: | 188 private: |
| 176 gfx::Point origin_; | 189 gfx::Point origin_; |
| 177 gfx::Size size_; | 190 gfx::Size size_; |
| 178 }; | 191 }; |
| 179 | 192 |
| 180 UI_EXPORT std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); | 193 UI_EXPORT std::ostream& operator<<(std::ostream& out, const gfx::Rect& r); |
| 181 | 194 |
| 182 } // namespace gfx | 195 } // namespace gfx |
| 183 | 196 |
| 184 #endif // UI_GFX_RECT_H_ | 197 #endif // UI_GFX_RECT_H_ |
| OLD | NEW |