OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ | 5 #ifndef UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ |
6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ | 6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
12 #include "ui/events/events_export.h" | 12 #include "ui/events/events_export.h" |
13 #include "ui/events/gestures/gesture_types.h" | 13 #include "ui/events/gestures/gesture_types.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 // A GestureRecognizer is an abstract base class for conversion of touch events | 16 // A GestureRecognizer is an abstract base class for conversion of touch events |
17 // into gestures. | 17 // into gestures. |
18 class EVENTS_EXPORT GestureRecognizer { | 18 class EVENTS_EXPORT GestureRecognizer { |
19 public: | 19 public: |
20 static GestureRecognizer* Create(); | 20 static GestureRecognizer* Create(); |
21 static GestureRecognizer* Get(); | 21 static GestureRecognizer* Get(); |
22 static void Reset(); | |
23 | 22 |
24 // List of GestureEvent*. | 23 // List of GestureEvent*. |
25 typedef ScopedVector<GestureEvent> Gestures; | 24 typedef ScopedVector<GestureEvent> Gestures; |
26 | 25 |
27 virtual ~GestureRecognizer() {} | 26 virtual ~GestureRecognizer() {} |
28 | 27 |
29 // Invoked for each touch event that could contribute to the current gesture. | 28 // Invoked for each touch event that could contribute to the current gesture. |
30 // Returns list of zero or more GestureEvents identified after processing | 29 // Returns list of zero or more GestureEvents identified after processing |
31 // TouchEvent. | 30 // TouchEvent. |
32 // Caller would be responsible for freeing up Gestures. | 31 // Caller would be responsible for freeing up Gestures. |
33 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event, | 32 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event, |
34 ui::EventResult result, | 33 ui::EventResult result, |
35 GestureConsumer* consumer) = 0; | 34 GestureConsumer* consumer) = 0; |
36 | 35 |
37 // This is called when the consumer is destroyed. So this should cleanup any | 36 // This is called when the consumer is destroyed. So this should cleanup any |
38 // internal state maintained for |consumer|. | 37 // internal state maintained for |consumer|. |
39 virtual void CleanupStateForConsumer(GestureConsumer* consumer) = 0; | 38 virtual void CleanupStateForConsumer(GestureConsumer* consumer) = 0; |
40 | 39 |
41 // Return the window which should handle this TouchEvent, in the case where | 40 // Return the window which should handle this TouchEvent, in the case where |
42 // the touch is already associated with a target. | 41 // the touch is already associated with a target. |
43 // Otherwise, returns null. | 42 // Otherwise, returns null. |
44 virtual GestureConsumer* GetTouchLockedTarget(const TouchEvent& event) = 0; | 43 virtual GestureConsumer* GetTouchLockedTarget(const TouchEvent& event) = 0; |
45 | 44 |
46 // Return the window which should handle this GestureEvent. | 45 // Return the window which should handle this GestureEvent. |
47 virtual GestureConsumer* GetTargetForGestureEvent( | 46 virtual GestureConsumer* GetTargetForGestureEvent( |
48 const GestureEvent& event) = 0; | 47 const GestureEvent& event) = 0; |
49 | 48 |
50 // Returns the target of the nearest active touch with source device of | 49 // If there is an active touch within |
51 // |source_device_id|, within | 50 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels, |
52 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels of | 51 // of |location|, returns the target of the nearest active touch. |
53 // |location|, or NULL if no such point exists. | 52 virtual GestureConsumer* GetTargetForLocation(const gfx::Point& location) = 0; |
54 virtual GestureConsumer* GetTargetForLocation( | |
55 const gfx::Point& location, int source_device_id) = 0; | |
56 | 53 |
57 // Makes |new_consumer| the target for events previously targeting | 54 // Makes |new_consumer| the target for events previously targeting |
58 // |current_consumer|. All other targets are canceled. | 55 // |current_consumer|. All other targets are canceled. |
59 // The caller is responsible for updating the state of the consumers to | 56 // The caller is responsible for updating the state of the consumers to |
60 // be aware of this transfer of control (there are no ENTERED/EXITED events). | 57 // be aware of this transfer of control (there are no ENTERED/EXITED events). |
61 // If |new_consumer| is NULL, all events are canceled. | 58 // If |new_consumer| is NULL, all events are canceled. |
62 // If |old_consumer| is NULL, all events not already targeting |new_consumer| | 59 // If |old_consumer| is NULL, all events not already targeting |new_consumer| |
63 // are canceled. | 60 // are canceled. |
64 virtual void TransferEventsTo(GestureConsumer* current_consumer, | 61 virtual void TransferEventsTo(GestureConsumer* current_consumer, |
65 GestureConsumer* new_consumer) = 0; | 62 GestureConsumer* new_consumer) = 0; |
(...skipping 15 matching lines...) Expand all Loading... |
81 | 78 |
82 // Unsubscribes |helper| from async gesture dispatch. | 79 // Unsubscribes |helper| from async gesture dispatch. |
83 // Since the GestureRecognizer does not own the |helper|, it is not deleted | 80 // Since the GestureRecognizer does not own the |helper|, it is not deleted |
84 // and must be cleaned up appropriately by the caller. | 81 // and must be cleaned up appropriately by the caller. |
85 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) = 0; | 82 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) = 0; |
86 }; | 83 }; |
87 | 84 |
88 } // namespace ui | 85 } // namespace ui |
89 | 86 |
90 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ | 87 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_ |
OLD | NEW |