Chromium Code Reviews| 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..44eb8d9b0b22b92b404b9cd38c48812da7f2007c 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 <stdio.h> |
|
sadrul
2012/10/22 16:24:28
This isn't needed anymore.
rjkroege
2012/10/23 19:10:52
stdlib is needed for getenv. Changed.
|
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base//string_number_conversions.h" |
| +#include "base//string_tokenizer.h" |
|
sadrul
2012/10/22 16:24:28
// -> /
rjkroege
2012/10/23 19:10:52
Done.
|
| #include "base/time.h" |
| #include "ui/base/events/event.h" |
| #include "ui/base/events/event_constants.h" |
| @@ -280,10 +283,60 @@ 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) { |
| + LOG(WARNING) << "Could not read configuration var. defaulting.\n"; |
|
sadrul
2012/10/22 16:24:28
This might show up in the test output, and will ca
rjkroege
2012/10/23 19:10:52
Done.
|
| + return; |
| + } |
| + |
| + unsigned i = 0; |
| + CStringTokenizer t(pk, pk + strlen(pk), ","); |
| + while (t.GetNext() && i < kNumberOfFlingVelocityBands) { |
| + double d; |
| + if (base::StringToDouble(t.token(), &d)) |
|
sadrul
2012/10/22 16:24:28
Braces (in chrome, if any of the if/else requires
rjkroege
2012/10/23 19:10:52
Done. I like Chrome land better.
|
| + 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 |