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

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: 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 GestureEventDetails tap_details(type, 1, 0); 69 GestureEventDetails tap_details(type, 1, 0);
70 tap_details.set_bounding_box( 70 tap_details.set_bounding_box(
71 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); 71 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor()));
72 return tap_details; 72 return tap_details;
73 } 73 }
74 74
75 } // namespace 75 } // namespace
76 76
77 // GestureProvider:::Config 77 // GestureProvider:::Config
78 78
79 GestureProvider::Config::Config() : disable_click_delay(false) {} 79 GestureProvider::Config::Config()
80 : disable_click_delay(false), send_aura_specific_gestures(false) {}
80 81
81 GestureProvider::Config::~Config() {} 82 GestureProvider::Config::~Config() {}
82 83
83 // GestureProvider::ScaleGestureListener 84 // GestureProvider::ScaleGestureListener
84 85
85 class GestureProvider::ScaleGestureListenerImpl 86 class GestureProvider::ScaleGestureListenerImpl
86 : public ScaleGestureDetector::ScaleGestureListener { 87 : public ScaleGestureDetector::ScaleGestureListener {
87 public: 88 public:
88 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, 89 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config,
89 GestureProvider* provider) 90 GestureProvider* provider)
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 }; 598 };
598 599
599 // GestureProvider 600 // GestureProvider
600 601
601 GestureProvider::GestureProvider(const Config& config, 602 GestureProvider::GestureProvider(const Config& config,
602 GestureProviderClient* client) 603 GestureProviderClient* client)
603 : client_(client), 604 : client_(client),
604 needs_show_press_event_(false), 605 needs_show_press_event_(false),
605 needs_tap_ending_event_(false), 606 needs_tap_ending_event_(false),
606 touch_scroll_in_progress_(false), 607 touch_scroll_in_progress_(false),
607 pinch_in_progress_(false) { 608 pinch_in_progress_(false),
609 send_aura_specific_gestures_(false) {
608 DCHECK(client); 610 DCHECK(client);
609 InitGestureDetectors(config); 611 InitGestureDetectors(config);
610 } 612 }
611 613
612 GestureProvider::~GestureProvider() {} 614 GestureProvider::~GestureProvider() {}
613 615
614 bool GestureProvider::OnTouchEvent(const MotionEvent& event) { 616 bool GestureProvider::OnTouchEvent(const MotionEvent& event) {
615 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent", 617 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent",
616 "action", GetMotionEventActionName(event.GetAction())); 618 "action", GetMotionEventActionName(event.GetAction()));
617 if (!CanHandle(event)) 619 if (!CanHandle(event))
618 return false; 620 return false;
619 621
622 if (send_aura_specific_gestures_)
623 SendGestureBeginOrEndIfNecessary(event);
jdduke (slow) 2014/04/03 20:17:16 But don't we want the GestureEnd to come after eve
tdresser 2014/04/03 21:14:41 Done.
624
620 const bool was_touch_scrolling_ = touch_scroll_in_progress_; 625 const bool was_touch_scrolling_ = touch_scroll_in_progress_;
621 const bool in_scale_gesture = 626 const bool in_scale_gesture =
622 scale_gesture_listener_->IsScaleGestureDetectionInProgress(); 627 scale_gesture_listener_->IsScaleGestureDetectionInProgress();
623 628
624 if (event.GetAction() == MotionEvent::ACTION_DOWN) { 629 if (event.GetAction() == MotionEvent::ACTION_DOWN) {
625 current_down_event_ = event.Clone(); 630 current_down_event_ = event.Clone();
626 touch_scroll_in_progress_ = false; 631 touch_scroll_in_progress_ = false;
627 needs_show_press_event_ = true; 632 needs_show_press_event_ = true;
628 current_longpress_time_ = base::TimeTicks(); 633 current_longpress_time_ = base::TimeTicks();
629 SendTapCancelIfNecessary(event); 634 SendTapCancelIfNecessary(event);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 void GestureProvider::InitGestureDetectors(const Config& config) { 694 void GestureProvider::InitGestureDetectors(const Config& config) {
690 TRACE_EVENT0("input", "GestureProvider::InitGestureDetectors"); 695 TRACE_EVENT0("input", "GestureProvider::InitGestureDetectors");
691 gesture_listener_.reset( 696 gesture_listener_.reset(
692 new GestureListenerImpl(config.gesture_detector_config, 697 new GestureListenerImpl(config.gesture_detector_config,
693 config.snap_scroll_controller_config, 698 config.snap_scroll_controller_config,
694 config.disable_click_delay, 699 config.disable_click_delay,
695 this)); 700 this));
696 701
697 scale_gesture_listener_.reset( 702 scale_gesture_listener_.reset(
698 new ScaleGestureListenerImpl(config.scale_gesture_detector_config, this)); 703 new ScaleGestureListenerImpl(config.scale_gesture_detector_config, this));
704 send_aura_specific_gestures_ = config.send_aura_specific_gestures;
699 } 705 }
700 706
701 bool GestureProvider::CanHandle(const MotionEvent& event) const { 707 bool GestureProvider::CanHandle(const MotionEvent& event) const {
702 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; 708 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_;
703 } 709 }
704 710
705 void GestureProvider::Fling(base::TimeTicks time, 711 void GestureProvider::Fling(base::TimeTicks time,
706 float x, 712 float x,
707 float y, 713 float y,
708 float velocity_x, 714 float velocity_x,
(...skipping 18 matching lines...) Expand all
727 ET_SCROLL_FLING_START, velocity_x, velocity_y); 733 ET_SCROLL_FLING_START, velocity_x, velocity_y);
728 Send(CreateGesture(ET_SCROLL_FLING_START, time, x, y, fling_details)); 734 Send(CreateGesture(ET_SCROLL_FLING_START, time, x, y, fling_details));
729 } 735 }
730 736
731 void GestureProvider::Send(const GestureEventData& gesture) { 737 void GestureProvider::Send(const GestureEventData& gesture) {
732 DCHECK(!gesture.time.is_null()); 738 DCHECK(!gesture.time.is_null());
733 // The only valid events that should be sent without an active touch sequence 739 // The only valid events that should be sent without an active touch sequence
734 // are SHOW_PRESS and TAP, potentially triggered by the double-tap 740 // are SHOW_PRESS and TAP, potentially triggered by the double-tap
735 // delay timing out. 741 // delay timing out.
736 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || 742 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP ||
737 gesture.type == ET_GESTURE_SHOW_PRESS); 743 gesture.type == ET_GESTURE_SHOW_PRESS ||
744 gesture.type == ET_GESTURE_BEGIN);
738 745
739 switch (gesture.type) { 746 switch (gesture.type) {
740 case ET_GESTURE_TAP_DOWN: 747 case ET_GESTURE_TAP_DOWN:
741 needs_tap_ending_event_ = true; 748 needs_tap_ending_event_ = true;
742 break; 749 break;
743 case ET_GESTURE_TAP_UNCONFIRMED: 750 case ET_GESTURE_TAP_UNCONFIRMED:
744 needs_show_press_event_ = false; 751 needs_show_press_event_ = false;
745 break; 752 break;
746 case ET_GESTURE_TAP: 753 case ET_GESTURE_TAP:
747 if (needs_show_press_event_) 754 if (needs_show_press_event_)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 818
812 void GestureProvider::EndTouchScrollIfNecessary(base::TimeTicks time, 819 void GestureProvider::EndTouchScrollIfNecessary(base::TimeTicks time,
813 bool send_scroll_end_event) { 820 bool send_scroll_end_event) {
814 if (!touch_scroll_in_progress_) 821 if (!touch_scroll_in_progress_)
815 return; 822 return;
816 touch_scroll_in_progress_ = false; 823 touch_scroll_in_progress_ = false;
817 if (send_scroll_end_event) 824 if (send_scroll_end_event)
818 Send(CreateGesture(ET_GESTURE_SCROLL_END, time, 0, 0)); 825 Send(CreateGesture(ET_GESTURE_SCROLL_END, time, 0, 0));
819 } 826 }
820 827
828 void GestureProvider::SendGestureBeginOrEndIfNecessary(
829 const MotionEvent& event) {
830 switch(event.GetAction()) {
jdduke (slow) 2014/04/03 20:17:16 Might as well move the check for the condition her
tdresser 2014/04/03 21:14:41 Done.
831 case MotionEvent::ACTION_DOWN:
832 case MotionEvent::ACTION_POINTER_DOWN:
833 Send(CreateGesture(ET_GESTURE_BEGIN, event));
834 break;
835 case MotionEvent::ACTION_UP:
836 case MotionEvent::ACTION_POINTER_UP:
837 case MotionEvent::ACTION_CANCEL:
838 Send(CreateGesture(ET_GESTURE_END, event));
839 break;
840 case MotionEvent::ACTION_MOVE:
841 break;
842 }
843 }
844
821 } // namespace ui 845 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698