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

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

Issue 223673006: Support GestureBegin and GestureEnd in ui::GestureProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke nits. Created 6 years, 8 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 GestureEventDetails tap_details(type, 1, 0); 72 GestureEventDetails tap_details(type, 1, 0);
73 tap_details.set_bounding_box( 73 tap_details.set_bounding_box(
74 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); 74 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor()));
75 return tap_details; 75 return tap_details;
76 } 76 }
77 77
78 } // namespace 78 } // namespace
79 79
80 // GestureProvider:::Config 80 // GestureProvider:::Config
81 81
82 GestureProvider::Config::Config() : disable_click_delay(false) {} 82 GestureProvider::Config::Config()
83 : disable_click_delay(false), gesture_begin_end_types_enabled(false) {}
83 84
84 GestureProvider::Config::~Config() {} 85 GestureProvider::Config::~Config() {}
85 86
86 // GestureProvider::ScaleGestureListener 87 // GestureProvider::ScaleGestureListener
87 88
88 class GestureProvider::ScaleGestureListenerImpl 89 class GestureProvider::ScaleGestureListenerImpl
89 : public ScaleGestureDetector::ScaleGestureListener { 90 : public ScaleGestureDetector::ScaleGestureListener {
90 public: 91 public:
91 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, 92 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config,
92 float device_scale_factor, 93 float device_scale_factor,
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // GestureProvider 526 // GestureProvider
526 527
527 GestureProvider::GestureProvider(const Config& config, 528 GestureProvider::GestureProvider(const Config& config,
528 GestureProviderClient* client) 529 GestureProviderClient* client)
529 : client_(client), 530 : client_(client),
530 needs_show_press_event_(false), 531 needs_show_press_event_(false),
531 needs_tap_ending_event_(false), 532 needs_tap_ending_event_(false),
532 touch_scroll_in_progress_(false), 533 touch_scroll_in_progress_(false),
533 pinch_in_progress_(false), 534 pinch_in_progress_(false),
534 double_tap_support_for_page_(true), 535 double_tap_support_for_page_(true),
535 double_tap_support_for_platform_(true) { 536 double_tap_support_for_platform_(true),
537 gesture_begin_end_types_enabled_(config.gesture_begin_end_types_enabled) {
536 DCHECK(client); 538 DCHECK(client);
537 InitGestureDetectors(config); 539 InitGestureDetectors(config);
538 } 540 }
539 541
540 GestureProvider::~GestureProvider() {} 542 GestureProvider::~GestureProvider() {}
541 543
542 bool GestureProvider::OnTouchEvent(const MotionEvent& event) { 544 bool GestureProvider::OnTouchEvent(const MotionEvent& event) {
543 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent", 545 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent",
544 "action", GetMotionEventActionName(event.GetAction())); 546 "action", GetMotionEventActionName(event.GetAction()));
545 if (!CanHandle(event)) 547 if (!CanHandle(event))
546 return false; 548 return false;
547 549
548 const bool in_scale_gesture = 550 const bool in_scale_gesture =
549 scale_gesture_listener_->IsScaleGestureDetectionInProgress(); 551 scale_gesture_listener_->IsScaleGestureDetectionInProgress();
550 552
551 if (event.GetAction() == MotionEvent::ACTION_DOWN) { 553 OnTouchEventHandlingBegin(event);
552 current_down_event_ = event.Clone(); 554 gesture_listener_->OnTouchEvent(event, in_scale_gesture);
553 touch_scroll_in_progress_ = false; 555 scale_gesture_listener_->OnTouchEvent(event);
554 needs_show_press_event_ = true; 556 OnTouchEventHandlingEnd(event);
555 current_longpress_time_ = base::TimeTicks();
556 SendTapCancelIfNecessary(event);
557 }
558
559 bool handled = gesture_listener_->OnTouchEvent(event, in_scale_gesture);
560 handled |= scale_gesture_listener_->OnTouchEvent(event);
561
562 if (event.GetAction() == MotionEvent::ACTION_UP ||
563 event.GetAction() == MotionEvent::ACTION_CANCEL) {
564 // Note: This call will have no effect if a fling was just generated, as
565 // |Fling()| will have already signalled an end to touch-scrolling.
566 EndTouchScrollIfNecessary(event, true);
567
568 // We shouldn't necessarily cancel a tap on ACTION_UP, as the double-tap
569 // timeout may yet trigger a SINGLE_TAP.
570 if (event.GetAction() == MotionEvent::ACTION_CANCEL)
571 SendTapCancelIfNecessary(event);
572
573 UpdateDoubleTapDetectionSupport();
574
575 current_down_event_.reset();
576 }
577
578 return true; 557 return true;
579 } 558 }
580 559
581 void GestureProvider::ResetGestureDetectors() { 560 void GestureProvider::ResetGestureDetectors() {
582 if (!current_down_event_) 561 if (!current_down_event_)
583 return; 562 return;
584 scoped_ptr<MotionEvent> cancel_event = current_down_event_->Cancel(); 563 scoped_ptr<MotionEvent> cancel_event = current_down_event_->Cancel();
585 gesture_listener_->OnTouchEvent(*cancel_event, false); 564 gesture_listener_->OnTouchEvent(*cancel_event, false);
586 scale_gesture_listener_->OnTouchEvent(*cancel_event); 565 scale_gesture_listener_->OnTouchEvent(*cancel_event);
587 } 566 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 DCHECK(!gesture.time.is_null()); 649 DCHECK(!gesture.time.is_null());
671 // The only valid events that should be sent without an active touch sequence 650 // The only valid events that should be sent without an active touch sequence
672 // are SHOW_PRESS and TAP, potentially triggered by the double-tap 651 // are SHOW_PRESS and TAP, potentially triggered by the double-tap
673 // delay timing out. 652 // delay timing out.
674 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || 653 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP ||
675 gesture.type == ET_GESTURE_SHOW_PRESS); 654 gesture.type == ET_GESTURE_SHOW_PRESS);
676 655
677 switch (gesture.type) { 656 switch (gesture.type) {
678 case ET_GESTURE_TAP_DOWN: 657 case ET_GESTURE_TAP_DOWN:
679 needs_tap_ending_event_ = true; 658 needs_tap_ending_event_ = true;
659 needs_show_press_event_ = true;
680 break; 660 break;
681 case ET_GESTURE_TAP_UNCONFIRMED: 661 case ET_GESTURE_TAP_UNCONFIRMED:
682 needs_show_press_event_ = false; 662 needs_show_press_event_ = false;
683 break; 663 break;
684 case ET_GESTURE_TAP: 664 case ET_GESTURE_TAP:
685 if (needs_show_press_event_) 665 if (needs_show_press_event_)
686 Send(CreateGesture(ET_GESTURE_SHOW_PRESS, 666 Send(CreateGesture(ET_GESTURE_SHOW_PRESS,
687 gesture.motion_event_id, 667 gesture.motion_event_id,
688 gesture.time, 668 gesture.time,
689 gesture.x, 669 gesture.x,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 759
780 void GestureProvider::UpdateDoubleTapDetectionSupport() { 760 void GestureProvider::UpdateDoubleTapDetectionSupport() {
781 if (IsDoubleTapInProgress()) 761 if (IsDoubleTapInProgress())
782 return; 762 return;
783 763
784 const bool supports_double_tap = IsDoubleTapSupported(); 764 const bool supports_double_tap = IsDoubleTapSupported();
785 gesture_listener_->SetDoubleTapEnabled(supports_double_tap); 765 gesture_listener_->SetDoubleTapEnabled(supports_double_tap);
786 scale_gesture_listener_->SetDoubleTapEnabled(supports_double_tap); 766 scale_gesture_listener_->SetDoubleTapEnabled(supports_double_tap);
787 } 767 }
788 768
769 void GestureProvider::OnTouchEventHandlingBegin(const MotionEvent& event) {
770 switch (event.GetAction()) {
771 case MotionEvent::ACTION_DOWN:
772 current_down_event_ = event.Clone();
773 touch_scroll_in_progress_ = false;
774 needs_show_press_event_ = false;
775 current_longpress_time_ = base::TimeTicks();
776 SendTapCancelIfNecessary(event);
777 if (gesture_begin_end_types_enabled_)
778 Send(CreateGesture(ET_GESTURE_BEGIN, event));
779 break;
780 case MotionEvent::ACTION_POINTER_DOWN:
781 if (gesture_begin_end_types_enabled_)
782 Send(CreateGesture(ET_GESTURE_BEGIN, event));
783 break;
784 case MotionEvent::ACTION_POINTER_UP:
785 case MotionEvent::ACTION_UP:
786 case MotionEvent::ACTION_CANCEL:
787 case MotionEvent::ACTION_MOVE:
788 break;
789 }
790 }
791
792 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) {
793 switch (event.GetAction()) {
794 case MotionEvent::ACTION_UP:
795 case MotionEvent::ACTION_CANCEL:
796 // Note: This call will have no effect if a fling was just generated, as
797 // |Fling()| will have already signalled an end to touch-scrolling.
798 EndTouchScrollIfNecessary(event, true);
799
800 // We shouldn't necessarily cancel a tap on ACTION_UP, as the double-tap
801 // timeout may yet trigger a SINGLE_TAP.
802 if (event.GetAction() == MotionEvent::ACTION_CANCEL)
803 SendTapCancelIfNecessary(event);
804
805 UpdateDoubleTapDetectionSupport();
806
807 if (gesture_begin_end_types_enabled_)
808 Send(CreateGesture(ET_GESTURE_END, event));
809
810 current_down_event_.reset();
811 break;
812 case MotionEvent::ACTION_POINTER_UP:
813 if (gesture_begin_end_types_enabled_)
814 Send(CreateGesture(ET_GESTURE_END, event));
815 break;
816 case MotionEvent::ACTION_DOWN:
817 case MotionEvent::ACTION_POINTER_DOWN:
818 case MotionEvent::ACTION_MOVE:
819 break;
820 }
821 }
822
789 } // namespace ui 823 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.h ('k') | ui/events/gesture_detection/gesture_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698