OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_TIMEOUT_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_TIMEOUT_HANDLER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" |
| 13 #include "content/browser/renderer_host/event_with_latency_info.h" |
| 14 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 15 #include "content/common/input/input_event_ack_state.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 class TouchEventQueue; |
| 20 |
| 21 class TouchTimeoutHandler { |
| 22 public: |
| 23 TouchTimeoutHandler(TouchEventQueue* touch_queue, |
| 24 base::TimeDelta desktop_timeout_delay, |
| 25 base::TimeDelta mobile_timeout_delay); |
| 26 |
| 27 ~TouchTimeoutHandler(); |
| 28 |
| 29 void StartIfNecessary(const TouchEventWithLatencyInfo& event); |
| 30 bool ConfirmTouchEvent(uint32_t unique_touch_event_id, |
| 31 InputEventAckState ack_result); |
| 32 bool FilterEvent(const blink::WebTouchEvent& event); |
| 33 void SetEnabled(bool enabled); |
| 34 void SetUseMobileTimeout(bool use_mobile_timeout); |
| 35 bool IsTimeoutTimerRunning() const { return timeout_monitor_.IsRunning(); } |
| 36 bool IsEnabled() const { return enabled_ && !GetTimeoutDelay().is_zero(); } |
| 37 |
| 38 private: |
| 39 enum PendingAckState { |
| 40 PENDING_ACK_NONE, |
| 41 PENDING_ACK_ORIGINAL_EVENT, |
| 42 PENDING_ACK_CANCEL_EVENT, |
| 43 }; |
| 44 |
| 45 void OnTimeOut(); |
| 46 // Skip a cancel event if the timed-out event had no consumer and was the |
| 47 // initial event in the gesture. |
| 48 bool AckedTimeoutEventRequiresCancel(InputEventAckState ack_result) const; |
| 49 void SetPendingAckState(PendingAckState new_pending_ack_state); |
| 50 void LogSequenceStartForUMA(); |
| 51 void LogSequenceEndForUMAIfNecessary(bool timed_out); |
| 52 base::TimeDelta GetTimeoutDelay() const; |
| 53 bool HasTimeoutEvent() const; |
| 54 |
| 55 TouchEventQueue* touch_queue_; |
| 56 |
| 57 // How long to wait on a touch ack before cancelling the touch sequence. |
| 58 const base::TimeDelta desktop_timeout_delay_; |
| 59 const base::TimeDelta mobile_timeout_delay_; |
| 60 bool use_mobile_timeout_; |
| 61 |
| 62 // The touch event source for which we expect the next ack. |
| 63 PendingAckState pending_ack_state_; |
| 64 |
| 65 // The event for which the ack timeout is triggered. |
| 66 TouchEventWithLatencyInfo timeout_event_; |
| 67 |
| 68 // Provides timeout-based callback behavior. |
| 69 TimeoutMonitor timeout_monitor_; |
| 70 |
| 71 bool enabled_; |
| 72 bool enabled_for_current_sequence_; |
| 73 |
| 74 // Bookkeeping to classify and log whether a touch sequence times out. |
| 75 bool sequence_awaiting_uma_update_; |
| 76 bool sequence_using_mobile_timeout_; |
| 77 }; |
| 78 |
| 79 } // namespace content |
| 80 |
| 81 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_TIMEOUT_HANDLER_H_ |
OLD | NEW |