base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / gestures / gesture_recognizer.h
blob9ed07049f1477ff112a799f23e3b97acd8efdf48
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_
8 #include <vector>
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"
14 #include "ui/gfx/geometry/point_f.h"
16 namespace ui {
17 // A GestureRecognizer is an abstract base class for conversion of touch events
18 // into gestures.
19 class EVENTS_EXPORT GestureRecognizer {
20 public:
21 static GestureRecognizer* Create();
22 static GestureRecognizer* Get();
23 static void Reset();
25 // List of GestureEvent*.
26 typedef ScopedVector<GestureEvent> Gestures;
28 virtual ~GestureRecognizer() {}
30 // Invoked before event dispatch. If the event is invalid given the current
31 // touch sequence, returns false.
32 virtual bool ProcessTouchEventPreDispatch(TouchEvent* event,
33 GestureConsumer* consumer) = 0;
35 // Returns a list of zero or more GestureEvents. The caller is responsible for
36 // freeing the returned events. Acks the first gesture packet in the queue.
37 virtual Gestures* AckAsyncTouchEvent(
38 const TouchEvent& event,
39 ui::EventResult result,
40 GestureConsumer* consumer) = 0;
42 // Returns a list of zero or more GestureEvents. The caller is responsible for
43 // freeing the returned events. Acks the last gesture packet in the queue.
44 virtual Gestures* AckSyncTouchEvent(const uint64 unique_event_id,
45 ui::EventResult result,
46 GestureConsumer* consumer) = 0;
48 // This is called when the consumer is destroyed. So this should cleanup any
49 // internal state maintained for |consumer|. Returns true iff there was
50 // state relating to |consumer| to clean up.
51 virtual bool CleanupStateForConsumer(GestureConsumer* consumer) = 0;
53 // Return the window which should handle this TouchEvent, in the case where
54 // the touch is already associated with a target.
55 // Otherwise, returns null.
56 virtual GestureConsumer* GetTouchLockedTarget(const TouchEvent& event) = 0;
58 // Return the window which should handle this GestureEvent.
59 virtual GestureConsumer* GetTargetForGestureEvent(
60 const GestureEvent& event) = 0;
62 // Returns the target of the nearest active touch with source device of
63 // |source_device_id|, within
64 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels of
65 // |location|, or NULL if no such point exists.
66 virtual GestureConsumer* GetTargetForLocation(
67 const gfx::PointF& location, int source_device_id) = 0;
69 // Makes |new_consumer| the target for events previously targeting
70 // |current_consumer|. All other targets are canceled.
71 // The caller is responsible for updating the state of the consumers to
72 // be aware of this transfer of control (there are no ENTERED/EXITED events).
73 // If |new_consumer| is NULL, all events are canceled.
74 // If |old_consumer| is NULL, all events not already targeting |new_consumer|
75 // are canceled.
76 virtual void TransferEventsTo(GestureConsumer* current_consumer,
77 GestureConsumer* new_consumer) = 0;
79 // If a gesture is underway for |consumer| |point| is set to the last touch
80 // point and true is returned. If no touch events have been processed for
81 // |consumer| false is returned and |point| is untouched.
82 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer,
83 gfx::PointF* point) = 0;
85 // Sends a touch cancel event for every active touch. Returns true iff any
86 // touch cancels were sent.
87 virtual bool CancelActiveTouches(GestureConsumer* consumer) = 0;
89 // Subscribes |helper| for dispatching async gestures such as long press.
90 // The Gesture Recognizer does NOT take ownership of |helper| and it is the
91 // responsibility of the |helper| to call |RemoveGestureEventHelper()| on
92 // destruction.
93 virtual void AddGestureEventHelper(GestureEventHelper* helper) = 0;
95 // Unsubscribes |helper| from async gesture dispatch.
96 // Since the GestureRecognizer does not own the |helper|, it is not deleted
97 // and must be cleaned up appropriately by the caller.
98 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) = 0;
101 } // namespace ui
103 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_