base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / gestures / gesture_recognizer_impl.h
blob45903ae5499a217d09ed6492ed132afa2b9502aa
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/geometry/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 ~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 TransferEventsTo(GestureConsumer* current_consumer,
44 GestureConsumer* new_consumer) override;
45 bool GetLastTouchPointForTarget(GestureConsumer* consumer,
46 gfx::PointF* point) override;
47 bool CancelActiveTouches(GestureConsumer* consumer) override;
49 protected:
50 virtual GestureProviderAura* GetGestureProviderForConsumer(
51 GestureConsumer* c);
53 private:
54 // Sets up the target consumer for gestures based on the touch-event.
55 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer);
57 void DispatchGestureEvent(GestureEvent* event);
59 // Overridden from GestureRecognizer
60 bool ProcessTouchEventPreDispatch(TouchEvent* event,
61 GestureConsumer* consumer) override;
63 Gestures* AckAsyncTouchEvent(const TouchEvent& event,
64 ui::EventResult result,
65 GestureConsumer* consumer) override;
67 Gestures* AckSyncTouchEvent(const uint64 unique_event_id,
68 ui::EventResult result,
69 GestureConsumer* consumer) override;
71 bool CleanupStateForConsumer(GestureConsumer* consumer) override;
72 void AddGestureEventHelper(GestureEventHelper* helper) override;
73 void RemoveGestureEventHelper(GestureEventHelper* helper) override;
75 // Overridden from GestureProviderAuraClient
76 void OnGestureEvent(GestureEvent* event) override;
78 // Convenience method to find the GestureEventHelper that can dispatch events
79 // to a specific |consumer|.
80 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer);
81 std::map<GestureConsumer*, GestureProviderAura*> consumer_gesture_provider_;
83 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id
84 // to its target window. touch-ids are removed from |touch_id_target_| on
85 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are
86 // removed in ConsumerDestroyed().
87 TouchIdToConsumerMap touch_id_target_;
88 TouchIdToConsumerMap touch_id_target_for_gestures_;
90 std::vector<GestureEventHelper*> helpers_;
92 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl);
95 // Provided only for testing:
96 EVENTS_EXPORT void SetGestureRecognizerForTesting(
97 GestureRecognizer* gesture_recognizer);
99 } // namespace ui
101 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_