| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/events/gesture_detection/gesture_detector.h" | 8 #include "ui/events/gesture_detection/gesture_detector.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 velocity_tracker_.Clear(); | 239 velocity_tracker_.Clear(); |
| 240 break; | 240 break; |
| 241 } | 241 } |
| 242 vx_total += vx2; | 242 vx_total += vx2; |
| 243 vy_total += vy2; | 243 vy_total += vy2; |
| 244 } | 244 } |
| 245 | 245 |
| 246 handled = HandleSwipeIfNeeded(ev, vx_total / count, vy_total / count); | 246 handled = HandleSwipeIfNeeded(ev, vx_total / count, vy_total / count); |
| 247 | 247 |
| 248 if (two_finger_tap_allowed_for_gesture_ && ev.GetPointerCount() == 2 && | 248 if (two_finger_tap_allowed_for_gesture_ && ev.GetPointerCount() == 2 && |
| 249 secondary_pointer_down_event_ && |
| 249 (ev.GetEventTime() - secondary_pointer_down_event_->GetEventTime() <= | 250 (ev.GetEventTime() - secondary_pointer_down_event_->GetEventTime() <= |
| 250 two_finger_tap_timeout_)) { | 251 two_finger_tap_timeout_)) { |
| 251 handled = listener_->OnTwoFingerTap(*current_down_event_, ev); | 252 handled = listener_->OnTwoFingerTap(*current_down_event_, ev); |
| 252 } | 253 } |
| 253 two_finger_tap_allowed_for_gesture_ = false; | 254 two_finger_tap_allowed_for_gesture_ = false; |
| 254 } break; | 255 } break; |
| 255 | 256 |
| 256 case MotionEvent::ACTION_DOWN: { | 257 case MotionEvent::ACTION_DOWN: { |
| 257 bool is_repeated_tap = | 258 bool is_repeated_tap = |
| 258 current_down_event_ && previous_up_event_ && | 259 current_down_event_ && previous_up_event_ && |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 548 |
| 548 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) { | 549 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) { |
| 549 // If there have been more than two down pointers in the touch sequence, | 550 // If there have been more than two down pointers in the touch sequence, |
| 550 // tapping is not possible. Slop region check is not needed. | 551 // tapping is not possible. Slop region check is not needed. |
| 551 if (maximum_pointer_count_ > 2) | 552 if (maximum_pointer_count_ > 2) |
| 552 return false; | 553 return false; |
| 553 | 554 |
| 554 for (size_t i = 0; i < ev.GetPointerCount(); i++) { | 555 for (size_t i = 0; i < ev.GetPointerCount(); i++) { |
| 555 const int pointer_id = ev.GetPointerId(i); | 556 const int pointer_id = ev.GetPointerId(i); |
| 556 const MotionEvent* source_pointer_down_event = GetSourcePointerDownEvent( | 557 const MotionEvent* source_pointer_down_event = GetSourcePointerDownEvent( |
| 557 *current_down_event_, | 558 *current_down_event_.get(), secondary_pointer_down_event_.get(), |
| 558 (maximum_pointer_count_ > 1 && secondary_pointer_down_event_) | |
| 559 ? *secondary_pointer_down_event_ | |
| 560 : *current_down_event_, | |
| 561 pointer_id); | 559 pointer_id); |
| 562 DCHECK(source_pointer_down_event); | 560 |
| 563 if (!source_pointer_down_event) | 561 if (!source_pointer_down_event) |
| 564 return false; | 562 return false; |
| 565 | 563 |
| 566 int source_index = | 564 int source_index = |
| 567 source_pointer_down_event->FindPointerIndexOfId(pointer_id); | 565 source_pointer_down_event->FindPointerIndexOfId(pointer_id); |
| 568 DCHECK_GE(source_index, 0); | 566 DCHECK_GE(source_index, 0); |
| 569 if (source_index < 0) | 567 if (source_index < 0) |
| 570 return false; | 568 return false; |
| 571 | 569 |
| 572 float dx = source_pointer_down_event->GetX(source_index) - ev.GetX(i); | 570 float dx = source_pointer_down_event->GetX(source_index) - ev.GetX(i); |
| 573 float dy = source_pointer_down_event->GetY(source_index) - ev.GetY(i); | 571 float dy = source_pointer_down_event->GetY(source_index) - ev.GetY(i); |
| 574 if (dx * dx + dy * dy > touch_slop_square_) | 572 if (dx * dx + dy * dy > touch_slop_square_) |
| 575 return false; | 573 return false; |
| 576 } | 574 } |
| 577 | 575 |
| 578 return true; | 576 return true; |
| 579 } | 577 } |
| 580 | 578 |
| 581 const MotionEvent* GestureDetector::GetSourcePointerDownEvent( | 579 const MotionEvent* GestureDetector::GetSourcePointerDownEvent( |
| 582 const MotionEvent& current_down_event, | 580 const MotionEvent& current_down_event, |
| 583 const MotionEvent& secondary_pointer_down_event, | 581 const MotionEvent* secondary_pointer_down_event, |
| 584 const int pointer_id) { | 582 const int pointer_id) { |
| 585 if (current_down_event.GetPointerId(0) == pointer_id) | 583 if (current_down_event.GetPointerId(0) == pointer_id) |
| 586 return ¤t_down_event; | 584 return ¤t_down_event; |
| 587 | 585 |
| 588 for (size_t i = 0; i < secondary_pointer_down_event.GetPointerCount(); i++) { | 586 // Secondary pointer down event is sometimes missing (crbug.com/704426), the |
| 589 if (secondary_pointer_down_event.GetPointerId(i) == pointer_id) | 587 // source pointer down event is not found in these cases. |
| 590 return &secondary_pointer_down_event; | 588 // crbug.com/704426 is the only related bug report and we don't have any |
| 589 // reliable repro of the bug. |
| 590 if (!secondary_pointer_down_event) |
| 591 return nullptr; |
| 592 |
| 593 for (size_t i = 0; i < secondary_pointer_down_event->GetPointerCount(); i++) { |
| 594 if (secondary_pointer_down_event->GetPointerId(i) == pointer_id) |
| 595 return secondary_pointer_down_event; |
| 591 } | 596 } |
| 592 | 597 |
| 593 NOTREACHED(); | |
| 594 return nullptr; | 598 return nullptr; |
| 595 } | 599 } |
| 596 | 600 |
| 597 } // namespace ui | 601 } // namespace ui |
| OLD | NEW |