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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_GFX_GEOMETRY_SCROLL_OFFSET_H_
6 #define UI_GFX_GEOMETRY_SCROLL_OFFSET_H_
7
8 #include "ui/gfx/geometry/safe_integer_conversions.h"
9 #include "ui/gfx/geometry/vector2d.h"
10 #include "ui/gfx/gfx_export.h"
11
12 namespace gfx {
13
14 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.
15 public:
16 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.
17 ScrollOffset(double x, double y) : x_(x), y_(y) {}
18 explicit ScrollOffset(const Vector2dF& v) : x_(v.x()), y_(v.y()) {}
19 explicit ScrollOffset(const Vector2d& v) : x_(v.x()), y_(v.y()) {}
20
21 double x() const { return x_; }
22 void set_x(double x) { x_ = x; }
23
24 double y() const { return y_; }
25 void set_y(double y) { y_ = y; }
26
27 // True if both components are 0.
28 bool IsZero() const;
29
30 // Add the components of the |other| ScrollOffset to the current ScrollOffset.
31 void Add(const ScrollOffset& other);
32 // Subtract the components of the |other| ScrollOffset from the current
33 // ScrollOffset.
34 void Subtract(const ScrollOffset& other);
35
36 void operator+=(const ScrollOffset& other) { Add(other); }
37 void operator-=(const ScrollOffset& other) { Subtract(other); }
38
39 void SetToMin(const ScrollOffset& other) {
40 x_ = x_ <= other.x_ ? x_ : other.x_;
41 y_ = y_ <= other.y_ ? y_ : other.y_;
42 }
43
44 void SetToMax(const ScrollOffset& other) {
45 x_ = x_ >= other.x_ ? x_ : other.x_;
46 y_ = y_ >= other.y_ ? y_ : other.y_;
47 }
48
49 void Scale(double scale) { Scale(scale, scale); }
50 void Scale(double x_scale, double y_scale) {
51 x_ *= x_scale;
52 y_ *= y_scale;
53 }
54
55 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.
56 return Vector2d(ToFlooredInt(x_), ToFlooredInt(y_));
57 }
58
59 Vector2dF ToVector2dF() const { return Vector2dF(x_, y_); }
60
61 private:
62 double x_;
63 double y_;
64 };
65
66 inline bool operator==(const ScrollOffset& lhs, const ScrollOffset& rhs) {
67 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
68 }
69
70 inline bool operator!=(const ScrollOffset& lhs, const ScrollOffset& rhs) {
71 return lhs.x() != rhs.x() || lhs.y() != rhs.y();
72 }
73
74 inline ScrollOffset operator-(const ScrollOffset& v) {
75 return ScrollOffset(-v.x(), -v.y());
76 }
77
78 inline ScrollOffset operator+(const ScrollOffset& lhs,
79 const ScrollOffset& rhs) {
80 ScrollOffset result = lhs;
81 result.Add(rhs);
82 return result;
83 }
84
85 inline ScrollOffset operator-(const ScrollOffset& lhs,
86 const ScrollOffset& rhs) {
87 ScrollOffset result = lhs;
88 result.Add(-rhs);
89 return result;
90 }
91
92 } // namespace gfx
93
94 #endif // UI_GFX_GEOMETRY_SCROLL_OFFSET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698