Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #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.
| |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base//string_number_conversions.h" | |
| 13 #include "base//string_tokenizer.h" | |
|
sadrul
2012/10/22 16:24:28
// -> /
rjkroege
2012/10/23 19:10:52
Done.
| |
| 11 #include "base/time.h" | 14 #include "base/time.h" |
| 12 #include "ui/base/events/event.h" | 15 #include "ui/base/events/event.h" |
| 13 #include "ui/base/events/event_constants.h" | 16 #include "ui/base/events/event_constants.h" |
| 14 #include "ui/base/gestures/gesture_configuration.h" | 17 #include "ui/base/gestures/gesture_configuration.h" |
| 15 #include "ui/base/gestures/gesture_util.h" | 18 #include "ui/base/gestures/gesture_util.h" |
| 16 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 17 | 20 |
| 18 namespace ui { | 21 namespace ui { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Setup a default flat fling acceleration profile. | |
| 296 void SetDefaultFlingVelocityScaling() { | |
| 297 for (unsigned i = 0; i < kNumberOfFlingVelocityBands; i++) { | |
| 298 fling_scaling_bands[i] = | |
| 299 GestureConfiguration::touchscreen_fling_acceleration_adjustment(); | |
| 300 } | |
| 301 } | |
| 302 | |
| 303 // Read |kNumberOfFlingVelocityBands| comma-separated floating point | |
| 304 // values from an environment variable and use that to configure the fling | |
| 305 // velocity profile. | |
| 306 void ReadFlingVelocityScalingIfNecessary() { | |
| 307 static bool did_setup_scaling = false; | |
| 308 if (did_setup_scaling) | |
| 309 return; | |
| 310 did_setup_scaling = true; | |
| 311 SetDefaultFlingVelocityScaling(); | |
| 312 char* pk = getenv("BANDED_FLING_VELOCITY_ADJUSTMENT"); | |
| 313 if (!pk) { | |
| 314 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.
| |
| 315 return; | |
| 316 } | |
| 317 | |
| 318 unsigned i = 0; | |
| 319 CStringTokenizer t(pk, pk + strlen(pk), ","); | |
| 320 while (t.GetNext() && i < kNumberOfFlingVelocityBands) { | |
| 321 double d; | |
| 322 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.
| |
| 323 fling_scaling_bands[i++] = d; | |
| 324 else { | |
| 325 LOG(WARNING) | |
| 326 << "BANDED_FLING_VELOCITY_ADJUSTMENT bad value: " | |
| 327 << t.token(); | |
| 328 } | |
| 329 } | |
| 330 } | |
| 331 | |
| 283 float CalibrateFlingVelocity(float velocity) { | 332 float CalibrateFlingVelocity(float velocity) { |
| 284 const float velocity_scaling = | 333 ReadFlingVelocityScalingIfNecessary(); |
| 285 GestureConfiguration::touchscreen_fling_acceleration_adjustment(); | 334 float bounded_velocity = |
| 286 return velocity_scaling * velocity; | 335 std::min(fabsf(velocity), kMaxFlingVelocityFromFinger - 1.f); |
| 336 int band = | |
| 337 (bounded_velocity / kMaxFlingVelocityFromFinger) * | |
| 338 kNumberOfFlingVelocityBands; | |
| 339 return fling_scaling_bands[band] * velocity; | |
| 287 } | 340 } |
| 288 | 341 |
| 289 } // namespace | 342 } // namespace |
| 290 | 343 |
| 291 //////////////////////////////////////////////////////////////////////////////// | 344 //////////////////////////////////////////////////////////////////////////////// |
| 292 // GestureSequence Public: | 345 // GestureSequence Public: |
| 293 | 346 |
| 294 GestureSequence::GestureSequence(GestureEventHelper* helper) | 347 GestureSequence::GestureSequence(GestureEventHelper* helper) |
| 295 : state_(GS_NO_GESTURE), | 348 : state_(GS_NO_GESTURE), |
| 296 flags_(0), | 349 flags_(0), |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 return; | 1134 return; |
| 1082 | 1135 |
| 1083 // Since long press timer has been started, there should be a non-NULL point. | 1136 // Since long press timer has been started, there should be a non-NULL point. |
| 1084 const GesturePoint* point = GetPointByPointId(0); | 1137 const GesturePoint* point = GetPointByPointId(0); |
| 1085 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1138 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
| 1086 event.location())) | 1139 event.location())) |
| 1087 long_press_timer_->Stop(); | 1140 long_press_timer_->Stop(); |
| 1088 } | 1141 } |
| 1089 | 1142 |
| 1090 } // namespace ui | 1143 } // namespace ui |
| OLD | NEW |