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 |