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

Unified Diff: ui/base/gestures/gesture_sequence.cc

Issue 11231018: Add a mechanism to provide non-linear scaling of fling acceleration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more review nits Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/gestures/gesture_sequence.cc
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc
index bc3b4f46d9b2ca7416adc10b4c66eaee37e389ff..98661ad5f1f48971adc4930c25108d48da907428 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -5,9 +5,12 @@
#include "ui/base/gestures/gesture_sequence.h"
#include <cmath>
+#include <stdlib.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/string_number_conversions.h"
+#include "base//string_tokenizer.h"
#include "base/time.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_constants.h"
@@ -280,10 +283,59 @@ unsigned int ComputeTouchBitmask(const GesturePoint* points) {
return touch_bitmask;
}
+// Number of different accelerations for fling velocity adjustment.
+const unsigned kNumberOfFlingVelocityBands = 8;
+
+// Fling acceleration bands.
+static float fling_scaling_bands[kNumberOfFlingVelocityBands];
+
+// Maximum fling velocity.
+const float kMaxFlingVelocityFromFinger = 15000.0f;
+
+// Setup a default flat fling acceleration profile.
+void SetDefaultFlingVelocityScaling() {
+ for (unsigned i = 0; i < kNumberOfFlingVelocityBands; i++) {
+ fling_scaling_bands[i] =
+ GestureConfiguration::touchscreen_fling_acceleration_adjustment();
+ }
+}
+
+// Read |kNumberOfFlingVelocityBands| comma-separated floating point
+// values from an environment variable and use that to configure the fling
+// velocity profile.
+void ReadFlingVelocityScalingIfNecessary() {
+ static bool did_setup_scaling = false;
+ if (did_setup_scaling)
+ return;
+ did_setup_scaling = true;
+ SetDefaultFlingVelocityScaling();
+ char* pk = getenv("BANDED_FLING_VELOCITY_ADJUSTMENT");
+ if (!pk)
+ return;
+ LOG(INFO) << "Attempting to configure fling from environment.\n";
+
+ unsigned i = 0;
+ CStringTokenizer t(pk, pk + strlen(pk), ",");
+ while (t.GetNext() && i < kNumberOfFlingVelocityBands) {
+ double d;
+ if (base::StringToDouble(t.token(), &d)) {
+ fling_scaling_bands[i++] = d;
+ } else {
+ LOG(WARNING)
+ << "BANDED_FLING_VELOCITY_ADJUSTMENT bad value: "
+ << t.token();
+ }
+ }
+}
+
float CalibrateFlingVelocity(float velocity) {
- const float velocity_scaling =
- GestureConfiguration::touchscreen_fling_acceleration_adjustment();
- return velocity_scaling * velocity;
+ ReadFlingVelocityScalingIfNecessary();
+ float bounded_velocity =
+ std::min(fabsf(velocity), kMaxFlingVelocityFromFinger - 1.f);
+ int band =
+ (bounded_velocity / kMaxFlingVelocityFromFinger) *
+ kNumberOfFlingVelocityBands;
+ return fling_scaling_bands[band] * velocity;
}
} // namespace
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698