OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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. | |
4 | |
5 #ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | |
6 #define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | |
7 | |
8 #include "ui/gfx/geometry/safe_integer_conversions.h" | |
9 #include "ui/gfx/geometry/vector2d.h" | |
10 #include "ui/gfx/gfx_export.h" | |
11 | |
12 namespace gfx { | |
13 | |
14 class GFX_EXPORT ScrollOffset { | |
15 public: | |
16 ScrollOffset() : x_(0), y_(0) {} | |
17 ScrollOffset(double x, double y) : x_(x), y_(y) {} | |
18 | |
19 double x() const { return x_; } | |
20 void set_x(double x) { x_ = x; } | |
21 | |
22 double y() const { return y_; } | |
23 void set_y(double y) { y_ = y; } | |
24 | |
25 // True if both components are 0. | |
26 bool IsZero() const; | |
27 | |
28 // Add the components of the |other| ScrollOffset to the current ScrollOffset. | |
29 void Add(const ScrollOffset& other); | |
30 // Subtract the components of the |other| ScrollOffset from the current | |
31 // ScrollOffset. | |
32 void Subtract(const ScrollOffset& other); | |
33 | |
34 void operator+=(const ScrollOffset& other) { Add(other); } | |
35 void operator-=(const ScrollOffset& other) { Subtract(other); } | |
36 | |
37 private: | |
38 double x_; | |
39 double y_; | |
40 }; | |
41 | |
42 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { | |
43 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); | |
44 } | |
45 | |
46 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { | |
47 return lhs.x() != rhs.x() || lhs.y() != rhs.y(); | |
48 } | |
49 | |
50 inline ScrollOffset operator-(const ScrollOffset& v) { | |
51 return ScrollOffset(-v.x(), -v.y()); | |
52 } | |
53 | |
54 inline ScrollOffset operator+(const ScrollOffset& lhs, | |
55 const ScrollOffset& rhs) { | |
56 ScrollOffset result = lhs; | |
57 result.Add(rhs); | |
58 return result; | |
59 } | |
60 | |
61 inline ScrollOffset operator-(const ScrollOffset& lhs, | |
62 const ScrollOffset& rhs) { | |
63 ScrollOffset result = lhs; | |
64 result.Add(-rhs); | |
65 return result; | |
66 } | |
67 | |
68 inline Vector2d ToFlooredVector2d(const ScrollOffset& v) { | |
danakj
2014/09/25 15:13:31
make this a member
Yufeng Shen (Slow to review)
2014/09/25 20:06:24
Done.
| |
69 int x = ToFlooredInt(v.x()); | |
70 int y = ToFlooredInt(v.y()); | |
71 return Vector2d(x, y); | |
72 } | |
73 | |
74 inline Vector2dF ToVector2dF(const ScrollOffset& v) { | |
danakj
2014/09/25 15:13:31
make a member
Yufeng Shen (Slow to review)
2014/09/25 20:06:24
Done.
| |
75 return Vector2dF(v.x(), v.y()); | |
76 } | |
77 | |
78 } // namespace gfx | |
79 | |
80 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | |
OLD | NEW |