gesture_listeners.h 3.5 KB

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