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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 e2.GetId(), | 349 e2.GetId(), |
350 e2.GetEventTime(), | 350 e2.GetEventTime(), |
351 e1.GetX(), | 351 e1.GetX(), |
352 e1.GetY(), | 352 e1.GetY(), |
353 e2.GetPointerCount(), | 353 e2.GetPointerCount(), |
354 GetBoundingBox(e2), | 354 GetBoundingBox(e2), |
355 scroll_details)); | 355 scroll_details)); |
356 } | 356 } |
357 | 357 |
358 if (distance_x || distance_y) { | 358 if (distance_x || distance_y) { |
| 359 const gfx::RectF bounding_box = GetBoundingBox(e2); |
359 GestureEventDetails scroll_details( | 360 GestureEventDetails scroll_details( |
360 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); | 361 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); |
361 provider_->Send( | 362 provider_->Send(CreateGesture(ET_GESTURE_SCROLL_UPDATE, |
362 CreateGesture(ET_GESTURE_SCROLL_UPDATE, e2, scroll_details)); | 363 e2.GetId(), |
| 364 e2.GetEventTime(), |
| 365 bounding_box.CenterPoint().x(), |
| 366 bounding_box.CenterPoint().y(), |
| 367 e2.GetPointerCount(), |
| 368 bounding_box, |
| 369 scroll_details)); |
363 } | 370 } |
364 | 371 |
365 return true; | 372 return true; |
366 } | 373 } |
367 | 374 |
368 virtual bool OnFling(const MotionEvent& e1, | 375 virtual bool OnFling(const MotionEvent& e1, |
369 const MotionEvent& e2, | 376 const MotionEvent& e2, |
370 float velocity_x, | 377 float velocity_x, |
371 float velocity_y) OVERRIDE { | 378 float velocity_y) OVERRIDE { |
372 if (snap_scroll_controller_.IsSnappingScrolls()) { | 379 if (snap_scroll_controller_.IsSnappingScrolls()) { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 switch (event.GetAction()) { | 739 switch (event.GetAction()) { |
733 case MotionEvent::ACTION_DOWN: | 740 case MotionEvent::ACTION_DOWN: |
734 current_down_event_ = event.Clone(); | 741 current_down_event_ = event.Clone(); |
735 touch_scroll_in_progress_ = false; | 742 touch_scroll_in_progress_ = false; |
736 pinch_in_progress_ = false; | 743 pinch_in_progress_ = false; |
737 current_longpress_time_ = base::TimeTicks(); | 744 current_longpress_time_ = base::TimeTicks(); |
738 if (gesture_begin_end_types_enabled_) | 745 if (gesture_begin_end_types_enabled_) |
739 Send(CreateGesture(ET_GESTURE_BEGIN, event)); | 746 Send(CreateGesture(ET_GESTURE_BEGIN, event)); |
740 break; | 747 break; |
741 case MotionEvent::ACTION_POINTER_DOWN: | 748 case MotionEvent::ACTION_POINTER_DOWN: |
742 if (gesture_begin_end_types_enabled_) | 749 if (gesture_begin_end_types_enabled_) { |
743 Send(CreateGesture(ET_GESTURE_BEGIN, event)); | 750 Send(CreateGesture(ET_GESTURE_BEGIN, |
| 751 event.GetId(), |
| 752 event.GetEventTime(), |
| 753 event.GetX(event.GetActionIndex()), |
| 754 event.GetY(event.GetActionIndex()), |
| 755 event.GetPointerCount(), |
| 756 GetBoundingBox(event))); |
| 757 } |
744 break; | 758 break; |
745 case MotionEvent::ACTION_POINTER_UP: | 759 case MotionEvent::ACTION_POINTER_UP: |
746 case MotionEvent::ACTION_UP: | 760 case MotionEvent::ACTION_UP: |
747 case MotionEvent::ACTION_CANCEL: | 761 case MotionEvent::ACTION_CANCEL: |
748 case MotionEvent::ACTION_MOVE: | 762 case MotionEvent::ACTION_MOVE: |
749 break; | 763 break; |
750 } | 764 } |
751 } | 765 } |
752 | 766 |
753 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { | 767 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { |
754 switch (event.GetAction()) { | 768 switch (event.GetAction()) { |
755 case MotionEvent::ACTION_UP: | 769 case MotionEvent::ACTION_UP: |
756 case MotionEvent::ACTION_CANCEL: | 770 case MotionEvent::ACTION_CANCEL: { |
757 // Note: This call will have no effect if a fling was just generated, as | 771 // Note: This call will have no effect if a fling was just generated, as |
758 // |Fling()| will have already signalled an end to touch-scrolling. | 772 // |Fling()| will have already signalled an end to touch-scrolling. |
759 EndTouchScrollIfNecessary(event, true); | 773 EndTouchScrollIfNecessary(event, true); |
760 | 774 |
761 if (gesture_begin_end_types_enabled_) | 775 const gfx::RectF bounding_box = GetBoundingBox(event); |
762 Send(CreateGesture(ET_GESTURE_END, event)); | 776 |
| 777 if (gesture_begin_end_types_enabled_) { |
| 778 for (size_t i = 0; i < event.GetPointerCount(); ++i) { |
| 779 Send(CreateGesture(ET_GESTURE_END, |
| 780 event.GetId(), |
| 781 event.GetEventTime(), |
| 782 event.GetX(i), |
| 783 event.GetY(i), |
| 784 event.GetPointerCount() - i, |
| 785 bounding_box)); |
| 786 } |
| 787 } |
763 | 788 |
764 current_down_event_.reset(); | 789 current_down_event_.reset(); |
765 | 790 |
766 UpdateDoubleTapDetectionSupport(); | 791 UpdateDoubleTapDetectionSupport(); |
767 break; | 792 break; |
| 793 } |
768 case MotionEvent::ACTION_POINTER_UP: | 794 case MotionEvent::ACTION_POINTER_UP: |
769 if (gesture_begin_end_types_enabled_) | 795 if (gesture_begin_end_types_enabled_) |
770 Send(CreateGesture(ET_GESTURE_END, event)); | 796 Send(CreateGesture(ET_GESTURE_END, event)); |
771 break; | 797 break; |
772 case MotionEvent::ACTION_DOWN: | 798 case MotionEvent::ACTION_DOWN: |
773 case MotionEvent::ACTION_POINTER_DOWN: | 799 case MotionEvent::ACTION_POINTER_DOWN: |
774 case MotionEvent::ACTION_MOVE: | 800 case MotionEvent::ACTION_MOVE: |
775 break; | 801 break; |
776 } | 802 } |
777 } | 803 } |
778 | 804 |
779 void GestureProvider::UpdateDoubleTapDetectionSupport() { | 805 void GestureProvider::UpdateDoubleTapDetectionSupport() { |
780 // The GestureDetector requires that any provided DoubleTapListener remain | 806 // The GestureDetector requires that any provided DoubleTapListener remain |
781 // attached to it for the duration of a touch sequence. Defer any potential | 807 // attached to it for the duration of a touch sequence. Defer any potential |
782 // null'ing of the listener until the sequence has ended. | 808 // null'ing of the listener until the sequence has ended. |
783 if (current_down_event_) | 809 if (current_down_event_) |
784 return; | 810 return; |
785 | 811 |
786 const bool double_tap_enabled = double_tap_support_for_page_ && | 812 const bool double_tap_enabled = double_tap_support_for_page_ && |
787 double_tap_support_for_platform_; | 813 double_tap_support_for_platform_; |
788 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 814 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
789 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 815 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
790 } | 816 } |
791 | 817 |
792 } // namespace ui | 818 } // namespace ui |
OLD | NEW |