| 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/events/gestures/gesture_sequence.h" | 5 #include "ui/events/gestures/gesture_sequence.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 float a = GestureConfiguration::fling_acceleration_curve_coefficients(i); | 343 float a = GestureConfiguration::fling_acceleration_curve_coefficients(i); |
| 344 nu += x * a; | 344 nu += x * a; |
| 345 x *= normalized_velocity; | 345 x *= normalized_velocity; |
| 346 } | 346 } |
| 347 if (velocity < 0.f) | 347 if (velocity < 0.f) |
| 348 return std::max(nu * velocity, -GestureConfiguration::fling_velocity_cap()); | 348 return std::max(nu * velocity, -GestureConfiguration::fling_velocity_cap()); |
| 349 else | 349 else |
| 350 return std::min(nu * velocity, GestureConfiguration::fling_velocity_cap()); | 350 return std::min(nu * velocity, GestureConfiguration::fling_velocity_cap()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 |
| 354 void UpdateGestureEventLatencyInfo(const TouchEvent& event, |
| 355 GestureSequence::Gestures* gestures) { |
| 356 // If the touch event does not cause any rendering scheduled, then |
| 357 // 1) If the touch event does not generate any gesture event, its |
| 358 // LatencyInfo ends here. |
| 359 // 2) If the touch event generates gesture events, its latencyinfo |
| 360 // is copied into the gesture events. |
| 361 if (!event.latency()->FindLatency( |
| 362 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) { |
| 363 if (gestures->empty()) { |
| 364 ui::LatencyInfo* touch_latency = |
| 365 const_cast<ui::LatencyInfo*>(event.latency()); |
| 366 touch_latency->AddLatencyNumber( |
| 367 ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, 0); |
| 368 } else { |
| 369 GestureSequence::Gestures::iterator it = gestures->begin(); |
| 370 for (; it != gestures->end(); it++) { |
| 371 (*it)->latency()->MergeWith(*event.latency()); |
| 372 // Inheriting the trace_id from the touch event's LatencyInfo |
| 373 (*it)->latency()->trace_id = event.latency()->trace_id; |
| 374 } |
| 375 } |
| 376 } |
| 377 } |
| 378 |
| 353 } // namespace | 379 } // namespace |
| 354 | 380 |
| 355 //////////////////////////////////////////////////////////////////////////////// | 381 //////////////////////////////////////////////////////////////////////////////// |
| 356 // GestureSequence Public: | 382 // GestureSequence Public: |
| 357 | 383 |
| 358 GestureSequence::GestureSequence(GestureEventHelper* helper) | 384 GestureSequence::GestureSequence(GestureEventHelper* helper) |
| 359 : state_(GS_NO_GESTURE), | 385 : state_(GS_NO_GESTURE), |
| 360 flags_(0), | 386 flags_(0), |
| 361 pinch_distance_start_(0.f), | 387 pinch_distance_start_(0.f), |
| 362 pinch_distance_current_(0.f), | 388 pinch_distance_current_(0.f), |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 point.Reset(); | 615 point.Reset(); |
| 590 --point_count_; | 616 --point_count_; |
| 591 CHECK_GE(point_count_, 0); | 617 CHECK_GE(point_count_, 0); |
| 592 RecreateBoundingBox(); | 618 RecreateBoundingBox(); |
| 593 if (state_ == GS_PINCH) { | 619 if (state_ == GS_PINCH) { |
| 594 pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_); | 620 pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_); |
| 595 pinch_distance_start_ = pinch_distance_current_; | 621 pinch_distance_start_ = pinch_distance_current_; |
| 596 } | 622 } |
| 597 } | 623 } |
| 598 | 624 |
| 599 const ui::LatencyInfo* touch_latency = event.latency(); | 625 UpdateGestureEventLatencyInfo(event, gestures.get()); |
| 600 Gestures::iterator it = gestures->begin(); | |
| 601 for (; it != gestures->end(); it++) { | |
| 602 (*it)->latency()->MergeWith(*touch_latency); | |
| 603 } | |
| 604 | |
| 605 return gestures.release(); | 626 return gestures.release(); |
| 606 } | 627 } |
| 607 | 628 |
| 608 void GestureSequence::RecreateBoundingBox() { | 629 void GestureSequence::RecreateBoundingBox() { |
| 609 // TODO(sad): Recreating the bounding box at every touch-event is not very | 630 // TODO(sad): Recreating the bounding box at every touch-event is not very |
| 610 // efficient. This should be made better. | 631 // efficient. This should be made better. |
| 611 if (point_count_ == 0) { | 632 if (point_count_ == 0) { |
| 612 bounding_box_.SetRect(0, 0, 0, 0); | 633 bounding_box_.SetRect(0, 0, 0, 0); |
| 613 } else if (point_count_ == 1) { | 634 } else if (point_count_ == 1) { |
| 614 bounding_box_ = GetPointByPointId(0)->enclosing_rectangle(); | 635 bounding_box_ = GetPointByPointId(0)->enclosing_rectangle(); |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 return; | 1250 return; |
| 1230 | 1251 |
| 1231 // Since long press timer has been started, there should be a non-NULL point. | 1252 // Since long press timer has been started, there should be a non-NULL point. |
| 1232 const GesturePoint* point = GetPointByPointId(0); | 1253 const GesturePoint* point = GetPointByPointId(0); |
| 1233 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1254 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
| 1234 event.location())) | 1255 event.location())) |
| 1235 GetLongPressTimer()->Stop(); | 1256 GetLongPressTimer()->Stop(); |
| 1236 } | 1257 } |
| 1237 | 1258 |
| 1238 } // namespace ui | 1259 } // namespace ui |
| OLD | NEW |