Index: ui/gfx/geometry/scroll_offset.h |
diff --git a/ui/gfx/geometry/scroll_offset.h b/ui/gfx/geometry/scroll_offset.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f00a7a406ab9f7cffa9e430c5c684fd3bd28418d |
--- /dev/null |
+++ b/ui/gfx/geometry/scroll_offset.h |
@@ -0,0 +1,80 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
+#define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |
+ |
+#include "ui/gfx/geometry/safe_integer_conversions.h" |
+#include "ui/gfx/geometry/vector2d.h" |
+#include "ui/gfx/gfx_export.h" |
+ |
+namespace gfx { |
+ |
+class GFX_EXPORT ScrollOffset { |
+ public: |
+ ScrollOffset() : x_(0), y_(0) {} |
+ ScrollOffset(double x, double y) : x_(x), y_(y) {} |
+ |
+ double x() const { return x_; } |
+ void set_x(double x) { x_ = x; } |
+ |
+ double y() const { return y_; } |
+ void set_y(double y) { y_ = y; } |
+ |
+ // True if both components are 0. |
+ bool IsZero() const; |
+ |
+ // Add the components of the |other| ScrollOffset to the current ScrollOffset. |
+ void Add(const ScrollOffset& other); |
+ // Subtract the components of the |other| ScrollOffset from the current |
+ // ScrollOffset. |
+ void Subtract(const ScrollOffset& other); |
+ |
+ void operator+=(const ScrollOffset& other) { Add(other); } |
+ void operator-=(const ScrollOffset& other) { Subtract(other); } |
+ |
+ private: |
+ double x_; |
+ double y_; |
+}; |
+ |
+inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
+ return lhs.x() == rhs.x() && lhs.y() == rhs.y(); |
+} |
+ |
+inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) { |
+ return lhs.x() != rhs.x() || lhs.y() != rhs.y(); |
+} |
+ |
+inline ScrollOffset operator-(const ScrollOffset& v) { |
+ return ScrollOffset(-v.x(), -v.y()); |
+} |
+ |
+inline ScrollOffset operator+(const ScrollOffset& lhs, |
+ const ScrollOffset& rhs) { |
+ ScrollOffset result = lhs; |
+ result.Add(rhs); |
+ return result; |
+} |
+ |
+inline ScrollOffset operator-(const ScrollOffset& lhs, |
+ const ScrollOffset& rhs) { |
+ ScrollOffset result = lhs; |
+ result.Add(-rhs); |
+ return result; |
+} |
+ |
+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.
|
+ int x = ToFlooredInt(v.x()); |
+ int y = ToFlooredInt(v.y()); |
+ return Vector2d(x, y); |
+} |
+ |
+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.
|
+ return Vector2dF(v.x(), v.y()); |
+} |
+ |
+} // namespace gfx |
+ |
+#endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_ |