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

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

Issue 289373009: Support tap_count in ui::GestureProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to GestureProviderAura. Created 6 years, 7 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 | Annotate | Revision Log
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 <cmath> 10 #include <cmath>
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 defer_confirm_single_tap_(false), 180 defer_confirm_single_tap_(false),
181 in_longpress_(false), 181 in_longpress_(false),
182 always_in_tap_region_(false), 182 always_in_tap_region_(false),
183 always_in_bigger_tap_region_(false), 183 always_in_bigger_tap_region_(false),
184 two_finger_tap_allowed_for_gesture_(false), 184 two_finger_tap_allowed_for_gesture_(false),
185 is_double_tapping_(false), 185 is_double_tapping_(false),
186 last_focus_x_(0), 186 last_focus_x_(0),
187 last_focus_y_(0), 187 last_focus_y_(0),
188 down_focus_x_(0), 188 down_focus_x_(0),
189 down_focus_y_(0), 189 down_focus_y_(0),
190 longpress_enabled_(true), 190 longpress_enabled_(true),
191 swipe_enabled_(false), 191 swipe_enabled_(false),
192 two_finger_tap_enabled_(false) { 192 two_finger_tap_enabled_(false) {
193 DCHECK(listener_); 193 DCHECK(listener_);
194 Init(config); 194 Init(config);
195 } 195 }
196 196
197 GestureDetector::~GestureDetector() {} 197 GestureDetector::~GestureDetector() {}
198 198
199 bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { 199 bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
200 const MotionEvent::Action action = ev.GetAction(); 200 const MotionEvent::Action action = ev.GetAction();
201 201
202 velocity_tracker_.AddMovement(ev); 202 velocity_tracker_.AddMovement(ev);
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 void GestureDetector::OnTapTimeout() { 512 void GestureDetector::OnTapTimeout() {
513 if (!double_tap_listener_) 513 if (!double_tap_listener_)
514 return; 514 return;
515 if (!still_down_) 515 if (!still_down_)
516 double_tap_listener_->OnSingleTapConfirmed(*current_down_event_); 516 double_tap_listener_->OnSingleTapConfirmed(*current_down_event_);
517 else 517 else
518 defer_confirm_single_tap_ = true; 518 defer_confirm_single_tap_ = true;
519 } 519 }
520 520
521 void GestureDetector::Cancel() { 521 void GestureDetector::Cancel() {
522 timeout_handler_->Stop(); 522 CancelTaps();
523 velocity_tracker_.Clear(); 523 velocity_tracker_.Clear();
524 is_double_tapping_ = false;
525 still_down_ = false; 524 still_down_ = false;
526 always_in_tap_region_ = false;
527 always_in_bigger_tap_region_ = false;
528 defer_confirm_single_tap_ = false;
529 in_longpress_ = false;
530 } 525 }
531 526
532 void GestureDetector::CancelTaps() { 527 void GestureDetector::CancelTaps() {
533 timeout_handler_->Stop(); 528 timeout_handler_->Stop();
534 is_double_tapping_ = false; 529 is_double_tapping_ = false;
535 always_in_tap_region_ = false; 530 always_in_tap_region_ = false;
536 always_in_bigger_tap_region_ = false; 531 always_in_bigger_tap_region_ = false;
537 defer_confirm_single_tap_ = false; 532 defer_confirm_single_tap_ = false;
538 in_longpress_ = false; 533 in_longpress_ = false;
539 } 534 }
540 535
541 bool GestureDetector::IsConsideredDoubleTap( 536 bool GestureDetector::IsConsideredDoubleTap(
542 const MotionEvent& first_down, 537 const MotionEvent& first_down,
543 const MotionEvent& first_up, 538 const MotionEvent& first_up,
544 const MotionEvent& second_down) const { 539 const MotionEvent& second_down) const {
545 if (!always_in_bigger_tap_region_) 540 if (!always_in_bigger_tap_region_)
546 return false; 541 return false;
547 542
548 if (second_down.GetEventTime() - first_up.GetEventTime() > 543 if (second_down.GetEventTime() - first_up.GetEventTime() >
549 double_tap_timeout_) 544 double_tap_timeout_)
550 return false; 545 return false;
551 546
552 const float delta_x = first_down.GetX() - second_down.GetX(); 547 const float delta_x = first_down.GetX() - second_down.GetX();
553 const float delta_y = first_down.GetY() - second_down.GetY(); 548 const float delta_y = first_down.GetY() - second_down.GetY();
554 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_); 549 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_);
555 } 550 }
556 551
557 } // namespace ui 552 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698