filtered_gesture_provider.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "ui/events/gesture_detection/filtered_gesture_provider.h"
  5. #include "base/auto_reset.h"
  6. #include "base/check.h"
  7. #include "base/notreached.h"
  8. #include "ui/events/gesture_detection/motion_event.h"
  9. namespace ui {
  10. FilteredGestureProvider::TouchHandlingResult::TouchHandlingResult()
  11. : succeeded(false), moved_beyond_slop_region(false) {
  12. }
  13. FilteredGestureProvider::FilteredGestureProvider(
  14. const GestureProvider::Config& config,
  15. GestureProviderClient* client)
  16. : client_(client),
  17. gesture_provider_(std::make_unique<GestureProvider>(config, this)),
  18. gesture_filter_(this),
  19. handling_event_(false),
  20. any_touch_moved_beyond_slop_region_(false) {}
  21. FilteredGestureProvider::~FilteredGestureProvider() = default;
  22. void FilteredGestureProvider::UpdateConfig(
  23. const GestureProvider::Config& config) {
  24. gesture_provider_ = std::make_unique<ui::GestureProvider>(config, this);
  25. }
  26. FilteredGestureProvider::TouchHandlingResult
  27. FilteredGestureProvider::OnTouchEvent(const MotionEvent& event) {
  28. DCHECK(!handling_event_);
  29. base::AutoReset<bool> handling_event(&handling_event_, true);
  30. pending_gesture_packet_ = GestureEventDataPacket::FromTouch(event);
  31. if (event.GetAction() == MotionEvent::Action::DOWN)
  32. any_touch_moved_beyond_slop_region_ = false;
  33. if (!gesture_provider_->OnTouchEvent(event))
  34. return TouchHandlingResult();
  35. TouchDispositionGestureFilter::PacketResult filter_result =
  36. gesture_filter_.OnGesturePacket(pending_gesture_packet_);
  37. if (filter_result != TouchDispositionGestureFilter::SUCCESS) {
  38. NOTREACHED() << "Invalid touch gesture sequence detected.";
  39. return TouchHandlingResult();
  40. }
  41. TouchHandlingResult result;
  42. result.succeeded = true;
  43. result.moved_beyond_slop_region = any_touch_moved_beyond_slop_region_;
  44. return result;
  45. }
  46. void FilteredGestureProvider::OnTouchEventAck(
  47. uint32_t unique_event_id,
  48. bool event_consumed,
  49. bool is_source_touch_event_set_blocking) {
  50. gesture_filter_.OnTouchEventAck(unique_event_id, event_consumed,
  51. is_source_touch_event_set_blocking);
  52. }
  53. void FilteredGestureProvider::ResetGestureHandlingState() {
  54. gesture_filter_.ResetGestureHandlingState();
  55. }
  56. void FilteredGestureProvider::SendSynthesizedEndEvents() {
  57. gesture_provider_->SendSynthesizedEndEvents();
  58. }
  59. void FilteredGestureProvider::ResetDetection() {
  60. gesture_provider_->ResetDetection();
  61. }
  62. void FilteredGestureProvider::SetMultiTouchZoomSupportEnabled(
  63. bool enabled) {
  64. gesture_provider_->SetMultiTouchZoomSupportEnabled(enabled);
  65. }
  66. void FilteredGestureProvider::SetDoubleTapSupportForPlatformEnabled(
  67. bool enabled) {
  68. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(enabled);
  69. }
  70. void FilteredGestureProvider::SetDoubleTapSupportForPageEnabled(bool enabled) {
  71. gesture_provider_->SetDoubleTapSupportForPageEnabled(enabled);
  72. }
  73. const ui::MotionEvent* FilteredGestureProvider::GetCurrentDownEvent() const {
  74. return gesture_provider_->current_down_event();
  75. }
  76. void FilteredGestureProvider::OnGestureEvent(const GestureEventData& event) {
  77. if (handling_event_) {
  78. if (event.details.type() == ui::ET_GESTURE_SCROLL_BEGIN)
  79. any_touch_moved_beyond_slop_region_ = true;
  80. pending_gesture_packet_.Push(event);
  81. return;
  82. }
  83. gesture_filter_.OnGesturePacket(
  84. GestureEventDataPacket::FromTouchTimeout(event));
  85. }
  86. bool FilteredGestureProvider::RequiresDoubleTapGestureEvents() const {
  87. return client_->RequiresDoubleTapGestureEvents();
  88. }
  89. void FilteredGestureProvider::ForwardGestureEvent(
  90. const GestureEventData& event) {
  91. client_->OnGestureEvent(event);
  92. }
  93. } // namespace ui