Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Unified Diff: ui/gfx/geometry/scroll_offset.h

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ScrollOffset instead of vector2dF for scroll offset Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698