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

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: scroll delta -> vector2dF, scroll offset -> ScrollOffset 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..389d04c20fc41690b81cff57e20bf6c6e22ef7f8
--- /dev/null
+++ b/ui/gfx/geometry/scroll_offset.h
@@ -0,0 +1,94 @@
+// 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 {
danakj 2014/09/25 22:01:27 Please add PrintTo like we have for other geometry
Yufeng Shen (Slow to review) 2014/09/26 20:19:08 Done.
+ public:
+ ScrollOffset() : x_(0), y_(0) {}
danakj 2014/09/25 22:01:27 Can you add some unit tests for this class, simila
Yufeng Shen (Slow to review) 2014/09/26 20:19:08 Done.
+ ScrollOffset(double x, double y) : x_(x), y_(y) {}
+ explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {}
+ explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.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); }
+
+ void SetToMin(const ScrollOffset& other) {
+ x_ = x_ <= other.x_ ? x_ : other.x_;
+ y_ = y_ <= other.y_ ? y_ : other.y_;
+ }
+
+ void SetToMax(const ScrollOffset& other) {
+ x_ = x_ >= other.x_ ? x_ : other.x_;
+ y_ = y_ >= other.y_ ? y_ : other.y_;
+ }
+
+ void Scale(double scale) { Scale(scale, scale); }
+ void Scale(double x_scale, double y_scale) {
+ x_ *= x_scale;
+ y_ *= y_scale;
+ }
+
+ Vector2d ToFlooredVector2d() const {
danakj 2014/09/25 22:01:27 Sorry, can I take this back? ._. Now that I see ho
Yufeng Shen (Slow to review) 2014/09/26 20:19:08 Done.
+ return Vector2d(ToFlooredInt(x_), ToFlooredInt(y_));
+ }
+
+ Vector2dF ToVector2dF() const { return Vector2dF(x_, y_); }
+
+ 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;
+}
+
+} // namespace gfx
+
+#endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_

Powered by Google App Engine
This is Rietveld 408576698