Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gestures / gesture_recognizer_impl.h
blob46bf74910f0a4dfa0dd53754560641fff974ed70
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_IMPL_H_
6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_
8 #include <map>
9 #include <vector>
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/events/events_export.h"
15 #include "ui/events/gestures/gesture_provider_aura.h"
16 #include "ui/events/gestures/gesture_recognizer.h"
17 #include "ui/gfx/point.h"
19 namespace ui {
20 class GestureConsumer;
21 class GestureEvent;
22 class GestureEventHelper;
23 class TouchEvent;
25 // TODO(tdresser): Once the unified gesture recognition process sticks
26 // (crbug.com/332418), GestureRecognizerImpl can be cleaned up
27 // significantly.
28 class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer,
29 public GestureProviderAuraClient {
30 public:
31 typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap;
33 GestureRecognizerImpl();
34 virtual ~GestureRecognizerImpl();
36 std::vector<GestureEventHelper*>& helpers() { return helpers_; }
38 // Overridden from GestureRecognizer
39 virtual GestureConsumer* GetTouchLockedTarget(
40 const TouchEvent& event) OVERRIDE;
41 virtual GestureConsumer* GetTargetForGestureEvent(
42 const GestureEvent& event) OVERRIDE;
43 virtual GestureConsumer* GetTargetForLocation(
44 const gfx::PointF& location, int source_device_id) OVERRIDE;
45 virtual void TransferEventsTo(GestureConsumer* current_consumer,
46 GestureConsumer* new_consumer) OVERRIDE;
47 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer,
48 gfx::PointF* point) OVERRIDE;
49 virtual bool CancelActiveTouches(GestureConsumer* consumer) OVERRIDE;
51 protected:
52 virtual GestureProviderAura* GetGestureProviderForConsumer(
53 GestureConsumer* c);
55 private:
56 // Sets up the target consumer for gestures based on the touch-event.
57 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer);
58 void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches);
60 void DispatchGestureEvent(GestureEvent* event);
62 // Overridden from GestureRecognizer
63 virtual bool ProcessTouchEventPreDispatch(const TouchEvent& event,
64 GestureConsumer* consumer) OVERRIDE;
66 virtual Gestures* ProcessTouchEventPostDispatch(
67 const TouchEvent& event,
68 ui::EventResult result,
69 GestureConsumer* consumer) OVERRIDE;
71 virtual Gestures* ProcessTouchEventOnAsyncAck(
72 const TouchEvent& event,
73 ui::EventResult result,
74 GestureConsumer* consumer) OVERRIDE;
76 virtual bool CleanupStateForConsumer(GestureConsumer* consumer)
77 OVERRIDE;
78 virtual void AddGestureEventHelper(GestureEventHelper* helper) OVERRIDE;
79 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) OVERRIDE;
81 // Overridden from GestureProviderAuraClient
82 virtual void OnGestureEvent(GestureEvent* event) OVERRIDE;
84 // Convenience method to find the GestureEventHelper that can dispatch events
85 // to a specific |consumer|.
86 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer);
87 std::map<GestureConsumer*, GestureProviderAura*> consumer_gesture_provider_;
89 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id
90 // to its target window. touch-ids are removed from |touch_id_target_| on
91 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are
92 // removed in ConsumerDestroyed().
93 TouchIdToConsumerMap touch_id_target_;
94 TouchIdToConsumerMap touch_id_target_for_gestures_;
96 std::vector<GestureEventHelper*> helpers_;
98 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl);
101 // Provided only for testing:
102 EVENTS_EXPORT void SetGestureRecognizerForTesting(
103 GestureRecognizer* gesture_recognizer);
105 } // namespace ui
107 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_