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

Side by Side Diff: ui/events/gesture_detection/velocity_tracker.cc

Issue 667923002: Standardize usage of virtual/override/final in ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « ui/events/gesture_detection/scale_gesture_listeners.h ('k') | ui/events/gestures/fling_curve.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/events/gesture_detection/velocity_tracker.h" 5 #include "ui/events/gesture_detection/velocity_tracker.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/events/gesture_detection/motion_event.h" 10 #include "ui/events/gesture_detection/motion_event.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Weight such that points older than a certain amount are weighed less. 112 // Weight such that points older than a certain amount are weighed less.
113 WEIGHTING_RECENT, 113 WEIGHTING_RECENT,
114 }; 114 };
115 115
116 // Number of samples to keep. 116 // Number of samples to keep.
117 static const uint8_t kHistorySize = 20; 117 static const uint8_t kHistorySize = 20;
118 118
119 // Degree must be no greater than Estimator::kMaxDegree. 119 // Degree must be no greater than Estimator::kMaxDegree.
120 LeastSquaresVelocityTrackerStrategy(uint32_t degree, 120 LeastSquaresVelocityTrackerStrategy(uint32_t degree,
121 Weighting weighting = WEIGHTING_NONE); 121 Weighting weighting = WEIGHTING_NONE);
122 virtual ~LeastSquaresVelocityTrackerStrategy(); 122 ~LeastSquaresVelocityTrackerStrategy() override;
123 123
124 virtual void Clear() override; 124 void Clear() override;
125 virtual void ClearPointers(BitSet32 id_bits) override; 125 void ClearPointers(BitSet32 id_bits) override;
126 virtual void AddMovement(const TimeTicks& event_time, 126 void AddMovement(const TimeTicks& event_time,
127 BitSet32 id_bits, 127 BitSet32 id_bits,
128 const Position* positions) override; 128 const Position* positions) override;
129 virtual bool GetEstimator(uint32_t id, 129 bool GetEstimator(uint32_t id, Estimator* out_estimator) const override;
130 Estimator* out_estimator) const override;
131 130
132 private: 131 private:
133 // Sample horizon. 132 // Sample horizon.
134 // We don't use too much history by default since we want to react to quick 133 // We don't use too much history by default since we want to react to quick
135 // changes in direction. 134 // changes in direction.
136 static const uint8_t kHorizonMS = 100; 135 static const uint8_t kHorizonMS = 100;
137 136
138 struct Movement { 137 struct Movement {
139 TimeTicks event_time; 138 TimeTicks event_time;
140 BitSet32 id_bits; 139 BitSet32 id_bits;
(...skipping 10 matching lines...) Expand all
151 const Weighting weighting_; 150 const Weighting weighting_;
152 uint32_t index_; 151 uint32_t index_;
153 Movement movements_[kHistorySize]; 152 Movement movements_[kHistorySize];
154 }; 153 };
155 154
156 // Velocity tracker algorithm that uses an IIR filter. 155 // Velocity tracker algorithm that uses an IIR filter.
157 class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy { 156 class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy {
158 public: 157 public:
159 // Degree must be 1 or 2. 158 // Degree must be 1 or 2.
160 explicit IntegratingVelocityTrackerStrategy(uint32_t degree); 159 explicit IntegratingVelocityTrackerStrategy(uint32_t degree);
161 virtual ~IntegratingVelocityTrackerStrategy(); 160 ~IntegratingVelocityTrackerStrategy() override;
162 161
163 virtual void Clear() override; 162 void Clear() override;
164 virtual void ClearPointers(BitSet32 id_bits) override; 163 void ClearPointers(BitSet32 id_bits) override;
165 virtual void AddMovement(const TimeTicks& event_time, 164 void AddMovement(const TimeTicks& event_time,
166 BitSet32 id_bits, 165 BitSet32 id_bits,
167 const Position* positions) override; 166 const Position* positions) override;
168 virtual bool GetEstimator(uint32_t id, 167 bool GetEstimator(uint32_t id, Estimator* out_estimator) const override;
169 Estimator* out_estimator) const override;
170 168
171 private: 169 private:
172 // Current state estimate for a particular pointer. 170 // Current state estimate for a particular pointer.
173 struct State { 171 struct State {
174 TimeTicks update_time; 172 TimeTicks update_time;
175 uint32_t degree; 173 uint32_t degree;
176 174
177 float xpos, xvel, xaccel; 175 float xpos, xvel, xaccel;
178 float ypos, yvel, yaccel; 176 float ypos, yvel, yaccel;
179 }; 177 };
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 out_estimator->degree = state.degree; 806 out_estimator->degree = state.degree;
809 out_estimator->xcoeff[0] = state.xpos; 807 out_estimator->xcoeff[0] = state.xpos;
810 out_estimator->xcoeff[1] = state.xvel; 808 out_estimator->xcoeff[1] = state.xvel;
811 out_estimator->xcoeff[2] = state.xaccel / 2; 809 out_estimator->xcoeff[2] = state.xaccel / 2;
812 out_estimator->ycoeff[0] = state.ypos; 810 out_estimator->ycoeff[0] = state.ypos;
813 out_estimator->ycoeff[1] = state.yvel; 811 out_estimator->ycoeff[1] = state.yvel;
814 out_estimator->ycoeff[2] = state.yaccel / 2; 812 out_estimator->ycoeff[2] = state.yaccel / 2;
815 } 813 }
816 814
817 } // namespace ui 815 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/scale_gesture_listeners.h ('k') | ui/events/gestures/fling_curve.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698