| 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_recognizer.h" | 15 #include "ui/events/gestures/gesture_recognizer.h" |
| 16 #include "ui/events/gestures/gesture_sequence.h" | 16 #include "ui/events/gestures/gesture_sequence.h" |
| 17 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 class GestureConsumer; | 20 class GestureConsumer; |
| 21 class GestureEvent; | 21 class GestureEvent; |
| 22 class GestureEventHelper; | 22 class GestureEventHelper; |
| 23 class GestureSequence; | 23 class GestureSequence; |
| 24 class TouchEvent; | 24 class TouchEvent; |
| 25 | 25 |
| 26 class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer, | 26 class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer { |
| 27 public GestureSequenceDelegate { | |
| 28 public: | 27 public: |
| 29 typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap; | 28 typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap; |
| 30 | 29 |
| 31 GestureRecognizerImpl(); | 30 GestureRecognizerImpl(); |
| 32 virtual ~GestureRecognizerImpl(); | 31 virtual ~GestureRecognizerImpl(); |
| 33 | 32 |
| 34 std::vector<GestureEventHelper*>& helpers() { return helpers_; } | 33 std::vector<GestureEventHelper*>& helpers() { return helpers_; } |
| 35 | 34 |
| 36 // Overridden from GestureRecognizer | 35 // Overridden from GestureRecognizer |
| 37 virtual GestureConsumer* GetTouchLockedTarget( | 36 virtual GestureConsumer* GetTouchLockedTarget( |
| 38 const TouchEvent& event) OVERRIDE; | 37 const TouchEvent& event) OVERRIDE; |
| 39 virtual GestureConsumer* GetTargetForGestureEvent( | 38 virtual GestureConsumer* GetTargetForGestureEvent( |
| 40 const GestureEvent& event) OVERRIDE; | 39 const GestureEvent& event) OVERRIDE; |
| 41 virtual GestureConsumer* GetTargetForLocation( | 40 virtual GestureConsumer* GetTargetForLocation( |
| 42 const gfx::Point& location) OVERRIDE; | 41 const gfx::Point& location) OVERRIDE; |
| 43 virtual void TransferEventsTo(GestureConsumer* current_consumer, | 42 virtual void TransferEventsTo(GestureConsumer* current_consumer, |
| 44 GestureConsumer* new_consumer) OVERRIDE; | 43 GestureConsumer* new_consumer) OVERRIDE; |
| 45 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, | 44 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, |
| 46 gfx::Point* point) OVERRIDE; | 45 gfx::Point* point) OVERRIDE; |
| 47 virtual void CancelActiveTouches(GestureConsumer* consumer) OVERRIDE; | 46 virtual void CancelActiveTouches(GestureConsumer* consumer) OVERRIDE; |
| 48 | 47 |
| 49 protected: | 48 protected: |
| 50 virtual GestureSequence* CreateSequence(GestureSequenceDelegate* delegate); | 49 virtual GestureSequence* CreateSequence( |
| 51 virtual GestureSequence* GetGestureSequenceForConsumer(GestureConsumer* c); | 50 GestureEventQueueTimerInterface* geq_timers); |
| 51 virtual GestureSequence* GetGestureSequenceForConsumer( |
| 52 GestureConsumer* c, GestureEventQueueTimerInterface* geq_timers); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 // Sets up the target consumer for gestures based on the touch-event. | 55 // Sets up the target consumer for gestures based on the touch-event. |
| 55 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer); | 56 void SetupTargets(const TouchEvent& event, GestureConsumer* consumer); |
| 56 void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches); | 57 void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches); |
| 57 | 58 |
| 58 // Overridden from GestureRecognizer | 59 // Overridden from GestureRecognizer |
| 59 virtual Gestures* ProcessTouchEventForGesture( | 60 virtual Gestures* ProcessTouchEventForGesture( |
| 60 const TouchEvent& event, | 61 const TouchEvent& event, |
| 61 ui::EventResult result, | 62 GestureConsumer* target, |
| 62 GestureConsumer* target) OVERRIDE; | 63 GestureEventQueueTimerInterface* geq_timers) OVERRIDE; |
| 63 virtual void CleanupStateForConsumer(GestureConsumer* consumer) OVERRIDE; | 64 virtual void CleanupStateForConsumer(GestureConsumer* consumer) OVERRIDE; |
| 64 virtual void AddGestureEventHelper(GestureEventHelper* helper) OVERRIDE; | 65 virtual void AddGestureEventHelper(GestureEventHelper* helper) OVERRIDE; |
| 65 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) OVERRIDE; | 66 virtual void RemoveGestureEventHelper(GestureEventHelper* helper) OVERRIDE; |
| 66 | 67 |
| 67 // Overridden from ui::GestureSequenceDelegate. | |
| 68 virtual void DispatchPostponedGestureEvent(GestureEvent* event) OVERRIDE; | |
| 69 | |
| 70 // Convenience method to find the GestureEventHelper that can dispatch events | 68 // Convenience method to find the GestureEventHelper that can dispatch events |
| 71 // to a specific |consumer|. | 69 // to a specific |consumer|. |
| 72 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer); | 70 GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer); |
| 73 | 71 |
| 74 std::map<GestureConsumer*, GestureSequence*> consumer_sequence_; | 72 std::map<GestureConsumer*, GestureSequence*> consumer_sequence_; |
| 75 | 73 |
| 76 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id | 74 // Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id |
| 77 // to its target window. touch-ids are removed from |touch_id_target_| on | 75 // to its target window. touch-ids are removed from |touch_id_target_| on |
| 78 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are | 76 // ET_TOUCH_RELEASE and ET_TOUCH_CANCEL. |touch_id_target_for_gestures_| are |
| 79 // removed in ConsumerDestroyed(). | 77 // removed in ConsumerDestroyed(). |
| 80 TouchIdToConsumerMap touch_id_target_; | 78 TouchIdToConsumerMap touch_id_target_; |
| 81 TouchIdToConsumerMap touch_id_target_for_gestures_; | 79 TouchIdToConsumerMap touch_id_target_for_gestures_; |
| 82 | 80 |
| 83 std::vector<GestureEventHelper*> helpers_; | 81 std::vector<GestureEventHelper*> helpers_; |
| 84 | 82 |
| 85 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl); | 83 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 // Provided only for testing: | 86 // Provided only for testing: |
| 89 EVENTS_EXPORT void SetGestureRecognizerForTesting( | 87 EVENTS_EXPORT void SetGestureRecognizerForTesting( |
| 90 GestureRecognizer* gesture_recognizer); | 88 GestureRecognizer* gesture_recognizer); |
| 91 | 89 |
| 92 } // namespace ui | 90 } // namespace ui |
| 93 | 91 |
| 94 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ | 92 #endif // UI_EVENTS_GESTURES_GESTURE_RECOGNIZER_IMPL_H_ |
| OLD | NEW |