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
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_
6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_
10 #include "base/memory/scoped_vector.h"
11 #include "ui/events/event_constants.h"
12 #include "ui/events/events_export.h"
13 #include "ui/events/gestures/gesture_types.h"
16 // A GestureRecognizer is an abstract base class for conversion of touch events
18 class EVENTS_EXPORT GestureRecognizer {
20 static GestureRecognizer* Create();
21 static GestureRecognizer* Get();
23 // List of GestureEvent*.
24 typedef ScopedVector<GestureEvent> Gestures;
26 virtual ~GestureRecognizer() {}
28 // Invoked for each touch event that could contribute to the current gesture.
29 // Returns list of zero or more GestureEvents identified after processing
31 // Caller would be responsible for freeing up Gestures.
32 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event,
33 ui::EventResult result,
34 GestureConsumer* consumer) = 0;
36 // This is called when the consumer is destroyed. So this should cleanup any
37 // internal state maintained for |consumer|.
38 virtual void CleanupStateForConsumer(GestureConsumer* consumer) = 0;
40 // Return the window which should handle this TouchEvent, in the case where
41 // the touch is already associated with a target.
42 // Otherwise, returns null.
43 virtual GestureConsumer* GetTouchLockedTarget(TouchEvent* event) = 0;
45 // Return the window which should handle this GestureEvent.
46 virtual GestureConsumer* GetTargetForGestureEvent(GestureEvent* event) = 0;
48 // If there is an active touch within
49 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels,
50 // of |location|, returns the target of the nearest active touch.
51 virtual GestureConsumer* GetTargetForLocation(const gfx::Point& location) = 0;
53 // Makes |new_consumer| the target for events previously targeting
54 // |current_consumer|. All other targets are canceled.
55 // The caller is responsible for updating the state of the consumers to
56 // be aware of this transfer of control (there are no ENTERED/EXITED events).
57 // If |new_consumer| is NULL, all events are canceled.
58 // If |old_consumer| is NULL, all events not already targeting |new_consumer|
60 virtual void TransferEventsTo(GestureConsumer* current_consumer,
61 GestureConsumer* new_consumer) = 0;
63 // If a gesture is underway for |consumer| |point| is set to the last touch
64 // point and true is returned. If no touch events have been processed for
65 // |consumer| false is returned and |point| is untouched.
66 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer,
67 gfx::Point* point) = 0;
69 // Subscribes |helper| for dispatching async gestures such as long press.
70 // The Gesture Recognizer does NOT take ownership of |helper| and it is the
71 // responsibility of the |helper| to call |RemoveGestureEventHelper()| on
73 virtual void AddGestureEventHelper(GestureEventHelper* helper) = 0;
75 // Unsubscribes |helper| from async gesture dispatch.
76 // Since the GestureRecognizer does not own the |helper|, it is not deleted
77 // and must be cleaned up appropriately by the caller.
78 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) = 0;
83 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_