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. 4 5 #ifndef UI_BASE_GESTURES_GESTURE_RECOGNIZER_H_ 6 #define UI_BASE_GESTURES_GESTURE_RECOGNIZER_H_ 7 8 #include <vector> 9 10 #include "base/memory/scoped_vector.h" 11 #include "ui/base/events/event_constants.h" 12 #include "ui/base/gestures/gesture_types.h" 13 #include "ui/base/ui_export.h" 14 15 namespace ui { 16 // A GestureRecognizer is an abstract base class for conversion of touch events 17 // into gestures. 18 class UI_EXPORT GestureRecognizer { 19 public: 20 static GestureRecognizer* Create(GestureEventHelper* helper); 21 22 // List of GestureEvent*. 23 typedef ScopedVector<GestureEvent> Gestures; 24 25 virtual ~GestureRecognizer() {} 26 27 // Invoked for each touch event that could contribute to the current gesture. 28 // Returns list of zero or more GestureEvents identified after processing 29 // TouchEvent. 30 // Caller would be responsible for freeing up Gestures. 31 virtual Gestures* ProcessTouchEventForGesture(const TouchEvent& event, 32 ui::EventResult result, 33 GestureConsumer* consumer) = 0; 34 35 // This is called when the consumer is destroyed. So this should cleanup any 36 // internal state maintained for |consumer|. 37 virtual void CleanupStateForConsumer(GestureConsumer* consumer) = 0; 38 39 // Return the window which should handle this TouchEvent, in the case where 40 // the touch is already associated with a target. 41 // Otherwise, returns null. 42 virtual GestureConsumer* GetTouchLockedTarget(TouchEvent* event) = 0; 43 44 // Return the window which should handle this GestureEvent. 45 virtual GestureConsumer* GetTargetForGestureEvent(GestureEvent* event) = 0; 46 47 // If there is an active touch within 48 // GestureConfiguration::max_separation_for_gesture_touches_in_pixels, 49 // of |location|, returns the target of the nearest active touch. 50 virtual GestureConsumer* GetTargetForLocation(const gfx::Point& location) = 0; 51 52 // Makes |new_consumer| the target for events previously targeting 53 // |current_consumer|. All other targets are canceled. 54 // The caller is responsible for updating the state of the consumers to 55 // be aware of this transfer of control (there are no ENTERED/EXITED events). 56 // If |new_consumer| is NULL, all events are canceled. 57 // If |old_consumer| is NULL, all events not already targeting |new_consumer| 58 // are canceled. 59 virtual void TransferEventsTo(GestureConsumer* current_consumer, 60 GestureConsumer* new_consumer) = 0; 61 62 // If a gesture is underway for |consumer| |point| is set to the last touch 63 // point and true is returned. If no touch events have been processed for 64 // |consumer| false is returned and |point| is untouched. 65 virtual bool GetLastTouchPointForTarget(GestureConsumer* consumer, 66 gfx::Point* point) = 0; 67 }; 68 69 } // namespace ui 70 71 #endif // UI_BASE_GESTURES_GESTURE_RECOGNIZER_H_ 72