Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / ui / gfx / geometry / point.h
bloba1686fb8abcc187b49ff7b272bee4475dbb678b3
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 #ifndef UI_GFX_GEOMETRY_POINT_H_
6 #define UI_GFX_GEOMETRY_POINT_H_
8 #include <iosfwd>
9 #include <string>
11 #include "ui/gfx/geometry/point_f.h"
12 #include "ui/gfx/geometry/vector2d.h"
13 #include "ui/gfx/gfx_export.h"
15 #if defined(OS_WIN)
16 typedef unsigned long DWORD;
17 typedef struct tagPOINT POINT;
18 #elif defined(OS_MACOSX)
19 typedef struct CGPoint CGPoint;
20 #endif
22 namespace gfx {
24 // A point has an x and y coordinate.
25 class GFX_EXPORT Point {
26 public:
27 Point() : x_(0), y_(0) {}
28 Point(int x, int y) : x_(x), y_(y) {}
29 #if defined(OS_WIN)
30 // |point| is a DWORD value that contains a coordinate. The x-coordinate is
31 // the low-order short and the y-coordinate is the high-order short. This
32 // value is commonly acquired from GetMessagePos/GetCursorPos.
33 explicit Point(DWORD point);
34 explicit Point(const POINT& point);
35 Point& operator=(const POINT& point);
36 #elif defined(OS_MACOSX)
37 explicit Point(const CGPoint& point);
38 #endif
40 ~Point() {}
42 #if defined(OS_WIN)
43 POINT ToPOINT() const;
44 #elif defined(OS_MACOSX)
45 CGPoint ToCGPoint() const;
46 #endif
48 int x() const { return x_; }
49 int y() const { return y_; }
50 void set_x(int x) { x_ = x; }
51 void set_y(int y) { y_ = y; }
53 void SetPoint(int x, int y) {
54 x_ = x;
55 y_ = y;
58 void Offset(int delta_x, int delta_y) {
59 x_ += delta_x;
60 y_ += delta_y;
63 void operator+=(const Vector2d& vector) {
64 x_ += vector.x();
65 y_ += vector.y();
68 void operator-=(const Vector2d& vector) {
69 x_ -= vector.x();
70 y_ -= vector.y();
73 void SetToMin(const Point& other);
74 void SetToMax(const Point& other);
76 bool IsOrigin() const { return x_ == 0 && y_ == 0; }
78 Vector2d OffsetFromOrigin() const { return Vector2d(x_, y_); }
80 // A point is less than another point if its y-value is closer
81 // to the origin. If the y-values are the same, then point with
82 // the x-value closer to the origin is considered less than the
83 // other.
84 // This comparison is required to use Point in sets, or sorted
85 // vectors.
86 bool operator<(const Point& rhs) const {
87 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
90 operator PointF() const {
91 return PointF(static_cast<float>(x()), static_cast<float>(y()));
94 // Returns a string representation of point.
95 std::string ToString() const;
97 private:
98 int x_;
99 int y_;
102 inline bool operator==(const Point& lhs, const Point& rhs) {
103 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
106 inline bool operator!=(const Point& lhs, const Point& rhs) {
107 return !(lhs == rhs);
110 inline Point operator+(const Point& lhs, const Vector2d& rhs) {
111 Point result(lhs);
112 result += rhs;
113 return result;
116 inline Point operator-(const Point& lhs, const Vector2d& rhs) {
117 Point result(lhs);
118 result -= rhs;
119 return result;
122 inline Vector2d operator-(const Point& lhs, const Point& rhs) {
123 return Vector2d(lhs.x() - rhs.x(), lhs.y() - rhs.y());
126 inline Point PointAtOffsetFromOrigin(const Vector2d& offset_from_origin) {
127 return Point(offset_from_origin.x(), offset_from_origin.y());
130 // This is declared here for use in gtest-based unit tests but is defined in
131 // the gfx_test_support target. Depend on that to use this in your unit test.
132 // This should not be used in production code - call ToString() instead.
133 void PrintTo(const Point& point, ::std::ostream* os);
135 } // namespace gfx
137 #endif // UI_GFX_GEOMETRY_POINT_H_