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

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

Issue 289373009: Support tap_count in ui::GestureProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small cleanup. 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 #include "ui/events/gesture_detection/gesture_provider.h" 5 #include "ui/events/gesture_detection/gesture_provider.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return CreateGesture(type, 94 return CreateGesture(type,
95 event.GetId(), 95 event.GetId(),
96 event.GetEventTime(), 96 event.GetEventTime(),
97 event.GetX(), 97 event.GetX(),
98 event.GetY(), 98 event.GetY(),
99 event.GetPointerCount(), 99 event.GetPointerCount(),
100 GetBoundingBox(event)); 100 GetBoundingBox(event));
101 } 101 }
102 102
103 GestureEventDetails CreateTapGestureDetails(EventType type, 103 GestureEventDetails CreateTapGestureDetails(EventType type,
104 const MotionEvent& event) { 104 const MotionEvent& event,
105 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be 105 int tap_count) {
106 // consistent with double tap behavior on a mobile viewport. See 106 DCHECK(type != ET_GESTURE_DOUBLE_TAP || tap_count == 1);
107 // crbug.com/234986 for context. 107 DCHECK_GT(tap_count, 0);
108 GestureEventDetails tap_details(type, 1, 0); 108 DCHECK_LE(tap_count, 3);
109 GestureEventDetails tap_details(type, tap_count, 0);
109 return tap_details; 110 return tap_details;
110 } 111 }
111 112
112 } // namespace 113 } // namespace
113 114
114 // GestureProvider:::Config 115 // GestureProvider:::Config
115 116
116 GestureProvider::Config::Config() 117 GestureProvider::Config::Config()
117 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)), 118 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)),
118 disable_click_delay(false), 119 disable_click_delay(false),
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 two_finger_tap_details)); 400 two_finger_tap_details));
400 return true; 401 return true;
401 } 402 }
402 403
403 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { 404 virtual void OnShowPress(const MotionEvent& e) OVERRIDE {
404 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); 405 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0);
405 provider_->Send( 406 provider_->Send(
406 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); 407 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details));
407 } 408 }
408 409
409 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { 410 virtual bool OnSingleTapUp(const MotionEvent& e, int tap_count) OVERRIDE {
410 // This is a hack to address the issue where user hovers 411 // This is a hack to address the issue where user hovers
411 // over a link for longer than double_tap_timeout_, then 412 // over a link for longer than double_tap_timeout_, then
412 // OnSingleTapConfirmed() is not triggered. But we still 413 // OnSingleTapConfirmed() is not triggered. But we still
413 // want to trigger the tap event at UP. So we override 414 // want to trigger the tap event at UP. So we override
414 // OnSingleTapUp() in this case. This assumes singleTapUp 415 // OnSingleTapUp() in this case. This assumes singleTapUp
415 // gets always called before singleTapConfirmed. 416 // gets always called before singleTapConfirmed.
416 if (!ignore_single_tap_) { 417 if (!ignore_single_tap_) {
417 if (e.GetEventTime() - current_down_time_ > double_tap_timeout_) { 418 if (e.GetEventTime() - current_down_time_ > double_tap_timeout_) {
418 return OnSingleTapConfirmed(e); 419 return OnSingleTapConfirmed(e, tap_count);
419 } else if (!IsDoubleTapEnabled() || disable_click_delay_) { 420 } else if (!IsDoubleTapEnabled() || disable_click_delay_) {
420 // If double-tap has been disabled, there is no need to wait 421 // If double-tap has been disabled, there is no need to wait
421 // for the double-tap timeout. 422 // for the double-tap timeout.
422 return OnSingleTapConfirmed(e); 423 return OnSingleTapConfirmed(e, tap_count);
423 } else { 424 } else {
424 // Notify Blink about this tapUp event anyway, when none of the above 425 // Notify Blink about this tapUp event anyway, when none of the above
425 // conditions applied. 426 // conditions applied.
426 provider_->Send(CreateGesture( 427 provider_->Send(CreateGesture(
427 ET_GESTURE_TAP_UNCONFIRMED, 428 ET_GESTURE_TAP_UNCONFIRMED,
428 e, 429 e,
429 CreateTapGestureDetails(ET_GESTURE_TAP_UNCONFIRMED, e))); 430 CreateTapGestureDetails(ET_GESTURE_TAP_UNCONFIRMED, e, tap_count)));
430 } 431 }
431 } 432 }
432 433
433 return provider_->SendLongTapIfNecessary(e); 434 return provider_->SendLongTapIfNecessary(e);
434 } 435 }
435 436
436 // GestureDetector::DoubleTapListener implementation. 437 // GestureDetector::DoubleTapListener implementation.
437 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { 438 virtual bool OnSingleTapConfirmed(const MotionEvent& e,
439 int tap_count) OVERRIDE {
438 // Long taps in the edges of the screen have their events delayed by 440 // Long taps in the edges of the screen have their events delayed by
439 // ContentViewHolder for tab swipe operations. As a consequence of the delay 441 // ContentViewHolder for tab swipe operations. As a consequence of the delay
440 // this method might be called after receiving the up event. 442 // this method might be called after receiving the up event.
441 // These corner cases should be ignored. 443 // These corner cases should be ignored.
442 if (ignore_single_tap_) 444 if (ignore_single_tap_)
443 return true; 445 return true;
444 446
445 ignore_single_tap_ = true; 447 ignore_single_tap_ = true;
446 448
447 provider_->Send(CreateGesture( 449 provider_->Send(
448 ET_GESTURE_TAP, e, CreateTapGestureDetails(ET_GESTURE_TAP, e))); 450 CreateGesture(ET_GESTURE_TAP,
451 e,
452 CreateTapGestureDetails(ET_GESTURE_TAP, e, tap_count)));
449 return true; 453 return true;
450 } 454 }
451 455
452 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE { return false; } 456 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE { return false; }
453 457
454 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE { 458 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE {
455 switch (e.GetAction()) { 459 switch (e.GetAction()) {
456 case MotionEvent::ACTION_DOWN: 460 case MotionEvent::ACTION_DOWN:
457 gesture_detector_.set_longpress_enabled(false); 461 gesture_detector_.set_longpress_enabled(false);
458 break; 462 break;
459 463
460 case MotionEvent::ACTION_UP: 464 case MotionEvent::ACTION_UP:
461 if (!provider_->IsPinchInProgress() && 465 if (!provider_->IsPinchInProgress() &&
462 !provider_->IsScrollInProgress()) { 466 !provider_->IsScrollInProgress()) {
463 provider_->Send( 467 // Tap count is set to 1 for ET_GESTURE_DOUBLE_TAP, in order to be
464 CreateGesture(ET_GESTURE_DOUBLE_TAP, 468 // consistent with double tap behavior on a mobile viewport. See
465 e, 469 // crbug.com/234986 for context.
466 CreateTapGestureDetails(ET_GESTURE_DOUBLE_TAP, e))); 470 provider_->Send(CreateGesture(
471 ET_GESTURE_DOUBLE_TAP,
472 e,
473 CreateTapGestureDetails(ET_GESTURE_DOUBLE_TAP, e, 1)));
467 return true; 474 return true;
468 } 475 }
469 break; 476 break;
470 default: 477 default:
471 break; 478 break;
472 } 479 }
473 return false; 480 return false;
474 } 481 }
475 482
476 virtual bool OnLongPress(const MotionEvent& e) OVERRIDE { 483 virtual bool OnLongPress(const MotionEvent& e) OVERRIDE {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 if (current_down_event_) 782 if (current_down_event_)
776 return; 783 return;
777 784
778 const bool double_tap_enabled = double_tap_support_for_page_ && 785 const bool double_tap_enabled = double_tap_support_for_page_ &&
779 double_tap_support_for_platform_; 786 double_tap_support_for_platform_;
780 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 787 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
781 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 788 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
782 } 789 }
783 790
784 } // namespace ui 791 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698