filtered_gesture_provider.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_FILTERED_GESTURE_PROVIDER_H_
  5. #define UI_EVENTS_GESTURE_DETECTION_FILTERED_GESTURE_PROVIDER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/memory/raw_ptr.h"
  9. #include "ui/events/gesture_detection/gesture_event_data_packet.h"
  10. #include "ui/events/gesture_detection/gesture_provider.h"
  11. #include "ui/events/gesture_detection/touch_disposition_gesture_filter.h"
  12. namespace ui {
  13. // Provides filtered gesture detection and dispatch given a sequence of touch
  14. // events and touch event acks.
  15. class GESTURE_DETECTION_EXPORT FilteredGestureProvider final
  16. : public ui::TouchDispositionGestureFilterClient,
  17. public ui::GestureProviderClient {
  18. public:
  19. // |client| will be offered all gestures detected by the |gesture_provider_|
  20. // and allowed by the |gesture_filter_|.
  21. FilteredGestureProvider(const GestureProvider::Config& config,
  22. GestureProviderClient* client);
  23. FilteredGestureProvider(const FilteredGestureProvider&) = delete;
  24. FilteredGestureProvider& operator=(const FilteredGestureProvider&) = delete;
  25. ~FilteredGestureProvider() final;
  26. void UpdateConfig(const GestureProvider::Config& config);
  27. struct TouchHandlingResult {
  28. TouchHandlingResult();
  29. // True if |event| was both valid and successfully handled by the
  30. // gesture provider. Otherwise, false, in which case the caller should drop
  31. // |event| and cease further propagation.
  32. bool succeeded;
  33. // Whether |event| occurred beyond the touch slop region.
  34. bool moved_beyond_slop_region;
  35. };
  36. [[nodiscard]] TouchHandlingResult OnTouchEvent(const MotionEvent& event);
  37. // To be called upon asynchronous and synchronous ack of an event that was
  38. // forwarded after a successful call to |OnTouchEvent()|.
  39. void OnTouchEventAck(uint32_t unique_event_id,
  40. bool event_consumed,
  41. bool is_source_touch_event_set_blocking);
  42. void ResetGestureHandlingState();
  43. // Synthesizes and propagates gesture end events.
  44. void SendSynthesizedEndEvents();
  45. // Methods delegated to |gesture_provider_|.
  46. void ResetDetection();
  47. void SetMultiTouchZoomSupportEnabled(bool enabled);
  48. void SetDoubleTapSupportForPlatformEnabled(bool enabled);
  49. void SetDoubleTapSupportForPageEnabled(bool enabled);
  50. const ui::MotionEvent* GetCurrentDownEvent() const;
  51. private:
  52. // GestureProviderClient implementation.
  53. void OnGestureEvent(const ui::GestureEventData& event) override;
  54. bool RequiresDoubleTapGestureEvents() const override;
  55. // TouchDispositionGestureFilterClient implementation.
  56. void ForwardGestureEvent(const ui::GestureEventData& event) override;
  57. const raw_ptr<GestureProviderClient> client_;
  58. std::unique_ptr<ui::GestureProvider> gesture_provider_;
  59. ui::TouchDispositionGestureFilter gesture_filter_;
  60. bool handling_event_;
  61. bool any_touch_moved_beyond_slop_region_;
  62. ui::GestureEventDataPacket pending_gesture_packet_;
  63. };
  64. } // namespace ui
  65. #endif // UI_EVENTS_GESTURE_DETECTION_FILTERED_GESTURE_PROVIDER_H_