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 <stdlib.h> |
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" |
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 return; |
| 315 LOG(INFO) << "Attempting to configure fling from environment.\n"; |
| 316 |
| 317 unsigned i = 0; |
| 318 CStringTokenizer t(pk, pk + strlen(pk), ","); |
| 319 while (t.GetNext() && i < kNumberOfFlingVelocityBands) { |
| 320 double d; |
| 321 if (base::StringToDouble(t.token(), &d)) { |
| 322 fling_scaling_bands[i++] = d; |
| 323 } else { |
| 324 LOG(WARNING) |
| 325 << "BANDED_FLING_VELOCITY_ADJUSTMENT bad value: " |
| 326 << t.token(); |
| 327 } |
| 328 } |
| 329 } |
| 330 |
283 float CalibrateFlingVelocity(float velocity) { | 331 float CalibrateFlingVelocity(float velocity) { |
284 const float velocity_scaling = | 332 ReadFlingVelocityScalingIfNecessary(); |
285 GestureConfiguration::touchscreen_fling_acceleration_adjustment(); | 333 float bounded_velocity = |
286 return velocity_scaling * velocity; | 334 std::min(fabsf(velocity), kMaxFlingVelocityFromFinger - 1.f); |
| 335 int band = |
| 336 (bounded_velocity / kMaxFlingVelocityFromFinger) * |
| 337 kNumberOfFlingVelocityBands; |
| 338 return fling_scaling_bands[band] * velocity; |
287 } | 339 } |
288 | 340 |
289 } // namespace | 341 } // namespace |
290 | 342 |
291 //////////////////////////////////////////////////////////////////////////////// | 343 //////////////////////////////////////////////////////////////////////////////// |
292 // GestureSequence Public: | 344 // GestureSequence Public: |
293 | 345 |
294 GestureSequence::GestureSequence(GestureEventHelper* helper) | 346 GestureSequence::GestureSequence(GestureEventHelper* helper) |
295 : state_(GS_NO_GESTURE), | 347 : state_(GS_NO_GESTURE), |
296 flags_(0), | 348 flags_(0), |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 return; | 1133 return; |
1082 | 1134 |
1083 // Since long press timer has been started, there should be a non-NULL point. | 1135 // Since long press timer has been started, there should be a non-NULL point. |
1084 const GesturePoint* point = GetPointByPointId(0); | 1136 const GesturePoint* point = GetPointByPointId(0); |
1085 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1137 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
1086 event.location())) | 1138 event.location())) |
1087 long_press_timer_->Stop(); | 1139 long_press_timer_->Stop(); |
1088 } | 1140 } |
1089 | 1141 |
1090 } // namespace ui | 1142 } // namespace ui |
OLD | NEW |