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/gfx/geometry/point.h"
20 class GestureConsumer
;
22 class GestureEventHelper
;
25 // TODO(tdresser): Once the unified gesture recognition process sticks
26 // (crbug.com/332418), GestureRecognizerImpl can be cleaned up
28 class EVENTS_EXPORT GestureRecognizerImpl
: public GestureRecognizer
,
29 public GestureProviderAuraClient
{
31 typedef std::map
<int, GestureConsumer
*> TouchIdToConsumerMap
;
33 GestureRecognizerImpl();
34 ~GestureRecognizerImpl() override
;
36 std::vector
<GestureEventHelper
*>& helpers() { return helpers_
; }
38 // Overridden from GestureRecognizer
39 GestureConsumer
* GetTouchLockedTarget(const TouchEvent
& event
) override
;
40 GestureConsumer
* GetTargetForGestureEvent(const GestureEvent
& event
) override
;
41 GestureConsumer
* GetTargetForLocation(const gfx::PointF
& location
,
42 int source_device_id
) override
;
43 void CancelActiveTouchesExcept(GestureConsumer
* not_cancelled
) override
;
44 void TransferEventsTo(GestureConsumer
* current_consumer
,
45 GestureConsumer
* new_consumer
) override
;
46 bool GetLastTouchPointForTarget(GestureConsumer
* consumer
,
47 gfx::PointF
* point
) override
;
48 bool CancelActiveTouches(GestureConsumer
* consumer
) override
;
51 virtual GestureProviderAura
* GetGestureProviderForConsumer(
55 // Sets up the target consumer for gestures based on the touch-event.
56 void SetupTargets(const TouchEvent
& event
, GestureConsumer
* consumer
);
58 void DispatchGestureEvent(GestureEvent
* event
);
60 // Overridden from GestureRecognizer
61 bool ProcessTouchEventPreDispatch(TouchEvent
* event
,
62 GestureConsumer
* consumer
) override
;
64 Gestures
* AckTouchEvent(uint32 unique_event_id
,
65 ui::EventResult result
,
66 GestureConsumer
* consumer
) override
;
68 bool CleanupStateForConsumer(GestureConsumer
* consumer
) override
;
69 void AddGestureEventHelper(GestureEventHelper
* helper
) override
;
70 void RemoveGestureEventHelper(GestureEventHelper
* helper
) override
;
72 // Overridden from GestureProviderAuraClient
73 void OnGestureEvent(GestureEvent
* event
) override
;
75 // Convenience method to find the GestureEventHelper that can dispatch events
76 // to a specific |consumer|.
77 GestureEventHelper
* FindDispatchHelperForConsumer(GestureConsumer
* consumer
);
78 std::map
<GestureConsumer
*, GestureProviderAura
*> consumer_gesture_provider_
;
80 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id
81 // to its target window. touch-ids are removed from |touch_id_target_| on
82 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are
83 // removed in ConsumerDestroyed().
84 TouchIdToConsumerMap touch_id_target_
;
85 TouchIdToConsumerMap touch_id_target_for_gestures_
;
87 std::vector
<GestureEventHelper
*> helpers_
;
89 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl
);
92 // Provided only for testing:
93 EVENTS_EXPORT
void SetGestureRecognizerForTesting(
94 GestureRecognizer
* gesture_recognizer
);
98 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_