Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: ui/events/gesture_detection/gesture_detector.cc

Issue 2175803002: The helper functions for slop region check and subtraction are modified. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 const float scroll_x = last_focus_x_ - focus_x; 299 const float scroll_x = last_focus_x_ - focus_x;
300 const float scroll_y = last_focus_y_ - focus_y; 300 const float scroll_y = last_focus_y_ - focus_y;
301 if (is_double_tapping_) { 301 if (is_double_tapping_) {
302 // Give the move events of the double-tap. 302 // Give the move events of the double-tap.
303 DCHECK(double_tap_listener_); 303 DCHECK(double_tap_listener_);
304 handled |= double_tap_listener_->OnDoubleTapEvent(ev); 304 handled |= double_tap_listener_->OnDoubleTapEvent(ev);
305 } else if (all_pointers_within_slop_regions_) { 305 } else if (all_pointers_within_slop_regions_) {
306 if (!IsWithinTouchSlop(ev)) { 306 if (!IsWithinTouchSlop(ev)) {
307 handled = listener_->OnScroll( 307 handled = listener_->OnScroll(
308 *current_down_event_, ev, 308 *current_down_event_, ev,
309 (ev.GetPointerCount() > 1 ? *secondary_pointer_down_event_ 309 (maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_
310 : ev), 310 : ev),
311 scroll_x, scroll_y); 311 scroll_x, scroll_y);
312 last_focus_x_ = focus_x; 312 last_focus_x_ = focus_x;
313 last_focus_y_ = focus_y; 313 last_focus_y_ = focus_y;
314 all_pointers_within_slop_regions_ = false; 314 all_pointers_within_slop_regions_ = false;
315 timeout_handler_->Stop(); 315 timeout_handler_->Stop();
316 } 316 }
317 317
318 const float delta_x = focus_x - down_focus_x_; 318 const float delta_x = focus_x - down_focus_x_;
319 const float delta_y = focus_y - down_focus_y_; 319 const float delta_y = focus_y - down_focus_y_;
320 const float distance_square = delta_x * delta_x + delta_y * delta_y; 320 const float distance_square = delta_x * delta_x + delta_y * delta_y;
321 if (distance_square > double_tap_touch_slop_square_) 321 if (distance_square > double_tap_touch_slop_square_)
322 always_in_bigger_tap_region_ = false; 322 always_in_bigger_tap_region_ = false;
323 } else if (std::abs(scroll_x) > kScrollEpsilon || 323 } else if (std::abs(scroll_x) > kScrollEpsilon ||
324 std::abs(scroll_y) > kScrollEpsilon) { 324 std::abs(scroll_y) > kScrollEpsilon) {
325 handled = listener_->OnScroll( 325 handled = listener_->OnScroll(
326 *current_down_event_, ev, 326 *current_down_event_, ev,
327 (ev.GetPointerCount() > 1 ? *secondary_pointer_down_event_ : ev), 327 (maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_
328 : ev),
328 scroll_x, scroll_y); 329 scroll_x, scroll_y);
329 last_focus_x_ = focus_x; 330 last_focus_x_ = focus_x;
330 last_focus_y_ = focus_y; 331 last_focus_y_ = focus_y;
331 } 332 }
332 333
333 if (!two_finger_tap_allowed_for_gesture_) 334 if (!two_finger_tap_allowed_for_gesture_)
334 break; 335 break;
335 336
336 // Two-finger tap should be prevented if either pointer exceeds its 337 // Two-finger tap should be prevented if either pointer exceeds its
337 // (independent) slop region. 338 // (independent) slop region.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return false; 532 return false;
532 533
533 if (vx_abs > vy_abs) 534 if (vx_abs > vy_abs)
534 vy = 0; 535 vy = 0;
535 else 536 else
536 vx = 0; 537 vx = 0;
537 return listener_->OnSwipe(*current_down_event_, up, vx, vy); 538 return listener_->OnSwipe(*current_down_event_, up, vx, vy);
538 } 539 }
539 540
540 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) { 541 bool GestureDetector::IsWithinTouchSlop(const MotionEvent& ev) {
541 // If there are more than two down pointers, tapping is not possible. 542 // If there have been more than two down pointers in the touch sequence,
542 // Slop region check is not needed. 543 // tapping is not possible. Slop region check is not needed.
543 if (ev.GetPointerCount() > 2) 544 if (maximum_pointer_count_ > 2)
544 return false; 545 return false;
545 546
546 const int id0 = current_down_event_->GetPointerId(0); 547 for (size_t i = 0; i < ev.GetPointerCount(); i++) {
547 const int ev_idx0 = ev.GetPointerId(0) == id0 ? 0 : 1; 548 const int pointer_id = ev.GetPointerId(i);
549 const MotionEvent* source_pointer_down_event = GetSourcePointerDownEvent(
550 *current_down_event_,
551 maximum_pointer_count_ > 1 ? *secondary_pointer_down_event_
552 : *current_down_event_,
553 pointer_id);
554 DCHECK(source_pointer_down_event);
555 if (!source_pointer_down_event)
556 return false;
548 557
549 // Check if the primary pointer exceeded the slop region. 558 int source_index =
550 float dx = current_down_event_->GetX() - ev.GetX(ev_idx0); 559 source_pointer_down_event->FindPointerIndexOfId(pointer_id);
551 float dy = current_down_event_->GetY() - ev.GetY(ev_idx0); 560 DCHECK_GE(source_index, 0);
552 if (dx * dx + dy * dy > touch_slop_square_) 561 if (source_index < 0)
553 return false; 562 return false;
554 563
555 if (ev.GetPointerCount() == 2) { 564 float dx = source_pointer_down_event->GetX(source_index) - ev.GetX(i);
556 // Check if the secondary pointer exceeded the slop region. 565 float dy = source_pointer_down_event->GetY(source_index) - ev.GetY(i);
557 const int ev_idx1 = ev_idx0 == 0 ? 1 : 0;
558 const int idx1 = secondary_pointer_down_event_->GetActionIndex();
559 dx = secondary_pointer_down_event_->GetX(idx1) - ev.GetX(ev_idx1);
560 dy = secondary_pointer_down_event_->GetY(idx1) - ev.GetY(ev_idx1);
561 if (dx * dx + dy * dy > touch_slop_square_) 566 if (dx * dx + dy * dy > touch_slop_square_)
562 return false; 567 return false;
563 } 568 }
564 569
565 return true; 570 return true;
566 } 571 }
567 572
573 const MotionEvent* GestureDetector::GetSourcePointerDownEvent(
574 const MotionEvent& current_down_event,
575 const MotionEvent& secondary_pointer_down_event,
576 const int pointer_id) {
577 if (current_down_event.GetPointerId(0) == pointer_id)
578 return &current_down_event;
579
580 for (size_t i = 0; i < secondary_pointer_down_event.GetPointerCount(); i++) {
581 if (secondary_pointer_down_event.GetPointerId(i) == pointer_id)
582 return &secondary_pointer_down_event;
583 }
584
585 NOTREACHED();
586 return nullptr;
587 }
588
568 } // namespace ui 589 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_detector.h ('k') | ui/events/gesture_detection/gesture_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698