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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/gestures/gesture_sequence.h" 5 #include "ui/base/gestures/gesture_sequence.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "ui/base/events/event.h" 12 #include "ui/base/events/event.h"
13 #include "ui/base/events/event_constants.h" 13 #include "ui/base/events/event_constants.h"
14 #include "ui/base/gestures/gesture_configuration.h" 14 #include "ui/base/gestures/gesture_configuration.h"
15 #include "ui/base/gestures/gesture_util.h" 15 #include "ui/base/gestures/gesture_util.h"
16 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
17 17
18 #include <stdio.h>
19
20
18 namespace ui { 21 namespace ui {
19 22
20 namespace { 23 namespace {
21 24
22 // ui::EventType is mapped to TouchState so it can fit into 3 bits of 25 // ui::EventType is mapped to TouchState so it can fit into 3 bits of
23 // Signature. 26 // Signature.
24 enum TouchState { 27 enum TouchState {
25 TS_RELEASED, 28 TS_RELEASED,
26 TS_PRESSED, 29 TS_PRESSED,
27 TS_MOVED, 30 TS_MOVED,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 276
274 unsigned int ComputeTouchBitmask(const GesturePoint* points) { 277 unsigned int ComputeTouchBitmask(const GesturePoint* points) {
275 unsigned int touch_bitmask = 0; 278 unsigned int touch_bitmask = 0;
276 for (int i = 0; i < GestureSequence::kMaxGesturePoints; ++i) { 279 for (int i = 0; i < GestureSequence::kMaxGesturePoints; ++i) {
277 if (points[i].in_use()) 280 if (points[i].in_use())
278 touch_bitmask |= 1 << points[i].touch_id(); 281 touch_bitmask |= 1 << points[i].touch_id();
279 } 282 }
280 return touch_bitmask; 283 return touch_bitmask;
281 } 284 }
282 285
286 // Number of different accelerations for fling velocity adjustment.
287 const unsigned kNumberOfFlingVelocityBands = 8;
288
289 // Fling acceleration bands.
290 static float fling_scaling_bands[kNumberOfFlingVelocityBands];
291
292 // Maximum fling velocity.
293 const float kMaxFlingVelocityFromFinger = 15000.0f;
294
295 // True if we've configured the fling scaling bands.
296 static bool did_setup_scaling = false;
297
298 // Setup a default flat fling acceleration profile.
299 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.
300 for (unsigned i = 0; i < kNumberOfFlingVelocityBands; i++) {
301 fling_scaling_bands[i] =
302 GestureConfiguration::touchscreen_fling_acceleration_adjustment();
303 }
304 }
305
306 // Read |kNumberOfFlingVelocityBands| comma-separated floating point
307 // values from an environment variable and use that to configure the fling
308 // velocity profile.
309 static void ReadFlingVelocityScalingIfNecessary() {
310 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.
311 return;
312 did_setup_scaling = true;
313 SetDefaultFlingVelocityScaling();
314 char* pk = getenv("BANDED_FLING_VELOCITY_ADJUSTMENT");
315 if (!pk) {
316 LOG(WARNING) << "Could not read configuration var. defaulting.\n";
317 return;
318 }
319
320 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.
321 for (unsigned i = 0; i < kNumberOfFlingVelocityBands; i++) {
322 float f;
323 f = strtof(s, &s);
324 s++;
325 if (f > 0.f)
326 fling_scaling_bands[i] = f;
327 }
328 }
329
283 float CalibrateFlingVelocity(float velocity) { 330 float CalibrateFlingVelocity(float velocity) {
284 const float velocity_scaling = 331 ReadFlingVelocityScalingIfNecessary();
285 GestureConfiguration::touchscreen_fling_acceleration_adjustment(); 332 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.
286 return velocity_scaling * velocity; 333 abs_velocity = std::min(abs_velocity, kMaxFlingVelocityFromFinger - 1.f);
334 int band =
335 (abs_velocity / kMaxFlingVelocityFromFinger) *
336 kNumberOfFlingVelocityBands;
337 return fling_scaling_bands[band] * velocity;
287 } 338 }
288 339
289 } // namespace 340 } // namespace
290 341
291 //////////////////////////////////////////////////////////////////////////////// 342 ////////////////////////////////////////////////////////////////////////////////
292 // GestureSequence Public: 343 // GestureSequence Public:
293 344
294 GestureSequence::GestureSequence(GestureEventHelper* helper) 345 GestureSequence::GestureSequence(GestureEventHelper* helper)
295 : state_(GS_NO_GESTURE), 346 : state_(GS_NO_GESTURE),
296 flags_(0), 347 flags_(0),
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 return; 1132 return;
1082 1133
1083 // Since long press timer has been started, there should be a non-NULL point. 1134 // Since long press timer has been started, there should be a non-NULL point.
1084 const GesturePoint* point = GetPointByPointId(0); 1135 const GesturePoint* point = GetPointByPointId(0);
1085 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), 1136 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
1086 event.location())) 1137 event.location()))
1087 long_press_timer_->Stop(); 1138 long_press_timer_->Stop();
1088 } 1139 }
1089 1140
1090 } // namespace ui 1141 } // namespace ui
OLDNEW
« 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