| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ | 5 #ifndef UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ |
| 6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ | 6 #define UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 14 #include "ui/events/events_export.h" | 14 #include "ui/events/events_export.h" |
| 15 #include "ui/events/gestures/gesture_provider_aura.h" | 15 #include "ui/events/gestures/gesture_provider_aura.h" |
| 16 #include "ui/events/gestures/gesture_recognizer.h" | 16 #include "ui/events/gestures/gesture_recognizer.h" |
| 17 #include "ui/events/gestures/gesture_sequence.h" | |
| 18 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
| 19 | 18 |
| 20 namespace ui { | 19 namespace ui { |
| 21 class GestureConsumer; | 20 class GestureConsumer; |
| 22 class GestureEvent; | 21 class GestureEvent; |
| 23 class GestureEventHelper; | 22 class GestureEventHelper; |
| 24 class GestureSequence; | |
| 25 class TouchEvent; | 23 class TouchEvent; |
| 26 | 24 |
| 27 // TODO(tdresser): Once the unified gesture recognition process sticks | 25 // TODO(tdresser): Once the unified gesture recognition process sticks |
| 28 // (crbug.com/332418), GestureRecognizerImpl can be cleaned up | 26 // (crbug.com/332418), GestureRecognizerImpl can be cleaned up |
| 29 // significantly. | 27 // significantly. |
| 30 class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer, | 28 class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer, |
| 31 public GestureSequenceDelegate, | |
| 32 public GestureProviderAuraClient { | 29 public GestureProviderAuraClient { |
| 33 public: | 30 public: |
| 34 typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap; | 31 typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap; |
| 35 | 32 |
| 36 GestureRecognizerImpl(); | 33 GestureRecognizerImpl(); |
| 37 virtual ~GestureRecognizerImpl(); | 34 virtual ~GestureRecognizerImpl(); |
| 38 | 35 |
| 39 std::vector<GestureEventHelper*>& helpers() { return helpers_; } | 36 std::vector<GestureEventHelper*>& helpers() { return helpers_; } |
| 40 | 37 |
| 41 // Overridden from GestureRecognizer | 38 // Overridden from GestureRecognizer |
| 42 virtual GestureConsumer* GetTouchLockedTarget( | 39 virtual GestureConsumer* GetTouchLockedTarget( |
| 43 const TouchEvent& event) OVERRIDE; | 40 const TouchEvent& event) OVERRIDE; |
| 44 virtual GestureConsumer* GetTargetForGestureEvent( | 41 virtual GestureConsumer* GetTargetForGestureEvent( |
| 45 const GestureEvent& event) OVERRIDE; | 42 const GestureEvent& event) OVERRIDE; |
| 46 virtual GestureConsumer* GetTargetForLocation( | 43 virtual GestureConsumer* GetTargetForLocation( |
| 47 const gfx::PointF& location, int source_device_id) OVERRIDE; | 44 const gfx::PointF& location, int source_device_id) OVERRIDE; |
| 48 virtual void TransferEventsTo(GestureConsumer* current_consumer, | 45 virtual void TransferEventsTo(GestureConsumer* current_consumer, |
| 49 GestureConsumer* new_consumer) OVERRIDE; | 46 GestureConsumer* new_consumer) OVERRIDE; |
| 50 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, | 47 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, |
| 51 gfx::PointF* point) OVERRIDE; | 48 gfx::PointF* point) OVERRIDE; |
| 52 virtual bool CancelActiveTouches(GestureConsumer* consumer) OVERRIDE; | 49 virtual bool CancelActiveTouches(GestureConsumer* consumer) OVERRIDE; |
| 53 | 50 |
| 54 protected: | 51 protected: |
| 55 virtual GestureSequence* GetGestureSequenceForConsumer(GestureConsumer* c); | |
| 56 virtual GestureProviderAura* GetGestureProviderForConsumer( | 52 virtual GestureProviderAura* GetGestureProviderForConsumer( |
| 57 GestureConsumer* c); | 53 GestureConsumer* c); |
| 58 virtual GestureSequence* CreateSequence( | |
| 59 ui::GestureSequenceDelegate* delegate); | |
| 60 | 54 |
| 61 private: | 55 private: |
| 62 // Sets up the target consumer for gestures based on the touch-event. | 56 // Sets up the target consumer for gestures based on the touch-event. |
| 63 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer); | 57 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer); |
| 64 void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches); | 58 void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches); |
| 65 | 59 |
| 66 void DispatchGestureEvent(GestureEvent* event); | 60 void DispatchGestureEvent(GestureEvent* event); |
| 67 | 61 |
| 68 // Overridden from GestureRecognizer | 62 // Overridden from GestureRecognizer |
| 69 virtual bool ProcessTouchEventPreDispatch(const TouchEvent& event, | 63 virtual bool ProcessTouchEventPreDispatch(const TouchEvent& event, |
| 70 GestureConsumer* consumer) OVERRIDE; | 64 GestureConsumer* consumer) OVERRIDE; |
| 71 | 65 |
| 72 virtual Gestures* ProcessTouchEventPostDispatch( | 66 virtual Gestures* ProcessTouchEventPostDispatch( |
| 73 const TouchEvent& event, | 67 const TouchEvent& event, |
| 74 ui::EventResult result, | 68 ui::EventResult result, |
| 75 GestureConsumer* consumer) OVERRIDE; | 69 GestureConsumer* consumer) OVERRIDE; |
| 76 | 70 |
| 77 virtual Gestures* ProcessTouchEventOnAsyncAck( | 71 virtual Gestures* ProcessTouchEventOnAsyncAck( |
| 78 const TouchEvent& event, | 72 const TouchEvent& event, |
| 79 ui::EventResult result, | 73 ui::EventResult result, |
| 80 GestureConsumer* consumer) OVERRIDE; | 74 GestureConsumer* consumer) OVERRIDE; |
| 81 | 75 |
| 82 virtual bool CleanupStateForConsumer(GestureConsumer* consumer) | 76 virtual bool CleanupStateForConsumer(GestureConsumer* consumer) |
| 83 OVERRIDE; | 77 OVERRIDE; |
| 84 virtual void AddGestureEventHelper(GestureEventHelper* helper) OVERRIDE; | 78 virtual void AddGestureEventHelper(GestureEventHelper* helper) OVERRIDE; |
| 85 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) OVERRIDE; | 79 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) OVERRIDE; |
| 86 | 80 |
| 87 // Overridden from ui::GestureSequenceDelegate. | |
| 88 virtual void DispatchPostponedGestureEvent(GestureEvent* event) OVERRIDE; | |
| 89 | |
| 90 // Overridden from GestureProviderAuraClient | 81 // Overridden from GestureProviderAuraClient |
| 91 virtual void OnGestureEvent(GestureEvent* event) OVERRIDE; | 82 virtual void OnGestureEvent(GestureEvent* event) OVERRIDE; |
| 92 | 83 |
| 93 // Convenience method to find the GestureEventHelper that can dispatch events | 84 // Convenience method to find the GestureEventHelper that can dispatch events |
| 94 // to a specific |consumer|. | 85 // to a specific |consumer|. |
| 95 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer); | 86 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer); |
| 96 | |
| 97 std::map<GestureConsumer*, GestureSequence*> consumer_sequence_; | |
| 98 std::map<GestureConsumer*, GestureProviderAura*> consumer_gesture_provider_; | 87 std::map<GestureConsumer*, GestureProviderAura*> consumer_gesture_provider_; |
| 99 | 88 |
| 100 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id | 89 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id |
| 101 // to its target window. touch-ids are removed from |touch_id_target_| on | 90 // to its target window. touch-ids are removed from |touch_id_target_| on |
| 102 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are | 91 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are |
| 103 // removed in ConsumerDestroyed(). | 92 // removed in ConsumerDestroyed(). |
| 104 TouchIdToConsumerMap touch_id_target_; | 93 TouchIdToConsumerMap touch_id_target_; |
| 105 TouchIdToConsumerMap touch_id_target_for_gestures_; | 94 TouchIdToConsumerMap touch_id_target_for_gestures_; |
| 106 | 95 |
| 107 std::vector<GestureEventHelper*> helpers_; | 96 std::vector<GestureEventHelper*> helpers_; |
| 108 | 97 |
| 109 bool use_unified_gesture_detector_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl); | 98 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl); |
| 112 }; | 99 }; |
| 113 | 100 |
| 114 // Provided only for testing: | 101 // Provided only for testing: |
| 115 EVENTS_EXPORT void SetGestureRecognizerForTesting( | 102 EVENTS_EXPORT void SetGestureRecognizerForTesting( |
| 116 GestureRecognizer* gesture_recognizer); | 103 GestureRecognizer* gesture_recognizer); |
| 117 | 104 |
| 118 } // namespace ui | 105 } // namespace ui |
| 119 | 106 |
| 120 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ | 107 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ |
| OLD | NEW |