OLD | NEW |
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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 config.disable_click_delay, | 632 config.disable_click_delay, |
633 this)); | 633 this)); |
634 | 634 |
635 scale_gesture_listener_.reset( | 635 scale_gesture_listener_.reset( |
636 new ScaleGestureListenerImpl(config.scale_gesture_detector_config, this)); | 636 new ScaleGestureListenerImpl(config.scale_gesture_detector_config, this)); |
637 | 637 |
638 UpdateDoubleTapDetectionSupport(); | 638 UpdateDoubleTapDetectionSupport(); |
639 } | 639 } |
640 | 640 |
641 bool GestureProvider::CanHandle(const MotionEvent& event) const { | 641 bool GestureProvider::CanHandle(const MotionEvent& event) const { |
642 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; | 642 // Aura requires one cancel event per touch point, whereas Android requires |
| 643 // one cancel event per touch sequence. Thus we need to allow extra cancel |
| 644 // events. |
| 645 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_ || |
| 646 event.GetAction() == MotionEvent::ACTION_CANCEL; |
643 } | 647 } |
644 | 648 |
645 void GestureProvider::Fling(const MotionEvent& event, | 649 void GestureProvider::Fling(const MotionEvent& event, |
646 float velocity_x, | 650 float velocity_x, |
647 float velocity_y) { | 651 float velocity_y) { |
648 if (!velocity_x && !velocity_y) { | 652 if (!velocity_x && !velocity_y) { |
649 EndTouchScrollIfNecessary(event, true); | 653 EndTouchScrollIfNecessary(event, true); |
650 return; | 654 return; |
651 } | 655 } |
652 | 656 |
(...skipping 12 matching lines...) Expand all Loading... |
665 ET_SCROLL_FLING_START, velocity_x, velocity_y); | 669 ET_SCROLL_FLING_START, velocity_x, velocity_y); |
666 Send(CreateGesture(fling_details, event)); | 670 Send(CreateGesture(fling_details, event)); |
667 } | 671 } |
668 | 672 |
669 void GestureProvider::Send(GestureEventData gesture) { | 673 void GestureProvider::Send(GestureEventData gesture) { |
670 DCHECK(!gesture.time.is_null()); | 674 DCHECK(!gesture.time.is_null()); |
671 // The only valid events that should be sent without an active touch sequence | 675 // 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 | 676 // are SHOW_PRESS and TAP, potentially triggered by the double-tap |
673 // delay timing out. | 677 // delay timing out. |
674 DCHECK(current_down_event_ || gesture.type() == ET_GESTURE_TAP || | 678 DCHECK(current_down_event_ || gesture.type() == ET_GESTURE_TAP || |
675 gesture.type() == ET_GESTURE_SHOW_PRESS); | 679 gesture.type() == ET_GESTURE_SHOW_PRESS || |
| 680 gesture.type() == ET_GESTURE_END); |
676 | 681 |
677 // TODO(jdduke): Provide a way of skipping this clamping for stylus and/or | 682 // TODO(jdduke): Provide a way of skipping this clamping for stylus and/or |
678 // mouse-based input, perhaps by exposing the source type on MotionEvent. | 683 // mouse-based input, perhaps by exposing the source type on MotionEvent. |
679 gesture.details.set_bounding_box( | 684 gesture.details.set_bounding_box( |
680 ClampBoundingBox(gesture.details.bounding_box_f(), | 685 ClampBoundingBox(gesture.details.bounding_box_f(), |
681 min_gesture_bounds_length_, | 686 min_gesture_bounds_length_, |
682 max_gesture_bounds_length_)); | 687 max_gesture_bounds_length_)); |
683 | 688 |
684 switch (gesture.type()) { | 689 switch (gesture.type()) { |
685 case ET_GESTURE_LONG_PRESS: | 690 case ET_GESTURE_LONG_PRESS: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 780 } |
776 | 781 |
777 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { | 782 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { |
778 switch (event.GetAction()) { | 783 switch (event.GetAction()) { |
779 case MotionEvent::ACTION_UP: | 784 case MotionEvent::ACTION_UP: |
780 case MotionEvent::ACTION_CANCEL: { | 785 case MotionEvent::ACTION_CANCEL: { |
781 // Note: This call will have no effect if a fling was just generated, as | 786 // Note: This call will have no effect if a fling was just generated, as |
782 // |Fling()| will have already signalled an end to touch-scrolling. | 787 // |Fling()| will have already signalled an end to touch-scrolling. |
783 EndTouchScrollIfNecessary(event, true); | 788 EndTouchScrollIfNecessary(event, true); |
784 | 789 |
785 const gfx::RectF bounding_box = GetBoundingBox(event); | 790 if (gesture_begin_end_types_enabled_) |
786 | 791 Send(CreateGesture(ET_GESTURE_END, event)); |
787 if (gesture_begin_end_types_enabled_) { | |
788 for (size_t i = 0; i < event.GetPointerCount(); ++i) { | |
789 Send(CreateGesture(ET_GESTURE_END, | |
790 event.GetId(), | |
791 event.GetEventTime(), | |
792 event.GetX(i), | |
793 event.GetY(i), | |
794 event.GetRawX(i), | |
795 event.GetRawY(i), | |
796 event.GetPointerCount() - i, | |
797 bounding_box)); | |
798 } | |
799 } | |
800 | 792 |
801 current_down_event_.reset(); | 793 current_down_event_.reset(); |
802 | 794 |
803 UpdateDoubleTapDetectionSupport(); | 795 UpdateDoubleTapDetectionSupport(); |
804 break; | 796 break; |
805 } | 797 } |
806 case MotionEvent::ACTION_POINTER_UP: | 798 case MotionEvent::ACTION_POINTER_UP: |
807 if (gesture_begin_end_types_enabled_) | 799 if (gesture_begin_end_types_enabled_) |
808 Send(CreateGesture(ET_GESTURE_END, event)); | 800 Send(CreateGesture(ET_GESTURE_END, event)); |
809 break; | 801 break; |
(...skipping 11 matching lines...) Expand all Loading... |
821 if (current_down_event_) | 813 if (current_down_event_) |
822 return; | 814 return; |
823 | 815 |
824 const bool double_tap_enabled = double_tap_support_for_page_ && | 816 const bool double_tap_enabled = double_tap_support_for_page_ && |
825 double_tap_support_for_platform_; | 817 double_tap_support_for_platform_; |
826 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 818 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
827 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 819 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
828 } | 820 } |
829 | 821 |
830 } // namespace ui | 822 } // namespace ui |
OLD | NEW |