OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | 5 #ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
6 #define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | 6 #define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ui/gfx/geometry/safe_integer_conversions.h" | 11 #include "ui/gfx/geometry/safe_integer_conversions.h" |
12 #include "ui/gfx/geometry/vector2d.h" | 12 #include "ui/gfx/geometry/vector2d.h" |
13 #include "ui/gfx/gfx_export.h" | 13 #include "ui/gfx/gfx_export.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 | 16 |
17 class GFX_EXPORT ScrollOffset { | 17 class GFX_EXPORT ScrollOffset { |
18 public: | 18 public: |
19 ScrollOffset() : x_(0), y_(0) {} | 19 ScrollOffset() : x_(0), y_(0) {} |
20 ScrollOffset(double x, double y) : x_(x), y_(y) {} | 20 ScrollOffset(float x, float y) : x_(x), y_(y) {} |
21 explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {} | 21 explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {} |
22 explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {} | 22 explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {} |
23 | 23 |
24 double x() const { return x_; } | 24 float x() const { return x_; } |
25 void set_x(double x) { x_ = x; } | 25 void set_x(float x) { x_ = x; } |
26 | 26 |
27 double y() const { return y_; } | 27 float y() const { return y_; } |
28 void set_y(double y) { y_ = y; } | 28 void set_y(float y) { y_ = y; } |
29 | 29 |
30 // True if both components are 0. | 30 // True if both components are 0. |
31 bool IsZero() const { | 31 bool IsZero() const { |
32 return x_ == 0 && y_ == 0; | 32 return x_ == 0 && y_ == 0; |
33 } | 33 } |
34 | 34 |
35 // Add the components of the |other| ScrollOffset to the current ScrollOffset. | 35 // Add the components of the |other| ScrollOffset to the current ScrollOffset. |
36 void Add(const ScrollOffset& other) { | 36 void Add(const ScrollOffset& other) { |
37 x_ += other.x_; | 37 x_ += other.x_; |
38 y_ += other.y_; | 38 y_ += other.y_; |
(...skipping 16 matching lines...) Expand all Loading... | |
55 void SetToMin(const ScrollOffset& other) { | 55 void SetToMin(const ScrollOffset& other) { |
56 x_ = x_ <= other.x_ ? x_ : other.x_; | 56 x_ = x_ <= other.x_ ? x_ : other.x_; |
57 y_ = y_ <= other.y_ ? y_ : other.y_; | 57 y_ = y_ <= other.y_ ? y_ : other.y_; |
58 } | 58 } |
59 | 59 |
60 void SetToMax(const ScrollOffset& other) { | 60 void SetToMax(const ScrollOffset& other) { |
61 x_ = x_ >= other.x_ ? x_ : other.x_; | 61 x_ = x_ >= other.x_ ? x_ : other.x_; |
62 y_ = y_ >= other.y_ ? y_ : other.y_; | 62 y_ = y_ >= other.y_ ? y_ : other.y_; |
63 } | 63 } |
64 | 64 |
65 void Scale(double scale) { Scale(scale, scale); } | 65 void Scale(float scale) { Scale(scale, scale); } |
66 void Scale(double x_scale, double y_scale) { | 66 void Scale(float x_scale, float y_scale) { |
67 x_ *= x_scale; | 67 x_ *= x_scale; |
68 y_ *= y_scale; | 68 y_ *= y_scale; |
69 } | 69 } |
70 | 70 |
71 std::string ToString() const; | 71 std::string ToString() const; |
72 | 72 |
73 private: | 73 private: |
74 double x_; | 74 float x_; |
75 double y_; | 75 float y_; |
bokan
2016/10/02 19:47:51
So did we decide that we don't care about the mons
danakj
2016/10/03 21:24:41
See the bug for how we got here :)
| |
76 }; | 76 }; |
77 | 77 |
78 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { | 78 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
79 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); | 79 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); |
80 } | 80 } |
81 | 81 |
82 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { | 82 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
83 return lhs.x() != rhs.x() || lhs.y() != rhs.y(); | 83 return lhs.x() != rhs.x() || lhs.y() != rhs.y(); |
84 } | 84 } |
85 | 85 |
(...skipping 30 matching lines...) Expand all Loading... | |
116 } | 116 } |
117 | 117 |
118 // This is declared here for use in gtest-based unit tests but is defined in | 118 // This is declared here for use in gtest-based unit tests but is defined in |
119 // the //ui/gfx:test_support target. Depend on that to use this in your unit | 119 // the //ui/gfx:test_support target. Depend on that to use this in your unit |
120 // test. This should not be used in production code - call ToString() instead. | 120 // test. This should not be used in production code - call ToString() instead. |
121 void PrintTo(const ScrollOffset& scroll_offset, ::std::ostream* os); | 121 void PrintTo(const ScrollOffset& scroll_offset, ::std::ostream* os); |
122 | 122 |
123 } // namespace gfx | 123 } // namespace gfx |
124 | 124 |
125 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | 125 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
OLD | NEW |