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_
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/events/gestures/gesture_sequence.h"
18 #include "ui/gfx/point.h"
21 class GestureConsumer
;
23 class GestureEventHelper
;
24 class GestureSequence
;
27 // TODO(tdresser): Once the unified gesture recognition process sticks
28 // (crbug.com/332418), GestureRecognizerImpl can be cleaned up
30 class EVENTS_EXPORT GestureRecognizerImpl
: public GestureRecognizer
,
31 public GestureSequenceDelegate
,
32 public GestureProviderAuraClient
{
34 typedef std::map
<int, GestureConsumer
*> TouchIdToConsumerMap
;
36 GestureRecognizerImpl();
37 virtual ~GestureRecognizerImpl();
39 std::vector
<GestureEventHelper
*>& helpers() { return helpers_
; }
41 // Overridden from GestureRecognizer
42 virtual GestureConsumer
* GetTouchLockedTarget(
43 const TouchEvent
& event
) OVERRIDE
;
44 virtual GestureConsumer
* GetTargetForGestureEvent(
45 const GestureEvent
& event
) OVERRIDE
;
46 virtual GestureConsumer
* GetTargetForLocation(
47 const gfx::PointF
& location
, int source_device_id
) OVERRIDE
;
48 virtual void TransferEventsTo(GestureConsumer
* current_consumer
,
49 GestureConsumer
* new_consumer
) OVERRIDE
;
50 virtual bool GetLastTouchPointForTarget(GestureConsumer
* consumer
,
51 gfx::PointF
* point
) OVERRIDE
;
52 virtual bool CancelActiveTouches(GestureConsumer
* consumer
) OVERRIDE
;
55 virtual GestureSequence
* GetGestureSequenceForConsumer(GestureConsumer
* c
);
56 virtual GestureProviderAura
* GetGestureProviderForConsumer(
58 virtual GestureSequence
* CreateSequence(
59 ui::GestureSequenceDelegate
* delegate
);
62 // Sets up the target consumer for gestures based on the touch-event.
63 void SetupTargets(const TouchEvent
& event
, GestureConsumer
* consumer
);
64 void CancelTouches(std::vector
<std::pair
<int, GestureConsumer
*> >* touches
);
66 void DispatchGestureEvent(GestureEvent
* event
);
68 // Overridden from GestureRecognizer
69 virtual Gestures
* ProcessTouchEventForGesture(
70 const TouchEvent
& event
,
71 ui::EventResult result
,
72 GestureConsumer
* target
) OVERRIDE
;
73 virtual bool CleanupStateForConsumer(GestureConsumer
* consumer
)
75 virtual void AddGestureEventHelper(GestureEventHelper
* helper
) OVERRIDE
;
76 virtual void RemoveGestureEventHelper(GestureEventHelper
* helper
) OVERRIDE
;
78 // Overridden from ui::GestureSequenceDelegate.
79 virtual void DispatchPostponedGestureEvent(GestureEvent
* event
) 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
);
88 std::map
<GestureConsumer
*, GestureSequence
*> consumer_sequence_
;
89 std::map
<GestureConsumer
*, GestureProviderAura
*> consumer_gesture_provider_
;
91 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id
92 // to its target window. touch-ids are removed from |touch_id_target_| on
93 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are
94 // removed in ConsumerDestroyed().
95 TouchIdToConsumerMap touch_id_target_
;
96 TouchIdToConsumerMap touch_id_target_for_gestures_
;
98 std::vector
<GestureEventHelper
*> helpers_
;
100 bool use_unified_gesture_detector_
;
102 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl
);
105 // Provided only for testing:
106 EVENTS_EXPORT
void SetGestureRecognizerForTesting(
107 GestureRecognizer
* gesture_recognizer
);
111 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_