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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
15 #include "ui/events/gesture_detection/gesture_event_data.h" | 15 #include "ui/events/gesture_detection/gesture_event_data.h" |
16 #include "ui/events/gesture_detection/gesture_listeners.h" | 16 #include "ui/events/gesture_detection/gesture_listeners.h" |
17 #include "ui/events/gesture_detection/motion_event.h" | 17 #include "ui/events/gesture_detection/motion_event.h" |
18 #include "ui/events/gesture_detection/motion_event_generic.h" | 18 #include "ui/events/gesture_detection/motion_event_generic.h" |
19 #include "ui/events/gesture_detection/scale_gesture_listeners.h" | 19 #include "ui/events/gesture_detection/scale_gesture_listeners.h" |
20 #include "ui/gfx/geometry/point_f.h" | 20 #include "ui/gfx/geometry/point_f.h" |
21 #include "ui/gfx/geometry/vector2d_f.h" | 21 #include "ui/gfx/geometry/vector2d_f.h" |
22 | 22 |
23 namespace ui { | 23 namespace ui { |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Double-tap drag zoom sensitivity (speed). | 26 // Double-tap drag zoom sensitivity (speed). |
27 const float kDoubleTapDragZoomSpeed = 0.005f; | 27 const float kDoubleTapDragZoomSpeed = 0.005f; |
28 | 28 |
29 const char* GetMotionEventActionName(MotionEvent::Action action) { | 29 const char* GetMotionEventActionName(MotionEvent::Action action) { |
30 | |
31 #define CASE_ACTION_TO_STRING(action) \ | |
aelias_OOO_until_Jul13
2016/11/09 02:43:14
I'm not a big fan of clever macro magic unless the
mustaq
2016/11/09 17:04:33
Done.
| |
32 case MotionEvent::action: \ | |
33 return #action; | |
34 | |
30 switch (action) { | 35 switch (action) { |
31 case MotionEvent::ACTION_NONE: | 36 CASE_ACTION_TO_STRING(ACTION_NONE); |
32 return "ACTION_NONE"; | 37 CASE_ACTION_TO_STRING(ACTION_POINTER_DOWN); |
33 case MotionEvent::ACTION_POINTER_DOWN: | 38 CASE_ACTION_TO_STRING(ACTION_POINTER_UP); |
34 return "ACTION_POINTER_DOWN"; | 39 CASE_ACTION_TO_STRING(ACTION_DOWN); |
35 case MotionEvent::ACTION_POINTER_UP: | 40 CASE_ACTION_TO_STRING(ACTION_UP); |
36 return "ACTION_POINTER_UP"; | 41 CASE_ACTION_TO_STRING(ACTION_CANCEL); |
37 case MotionEvent::ACTION_DOWN: | 42 CASE_ACTION_TO_STRING(ACTION_MOVE); |
38 return "ACTION_DOWN"; | 43 CASE_ACTION_TO_STRING(ACTION_HOVER_ENTER); |
39 case MotionEvent::ACTION_UP: | 44 CASE_ACTION_TO_STRING(ACTION_HOVER_EXIT); |
40 return "ACTION_UP"; | 45 CASE_ACTION_TO_STRING(ACTION_HOVER_MOVE); |
41 case MotionEvent::ACTION_CANCEL: | 46 CASE_ACTION_TO_STRING(ACTION_BUTTON_PRESS); |
42 return "ACTION_CANCEL"; | 47 CASE_ACTION_TO_STRING(ACTION_BUTTON_RELEASE); |
43 case MotionEvent::ACTION_MOVE: | |
44 return "ACTION_MOVE"; | |
45 } | 48 } |
46 return ""; | 49 return ""; |
50 | |
51 #undef CASE_ACTION_TO_STRING | |
47 } | 52 } |
48 | 53 |
49 gfx::RectF ClampBoundingBox(const gfx::RectF& bounds, | 54 gfx::RectF ClampBoundingBox(const gfx::RectF& bounds, |
50 float min_length, | 55 float min_length, |
51 float max_length) { | 56 float max_length) { |
52 float width = bounds.width(); | 57 float width = bounds.width(); |
53 float height = bounds.height(); | 58 float height = bounds.height(); |
54 if (min_length) { | 59 if (min_length) { |
55 width = std::max(min_length, width); | 60 width = std::max(min_length, width); |
56 height = std::max(min_length, height); | 61 height = std::max(min_length, height); |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
846 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN), | 851 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN), |
847 event.GetFlags())); | 852 event.GetFlags())); |
848 } | 853 } |
849 break; | 854 break; |
850 case MotionEvent::ACTION_POINTER_UP: | 855 case MotionEvent::ACTION_POINTER_UP: |
851 case MotionEvent::ACTION_UP: | 856 case MotionEvent::ACTION_UP: |
852 case MotionEvent::ACTION_CANCEL: | 857 case MotionEvent::ACTION_CANCEL: |
853 case MotionEvent::ACTION_MOVE: | 858 case MotionEvent::ACTION_MOVE: |
854 break; | 859 break; |
855 case MotionEvent::ACTION_NONE: | 860 case MotionEvent::ACTION_NONE: |
861 case MotionEvent::ACTION_HOVER_ENTER: | |
862 case MotionEvent::ACTION_HOVER_EXIT: | |
863 case MotionEvent::ACTION_HOVER_MOVE: | |
864 case MotionEvent::ACTION_BUTTON_PRESS: | |
865 case MotionEvent::ACTION_BUTTON_RELEASE: | |
856 NOTREACHED(); | 866 NOTREACHED(); |
857 break; | 867 break; |
858 } | 868 } |
859 } | 869 } |
860 | 870 |
861 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { | 871 void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) { |
862 switch (event.GetAction()) { | 872 switch (event.GetAction()) { |
863 case MotionEvent::ACTION_UP: | 873 case MotionEvent::ACTION_UP: |
864 case MotionEvent::ACTION_CANCEL: { | 874 case MotionEvent::ACTION_CANCEL: { |
865 if (gesture_begin_end_types_enabled_) | 875 if (gesture_begin_end_types_enabled_) |
866 gesture_listener_->Send( | 876 gesture_listener_->Send( |
867 gesture_listener_->CreateGesture(ET_GESTURE_END, event)); | 877 gesture_listener_->CreateGesture(ET_GESTURE_END, event)); |
868 | 878 |
869 current_down_event_.reset(); | 879 current_down_event_.reset(); |
870 | 880 |
871 UpdateDoubleTapDetectionSupport(); | 881 UpdateDoubleTapDetectionSupport(); |
872 break; | 882 break; |
873 } | 883 } |
874 case MotionEvent::ACTION_POINTER_UP: | 884 case MotionEvent::ACTION_POINTER_UP: |
875 if (gesture_begin_end_types_enabled_) | 885 if (gesture_begin_end_types_enabled_) |
876 gesture_listener_->Send( | 886 gesture_listener_->Send( |
877 gesture_listener_->CreateGesture(ET_GESTURE_END, event)); | 887 gesture_listener_->CreateGesture(ET_GESTURE_END, event)); |
878 break; | 888 break; |
879 case MotionEvent::ACTION_DOWN: | 889 case MotionEvent::ACTION_DOWN: |
880 case MotionEvent::ACTION_POINTER_DOWN: | 890 case MotionEvent::ACTION_POINTER_DOWN: |
881 case MotionEvent::ACTION_MOVE: | 891 case MotionEvent::ACTION_MOVE: |
882 break; | 892 break; |
883 case MotionEvent::ACTION_NONE: | 893 case MotionEvent::ACTION_NONE: |
894 case MotionEvent::ACTION_HOVER_ENTER: | |
895 case MotionEvent::ACTION_HOVER_EXIT: | |
896 case MotionEvent::ACTION_HOVER_MOVE: | |
897 case MotionEvent::ACTION_BUTTON_PRESS: | |
898 case MotionEvent::ACTION_BUTTON_RELEASE: | |
884 NOTREACHED(); | 899 NOTREACHED(); |
885 break; | 900 break; |
886 } | 901 } |
887 } | 902 } |
888 | 903 |
889 void GestureProvider::UpdateDoubleTapDetectionSupport() { | 904 void GestureProvider::UpdateDoubleTapDetectionSupport() { |
890 // The GestureDetector requires that any provided DoubleTapListener remain | 905 // The GestureDetector requires that any provided DoubleTapListener remain |
891 // attached to it for the duration of a touch sequence. Defer any potential | 906 // attached to it for the duration of a touch sequence. Defer any potential |
892 // null'ing of the listener until the sequence has ended. | 907 // null'ing of the listener until the sequence has ended. |
893 if (current_down_event_) | 908 if (current_down_event_) |
894 return; | 909 return; |
895 | 910 |
896 const bool double_tap_enabled = | 911 const bool double_tap_enabled = |
897 double_tap_support_for_page_ && double_tap_support_for_platform_; | 912 double_tap_support_for_page_ && double_tap_support_for_platform_; |
898 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 913 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
899 } | 914 } |
900 | 915 |
901 } // namespace ui | 916 } // namespace ui |
OLD | NEW |