| 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 // TODO(szager): Reconcile terminology with blink. An 'offset' here corresponds |
| 18 // to a 'position' in blink. In blink, 'offset' means something else. See |
| 19 // third_party/WebKit/Source/core/layout/README.md for more information. |
| 20 |
| 17 class GFX_EXPORT ScrollOffset { | 21 class GFX_EXPORT ScrollOffset { |
| 18 public: | 22 public: |
| 19 ScrollOffset() : x_(0), y_(0) {} | 23 ScrollOffset() : x_(0), y_(0) {} |
| 20 ScrollOffset(double x, double y) : x_(x), y_(y) {} | 24 ScrollOffset(float x, float y) : x_(x), y_(y) {} |
| 21 explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {} | 25 explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {} |
| 22 explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {} | 26 explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {} |
| 23 | 27 |
| 24 double x() const { return x_; } | 28 float x() const { return x_; } |
| 25 void set_x(double x) { x_ = x; } | 29 void set_x(float x) { x_ = x; } |
| 26 | 30 |
| 27 double y() const { return y_; } | 31 float y() const { return y_; } |
| 28 void set_y(double y) { y_ = y; } | 32 void set_y(float y) { y_ = y; } |
| 29 | 33 |
| 30 // True if both components are 0. | 34 // True if both components are 0. |
| 31 bool IsZero() const { | 35 bool IsZero() const { |
| 32 return x_ == 0 && y_ == 0; | 36 return x_ == 0 && y_ == 0; |
| 33 } | 37 } |
| 34 | 38 |
| 35 // Add the components of the |other| ScrollOffset to the current ScrollOffset. | 39 // Add the components of the |other| ScrollOffset to the current ScrollOffset. |
| 36 void Add(const ScrollOffset& other) { | 40 void Add(const ScrollOffset& other) { |
| 37 x_ += other.x_; | 41 x_ += other.x_; |
| 38 y_ += other.y_; | 42 y_ += other.y_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 void SetToMin(const ScrollOffset& other) { | 59 void SetToMin(const ScrollOffset& other) { |
| 56 x_ = x_ <= other.x_ ? x_ : other.x_; | 60 x_ = x_ <= other.x_ ? x_ : other.x_; |
| 57 y_ = y_ <= other.y_ ? y_ : other.y_; | 61 y_ = y_ <= other.y_ ? y_ : other.y_; |
| 58 } | 62 } |
| 59 | 63 |
| 60 void SetToMax(const ScrollOffset& other) { | 64 void SetToMax(const ScrollOffset& other) { |
| 61 x_ = x_ >= other.x_ ? x_ : other.x_; | 65 x_ = x_ >= other.x_ ? x_ : other.x_; |
| 62 y_ = y_ >= other.y_ ? y_ : other.y_; | 66 y_ = y_ >= other.y_ ? y_ : other.y_; |
| 63 } | 67 } |
| 64 | 68 |
| 65 void Scale(double scale) { Scale(scale, scale); } | 69 void Scale(float scale) { Scale(scale, scale); } |
| 66 void Scale(double x_scale, double y_scale) { | 70 void Scale(float x_scale, float y_scale) { |
| 67 x_ *= x_scale; | 71 x_ *= x_scale; |
| 68 y_ *= y_scale; | 72 y_ *= y_scale; |
| 69 } | 73 } |
| 70 | 74 |
| 71 std::string ToString() const; | 75 std::string ToString() const; |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 double x_; | 78 float x_; |
| 75 double y_; | 79 float y_; |
| 76 }; | 80 }; |
| 77 | 81 |
| 78 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { | 82 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
| 79 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); | 83 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { | 86 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
| 83 return lhs.x() != rhs.x() || lhs.y() != rhs.y(); | 87 return lhs.x() != rhs.x() || lhs.y() != rhs.y(); |
| 84 } | 88 } |
| 85 | 89 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 116 } | 120 } |
| 117 | 121 |
| 118 // This is declared here for use in gtest-based unit tests but is defined in | 122 // 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 | 123 // 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. | 124 // test. This should not be used in production code - call ToString() instead. |
| 121 void PrintTo(const ScrollOffset& scroll_offset, ::std::ostream* os); | 125 void PrintTo(const ScrollOffset& scroll_offset, ::std::ostream* os); |
| 122 | 126 |
| 123 } // namespace gfx | 127 } // namespace gfx |
| 124 | 128 |
| 125 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ | 129 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
| OLD | NEW |