| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 const float scroll_x = last_focus_x_ - focus_x; | 304 const float scroll_x = last_focus_x_ - focus_x; |
| 305 const float scroll_y = last_focus_y_ - focus_y; | 305 const float scroll_y = last_focus_y_ - focus_y; |
| 306 if (is_double_tapping_) { | 306 if (is_double_tapping_) { |
| 307 // Give the move events of the double-tap. | 307 // Give the move events of the double-tap. |
| 308 DCHECK(double_tap_listener_); | 308 DCHECK(double_tap_listener_); |
| 309 handled |= double_tap_listener_->OnDoubleTapEvent(ev); | 309 handled |= double_tap_listener_->OnDoubleTapEvent(ev); |
| 310 } else if (all_pointers_within_slop_regions_) { | 310 } else if (all_pointers_within_slop_regions_) { |
| 311 if (!IsWithinTouchSlop(ev)) { | 311 if (!IsWithinTouchSlop(ev)) { |
| 312 handled = listener_->OnScroll( | 312 handled = listener_->OnScroll( |
| 313 *current_down_event_, ev, | 313 *current_down_event_, ev, |
| 314 (maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_ | 314 (maximum_pointer_count_ > 1 && secondary_pointer_down_event_) |
| 315 : ev), | 315 ? *secondary_pointer_down_event_ |
| 316 : ev, |
| 316 scroll_x, scroll_y); | 317 scroll_x, scroll_y); |
| 317 last_focus_x_ = focus_x; | 318 last_focus_x_ = focus_x; |
| 318 last_focus_y_ = focus_y; | 319 last_focus_y_ = focus_y; |
| 319 all_pointers_within_slop_regions_ = false; | 320 all_pointers_within_slop_regions_ = false; |
| 320 timeout_handler_->Stop(); | 321 timeout_handler_->Stop(); |
| 321 } | 322 } |
| 322 | 323 |
| 323 const float delta_x = focus_x - down_focus_x_; | 324 const float delta_x = focus_x - down_focus_x_; |
| 324 const float delta_y = focus_y - down_focus_y_; | 325 const float delta_y = focus_y - down_focus_y_; |
| 325 const float distance_square = delta_x * delta_x + delta_y * delta_y; | 326 const float distance_square = delta_x * delta_x + delta_y * delta_y; |
| 326 if (distance_square > double_tap_touch_slop_square_) | 327 if (distance_square > double_tap_touch_slop_square_) |
| 327 always_in_bigger_tap_region_ = false; | 328 always_in_bigger_tap_region_ = false; |
| 328 } else if (std::abs(scroll_x) > kScrollEpsilon || | 329 } else if (std::abs(scroll_x) > kScrollEpsilon || |
| 329 std::abs(scroll_y) > kScrollEpsilon) { | 330 std::abs(scroll_y) > kScrollEpsilon) { |
| 330 handled = listener_->OnScroll( | 331 handled = listener_->OnScroll( |
| 331 *current_down_event_, ev, | 332 *current_down_event_, ev, |
| 332 (maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_ | 333 (maximum_pointer_count_ > 1 && secondary_pointer_down_event_) |
| 333 : ev), | 334 ? *secondary_pointer_down_event_ |
| 335 : ev, |
| 334 scroll_x, scroll_y); | 336 scroll_x, scroll_y); |
| 335 last_focus_x_ = focus_x; | 337 last_focus_x_ = focus_x; |
| 336 last_focus_y_ = focus_y; | 338 last_focus_y_ = focus_y; |
| 337 } | 339 } |
| 338 | 340 |
| 339 if (!two_finger_tap_allowed_for_gesture_) | 341 if (!two_finger_tap_allowed_for_gesture_) |
| 340 break; | 342 break; |
| 341 | 343 |
| 342 // Two-finger tap should be prevented if either pointer exceeds its | 344 // Two-finger tap should be prevented if either pointer exceeds its |
| 343 // (independent) slop region. | 345 // (independent) slop region. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) { | 548 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) { |
| 547 // If there have been more than two down pointers in the touch sequence, | 549 // If there have been more than two down pointers in the touch sequence, |
| 548 // tapping is not possible. Slop region check is not needed. | 550 // tapping is not possible. Slop region check is not needed. |
| 549 if (maximum_pointer_count_ > 2) | 551 if (maximum_pointer_count_ > 2) |
| 550 return false; | 552 return false; |
| 551 | 553 |
| 552 for (size_t i = 0; i < ev.GetPointerCount(); i++) { | 554 for (size_t i = 0; i < ev.GetPointerCount(); i++) { |
| 553 const int pointer_id = ev.GetPointerId(i); | 555 const int pointer_id = ev.GetPointerId(i); |
| 554 const MotionEvent* source_pointer_down_event = GetSourcePointerDownEvent( | 556 const MotionEvent* source_pointer_down_event = GetSourcePointerDownEvent( |
| 555 *current_down_event_, | 557 *current_down_event_, |
| 556 maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_ | 558 (maximum_pointer_count_ > 1 && secondary_pointer_down_event_) |
| 557 : *current_down_event_, | 559 ? *secondary_pointer_down_event_ |
| 560 : *current_down_event_, |
| 558 pointer_id); | 561 pointer_id); |
| 559 DCHECK(source_pointer_down_event); | 562 DCHECK(source_pointer_down_event); |
| 560 if (!source_pointer_down_event) | 563 if (!source_pointer_down_event) |
| 561 return false; | 564 return false; |
| 562 | 565 |
| 563 int source_index = | 566 int source_index = |
| 564 source_pointer_down_event->FindPointerIndexOfId(pointer_id); | 567 source_pointer_down_event->FindPointerIndexOfId(pointer_id); |
| 565 DCHECK_GE(source_index, 0); | 568 DCHECK_GE(source_index, 0); |
| 566 if (source_index < 0) | 569 if (source_index < 0) |
| 567 return false; | 570 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 585 for (size_t i = 0; i < secondary_pointer_down_event.GetPointerCount(); i++) { | 588 for (size_t i = 0; i < secondary_pointer_down_event.GetPointerCount(); i++) { |
| 586 if (secondary_pointer_down_event.GetPointerId(i) == pointer_id) | 589 if (secondary_pointer_down_event.GetPointerId(i) == pointer_id) |
| 587 return &secondary_pointer_down_event; | 590 return &secondary_pointer_down_event; |
| 588 } | 591 } |
| 589 | 592 |
| 590 NOTREACHED(); | 593 NOTREACHED(); |
| 591 return nullptr; | 594 return nullptr; |
| 592 } | 595 } |
| 593 | 596 |
| 594 } // namespace ui | 597 } // namespace ui |
| OLD | NEW |