1 // Copyright 2014 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_EVENTS_GESTURE_DETECTION_GESTURE_LISTENERS_H_ 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_LISTENERS_H_ 7 8 #include "ui/events/gesture_detection/gesture_detection_export.h" 9 10 namespace ui { 11 12 class MotionEvent; 13 14 // Client through which |GestureDetector| signals gesture detection. 15 class GESTURE_DETECTION_EXPORT GestureListener { 16 public: ~GestureListener()17 virtual ~GestureListener() {} 18 virtual bool OnDown(const MotionEvent& e) = 0; 19 virtual void OnShowPress(const MotionEvent& e) = 0; 20 virtual bool OnSingleTapUp(const MotionEvent& e, int tap_count) = 0; 21 virtual void OnLongPress(const MotionEvent& e) = 0; 22 virtual bool OnScroll(const MotionEvent& e1, 23 const MotionEvent& e2, 24 const MotionEvent& secondary_pointer_down, 25 float distance_x, 26 float distance_y) = 0; 27 virtual bool OnFling(const MotionEvent& e1, 28 const MotionEvent& e2, 29 float velocity_x, 30 float velocity_y) = 0; 31 // Added for Chromium (Aura). 32 virtual bool OnSwipe(const MotionEvent& e1, 33 const MotionEvent& e2, 34 float velocity_x, 35 float velocity_y) = 0; 36 virtual bool OnTwoFingerTap(const MotionEvent& e1, const MotionEvent& e2) = 0; 37 virtual void OnTapCancel(const MotionEvent& e) = 0; 38 }; 39 40 // Client through which |GestureDetector| signals double-tap detection. 41 class GESTURE_DETECTION_EXPORT DoubleTapListener { 42 public: ~DoubleTapListener()43 virtual ~DoubleTapListener() {} 44 virtual bool OnSingleTapConfirmed(const MotionEvent& e) = 0; 45 virtual bool OnDoubleTap(const MotionEvent& e) = 0; 46 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0; 47 }; 48 49 // A convenience class to extend when you only want to listen for a subset 50 // of all the gestures. This implements all methods in the 51 // |GestureListener| and |DoubleTapListener| but does 52 // nothing and returns false for all applicable methods. 53 class GESTURE_DETECTION_EXPORT SimpleGestureListener 54 : public GestureListener, 55 public DoubleTapListener { 56 public: 57 // GestureListener implementation. 58 bool OnDown(const MotionEvent& e) override; 59 void OnShowPress(const MotionEvent& e) override; 60 bool OnSingleTapUp(const MotionEvent& e, int tap_count) override; 61 void OnLongPress(const MotionEvent& e) override; 62 bool OnScroll(const MotionEvent& e1, 63 const MotionEvent& e2, 64 const MotionEvent& secondary_pointer_down, 65 float distance_x, 66 float distance_y) override; 67 bool OnFling(const MotionEvent& e1, 68 const MotionEvent& e2, 69 float velocity_x, 70 float velocity_y) override; 71 bool OnSwipe(const MotionEvent& e1, 72 const MotionEvent& e2, 73 float velocity_x, 74 float velocity_y) override; 75 bool OnTwoFingerTap(const MotionEvent& e1, const MotionEvent& e2) override; OnTapCancel(const MotionEvent & e)76 void OnTapCancel(const MotionEvent& e) override {} 77 78 // DoubleTapListener implementation. 79 bool OnSingleTapConfirmed(const MotionEvent& e) override; 80 bool OnDoubleTap(const MotionEvent& e) override; 81 bool OnDoubleTapEvent(const MotionEvent& e) override; 82 }; 83 84 } // namespace ui 85 86 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_LISTENERS_H_ 87