Revert 187797 "Added tests for page launcher extensions in the a..."
[chromium-blink-merge.git] / ui / gfx / rect.h
blob52856d77031966c702568142d912a195de529d69
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
3 // found in the LICENSE file.
5 // Defines a simple integer rectangle class. The containment semantics
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.
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
10 // in the operations (such as Contains()) to complain in this case.
12 #ifndef UI_GFX_RECT_H_
13 #define UI_GFX_RECT_H_
15 #include <string>
17 #include "ui/gfx/point.h"
18 #include "ui/gfx/rect_base.h"
19 #include "ui/gfx/rect_f.h"
20 #include "ui/gfx/size.h"
21 #include "ui/gfx/vector2d.h"
23 #if defined(OS_WIN)
24 typedef struct tagRECT RECT;
25 #elif defined(TOOLKIT_GTK)
26 typedef struct _GdkRectangle GdkRectangle;
27 #elif defined(OS_IOS)
28 #include <CoreGraphics/CoreGraphics.h>
29 #elif defined(OS_MACOSX)
30 #include <ApplicationServices/ApplicationServices.h>
31 #endif
33 namespace gfx {
35 class Insets;
37 class UI_EXPORT Rect
38 : public RectBase<Rect, Point, Size, Insets, Vector2d, int> {
39 public:
40 Rect() : RectBase<Rect, Point, Size, Insets, Vector2d, int>(Point()) {}
42 Rect(int width, int height)
43 : RectBase<Rect, Point, Size, Insets, Vector2d, int>
44 (Size(width, height)) {}
46 Rect(int x, int y, int width, int height)
47 : RectBase<Rect, Point, Size, Insets, Vector2d, int>
48 (Point(x, y), Size(width, height)) {}
50 #if defined(OS_WIN)
51 explicit Rect(const RECT& r);
52 #elif defined(OS_MACOSX)
53 explicit Rect(const CGRect& r);
54 #elif defined(TOOLKIT_GTK)
55 explicit Rect(const GdkRectangle& r);
56 #endif
58 explicit Rect(const gfx::Size& size)
59 : RectBase<Rect, Point, Size, Insets, Vector2d, int>(size) {}
61 Rect(const gfx::Point& origin, const gfx::Size& size)
62 : RectBase<Rect, Point, Size, Insets, Vector2d, int>(origin, size) {}
64 ~Rect() {}
66 #if defined(OS_WIN)
67 // Construct an equivalent Win32 RECT object.
68 RECT ToRECT() const;
69 #elif defined(TOOLKIT_GTK)
70 GdkRectangle ToGdkRectangle() const;
71 #elif defined(OS_MACOSX)
72 // Construct an equivalent CoreGraphics object.
73 CGRect ToCGRect() const;
74 #endif
76 operator RectF() const {
77 return RectF(origin().x(), origin().y(), size().width(), size().height());
80 std::string ToString() const;
83 inline bool operator==(const Rect& lhs, const Rect& rhs) {
84 return lhs.origin() == rhs.origin() && lhs.size() == rhs.size();
87 inline bool operator!=(const Rect& lhs, const Rect& rhs) {
88 return !(lhs == rhs);
91 UI_EXPORT Rect operator+(const Rect& lhs, const Vector2d& rhs);
92 UI_EXPORT Rect operator-(const Rect& lhs, const Vector2d& rhs);
94 inline Rect operator+(const Vector2d& lhs, const Rect& rhs) {
95 return rhs + lhs;
98 UI_EXPORT Rect IntersectRects(const Rect& a, const Rect& b);
99 UI_EXPORT Rect UnionRects(const Rect& a, const Rect& b);
100 UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b);
102 // Constructs a rectangle with |p1| and |p2| as opposite corners.
104 // This could also be thought of as "the smallest rect that contains both
105 // points", except that we consider points on the right/bottom edges of the
106 // rect to be outside the rect. So technically one or both points will not be
107 // contained within the rect, because they will appear on one of these edges.
108 UI_EXPORT Rect BoundingRect(const Point& p1, const Point& p2);
110 #if !defined(COMPILER_MSVC)
111 extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>;
112 #endif
114 } // namespace gfx
116 #endif // UI_GFX_RECT_H_