Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / gestures / gesture_recognizer.h
blobfd7e5448240a00903f544564a226116e70d79917
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 gesture packet in the queue which
37 // matches with unique_event_id.
38 virtual Gestures* AckTouchEvent(uint32 unique_event_id,
39 ui::EventResult result,
40 GestureConsumer* consumer) = 0;
42 // This is called when the consumer is destroyed. So this should cleanup any
43 // internal state maintained for |consumer|. Returns true iff there was
44 // state relating to |consumer| to clean up.
45 virtual bool CleanupStateForConsumer(GestureConsumer* consumer) = 0;
47 // Return the window which should handle this TouchEvent, in the case where
48 // the touch is already associated with a target.
49 // Otherwise, returns null.
50 virtual GestureConsumer* GetTouchLockedTarget(const TouchEvent& event) = 0;
52 // Return the window which should handle this GestureEvent.
53 virtual GestureConsumer* GetTargetForGestureEvent(
54 const GestureEvent& event) = 0;
56 // Returns the target of the nearest active touch with source device of
57 // |source_device_id|, within
58 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels of
59 // |location|, or NULL if no such point exists.
60 virtual GestureConsumer* GetTargetForLocation(
61 const gfx::PointF& location, int source_device_id) = 0;
63 // Cancels all touches except those targeted to |not_cancelled|. If
64 // |not_cancelled| == nullptr, cancels all touches.
65 virtual void CancelActiveTouchesExcept(GestureConsumer* not_cancelled) = 0;
67 // Makes |new_consumer| the target for events previously targeting
68 // |current_consumer|. Touches targeting all other targets are
69 // canceled. The caller is responsible for updating the state of the
70 // consumers to be aware of this transfer of control (there are no
71 // ENTERED/EXITED events).
72 virtual void TransferEventsTo(GestureConsumer* current_consumer,
73 GestureConsumer* new_consumer) = 0;
75 // If a gesture is underway for |consumer| |point| is set to the last touch
76 // point and true is returned. If no touch events have been processed for
77 // |consumer| false is returned and |point| is untouched.
78 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer,
79 gfx::PointF* point) = 0;
81 // Sends a touch cancel event for every active touch. Returns true iff any
82 // touch cancels were sent.
83 virtual bool CancelActiveTouches(GestureConsumer* consumer) = 0;
85 // Subscribes |helper| for dispatching async gestures such as long press.
86 // The Gesture Recognizer does NOT take ownership of |helper| and it is the
87 // responsibility of the |helper| to call |RemoveGestureEventHelper()| on
88 // destruction.
89 virtual void AddGestureEventHelper(GestureEventHelper* helper) = 0;
91 // Unsubscribes |helper| from async gesture dispatch.
92 // Since the GestureRecognizer does not own the |helper|, it is not deleted
93 // and must be cleaned up appropriately by the caller.
94 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) = 0;
97 } // namespace ui
99 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_H_