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

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: 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..74d735c090e700248fbd8d6aa2b1be5c4146a2c6 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -15,6 +15,9 @@
#include "ui/base/gestures/gesture_util.h"
#include "ui/gfx/rect.h"
+#include <stdio.h>
+
+
namespace ui {
namespace {
@@ -280,10 +283,58 @@ 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;
+
+// True if we've configured the fling scaling bands.
+static bool did_setup_scaling = false;
+
+// Setup a default flat fling acceleration profile.
+static void SetDefaultFlingVelocityScaling() {
sadrul 2012/10/20 01:28:51 I think functions in anonymous namespace don't nee
rjkroege 2012/10/22 15:21:34 Done.
+ 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.
+static void ReadFlingVelocityScalingIfNecessary() {
+ if (did_setup_scaling)
sadrul 2012/10/20 01:28:51 Make |did_setup_scaling| a local static variable i
rjkroege 2012/10/22 15:21:34 Done.
+ return;
+ did_setup_scaling = true;
+ SetDefaultFlingVelocityScaling();
+ char* pk = getenv("BANDED_FLING_VELOCITY_ADJUSTMENT");
+ if (!pk) {
+ LOG(WARNING) << "Could not read configuration var. defaulting.\n";
+ return;
+ }
+
+ char* s = pk;
sadrul 2012/10/20 01:28:51 Perhaps use StringTokenizer (base/string_tokenizer
rjkroege 2012/10/22 15:21:34 Is this really an improvement? :-) Done.
rjkroege 2012/10/22 15:21:34 Done.
+ for (unsigned i = 0; i < kNumberOfFlingVelocityBands; i++) {
+ float f;
+ f = strtof(s, &s);
+ s++;
+ if (f > 0.f)
+ fling_scaling_bands[i] = f;
+ }
+}
+
float CalibrateFlingVelocity(float velocity) {
- const float velocity_scaling =
- GestureConfiguration::touchscreen_fling_acceleration_adjustment();
- return velocity_scaling * velocity;
+ ReadFlingVelocityScalingIfNecessary();
+ float abs_velocity = (velocity < 0) ? velocity * -1: velocity;
sadrul 2012/10/20 01:28:51 abs_velocity = fabs(velocity)?
rjkroege 2012/10/22 15:21:34 Done.
+ abs_velocity = std::min(abs_velocity, kMaxFlingVelocityFromFinger - 1.f);
+ int band =
+ (abs_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