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

Unified Diff: ui/events/gesture_detection/velocity_tracker.cc

Issue 233433005: Remove static-initializeres from VelocityTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 6 years, 8 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
« no previous file with comments | « ui/events/gesture_detection/velocity_tracker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/gesture_detection/velocity_tracker.cc
diff --git a/ui/events/gesture_detection/velocity_tracker.cc b/ui/events/gesture_detection/velocity_tracker.cc
index 639e5ef098bd7671e6d4fbb7af9c73601914ea83..40a30c53e6de1dd358f6d8e3771bd6741a2f8518 100644
--- a/ui/events/gesture_detection/velocity_tracker.cc
+++ b/ui/events/gesture_detection/velocity_tracker.cc
@@ -34,6 +34,12 @@ namespace {
COMPILE_ASSERT(MotionEvent::MAX_POINTER_ID < 32, max_pointer_id_too_large);
+// Threshold for determining that a pointer has stopped moving.
+// Some input devices do not send ACTION_MOVE events in the case where a pointer
+// hasstopped. We need to detect this case so that we can accurately predict
tdresser 2014/04/14 18:22:21 Might as well fix hasstopped while you're here.
jdduke (slow) 2014/04/14 18:40:38 Done.
+// the velocity after the pointer starts moving again.
+const int kAssumePointerStoppedTimeMs = 40;
+
struct Position {
float x, y;
};
@@ -66,13 +72,7 @@ struct Estimator {
}
};
-// Threshold for determining that a pointer has stopped moving.
-// Some input devices do not send ACTION_MOVE events in the case where a pointer
-// hasstopped. We need to detect this case so that we can accurately predict
-// the velocity after the pointer starts moving again.
-const TimeDelta ASSUME_POINTER_STOPPED_TIME = TimeDelta::FromMilliseconds(40);
-
-static float VectorDot(const float* a, const float* b, uint32_t m) {
+float VectorDot(const float* a, const float* b, uint32_t m) {
float r = 0;
while (m--) {
r += *(a++) * *(b++);
@@ -80,7 +80,7 @@ static float VectorDot(const float* a, const float* b, uint32_t m) {
return r;
}
-static float VectorNorm(const float* a, uint32_t m) {
+float VectorNorm(const float* a, uint32_t m) {
float r = 0;
while (m--) {
float t = *(a++);
@@ -107,9 +107,6 @@ class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy {
WEIGHTING_RECENT,
};
- // Number of samples to keep.
- enum { HISTORY_SIZE = 20 };
-
// Degree must be no greater than Estimator::MAX_DEGREE.
LeastSquaresVelocityTrackerStrategy(uint32_t degree,
Weighting weighting = WEIGHTING_NONE);
@@ -124,10 +121,13 @@ class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy {
Estimator* out_estimator) const OVERRIDE;
private:
+ // Number of samples to keep.
+ enum { HISTORY_SIZE = 20 };
+
// Sample horizon.
// We don't use too much history by default since we want to react to quick
// changes in direction.
- static const TimeDelta HORIZON;
+ enum { HORIZON_MS = 100 };
struct Movement {
TimeTicks event_time;
@@ -255,7 +255,8 @@ void VelocityTracker::AddMovement(const TimeTicks& event_time,
id_bits.clear_last_marked_bit();
if ((current_pointer_id_bits_.value & id_bits.value) &&
- event_time >= (last_event_time_ + ASSUME_POINTER_STOPPED_TIME)) {
+ event_time >= (last_event_time_ + base::TimeDelta::FromMilliseconds(
+ kAssumePointerStoppedTimeMs))) {
tdresser 2014/04/14 18:22:21 Is this indentation correct?
jdduke (slow) 2014/04/14 18:40:38 According to "git cl format", yes =/
// We have not received any movements for too long. Assume that all
// pointers
// have stopped.
@@ -377,9 +378,6 @@ bool VelocityTracker::GetEstimator(uint32_t id,
// --- LeastSquaresVelocityTrackerStrategy ---
-const TimeDelta LeastSquaresVelocityTrackerStrategy::HORIZON =
- TimeDelta::FromMilliseconds(100);
-
LeastSquaresVelocityTrackerStrategy::LeastSquaresVelocityTrackerStrategy(
uint32_t degree,
Weighting weighting)
@@ -568,6 +566,7 @@ bool LeastSquaresVelocityTrackerStrategy::GetEstimator(
float time[HISTORY_SIZE];
uint32_t m = 0;
uint32_t index = index_;
+ const base::TimeDelta horizon = base::TimeDelta::FromMilliseconds(HORIZON_MS);
const Movement& newest_movement = movements_[index_];
do {
const Movement& movement = movements_[index];
@@ -575,7 +574,7 @@ bool LeastSquaresVelocityTrackerStrategy::GetEstimator(
break;
TimeDelta age = newest_movement.event_time - movement.event_time;
- if (age > HORIZON)
+ if (age > horizon)
break;
const Position& position = movement.GetPosition(id);
« no previous file with comments | « ui/events/gesture_detection/velocity_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698