OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ |
7 | 7 |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 class TapSuppressionControllerClient; | 14 class TapSuppressionControllerClient; |
15 | 15 |
16 // The core controller for suppression of taps (touchpad or touchscreen) | 16 // The core controller for suppression of taps (touchpad or touchscreen) |
17 // immediately following a GestureFlingCancel event (caused by the same tap). | 17 // immediately following a GestureFlingCancel event (caused by the same tap). |
18 // Only taps of sufficient speed and within a specified time window after a | 18 // Only taps of sufficient speed and within a specified time window after a |
19 // GestureFlingCancel are suppressed. | 19 // GestureFlingCancel are suppressed. |
20 class CONTENT_EXPORT TapSuppressionController { | 20 class CONTENT_EXPORT TapSuppressionController { |
21 public: | 21 public: |
22 struct CONTENT_EXPORT Config { | 22 explicit TapSuppressionController(TapSuppressionControllerClient* client); |
23 Config(); | |
24 | |
25 // Defaults to false, in which case no suppression is performed. | |
26 bool enabled; | |
27 | |
28 // The maximum time allowed between a GestureFlingCancel and its | |
29 // corresponding tap down. | |
30 base::TimeDelta max_cancel_to_down_time; | |
31 | |
32 // The maximum time allowed between a single tap's down and up events. | |
33 base::TimeDelta max_tap_gap_time; | |
34 }; | |
35 | |
36 TapSuppressionController(TapSuppressionControllerClient* client, | |
37 const Config& config); | |
38 virtual ~TapSuppressionController(); | 23 virtual ~TapSuppressionController(); |
39 | 24 |
40 // Should be called whenever a GestureFlingCancel event is received. | 25 // Should be called whenever a GestureFlingCancel event is received. |
41 void GestureFlingCancel(); | 26 void GestureFlingCancel(); |
42 | 27 |
43 // Should be called whenever an ACK for a GestureFlingCancel event is | 28 // Should be called whenever an ACK for a GestureFlingCancel event is |
44 // received. |processed| is true when the GestureFlingCancel actually stopped | 29 // received. |processed| is true when the GestureFlingCancel actually stopped |
45 // a fling and therefore should suppress the forwarding of the following tap. | 30 // a fling and therefore should suppress the forwarding of the following tap. |
46 void GestureFlingCancelAck(bool processed); | 31 void GestureFlingCancelAck(bool processed); |
47 | 32 |
48 // Should be called whenever a tap down (touchpad or touchscreen) is received. | 33 // Should be called whenever a tap down (touchpad or touchscreen) is received. |
49 // Returns true if the tap down should be deferred. The caller is responsible | 34 // Returns true if the tap down should be deferred. The caller is responsible |
50 // for keeping the event for later release, if needed. | 35 // for keeping the event for later release, if needed. |
51 bool ShouldDeferTapDown(); | 36 bool ShouldDeferTapDown(); |
52 | 37 |
53 // Should be called whenever a tap ending event is received. Returns true if | 38 // Should be called whenever a tap ending event is received. Returns true if |
54 // the tap event should be suppressed. | 39 // the tap event should be suppressed. |
55 bool ShouldSuppressTapEnd(); | 40 bool ShouldSuppressTapEnd(); |
56 | 41 |
57 protected: | 42 protected: |
58 virtual base::TimeTicks Now(); | 43 virtual base::TimeTicks Now(); |
59 virtual void StartTapDownTimer(const base::TimeDelta& delay); | 44 virtual void StartTapDownTimer(const base::TimeDelta& delay); |
60 virtual void StopTapDownTimer(); | 45 virtual void StopTapDownTimer(); |
61 void TapDownTimerExpired(); | 46 void TapDownTimerExpired(); |
62 | 47 |
63 private: | 48 private: |
64 friend class MockTapSuppressionController; | 49 friend class MockTapSuppressionController; |
65 | 50 |
66 enum State { | 51 enum State { |
67 DISABLED, | |
68 NOTHING, | 52 NOTHING, |
69 GFC_IN_PROGRESS, | 53 GFC_IN_PROGRESS, |
70 TAP_DOWN_STASHED, | 54 TAP_DOWN_STASHED, |
71 LAST_CANCEL_STOPPED_FLING, | 55 LAST_CANCEL_STOPPED_FLING, |
72 }; | 56 }; |
73 | 57 |
74 | 58 |
75 TapSuppressionControllerClient* client_; | 59 TapSuppressionControllerClient* client_; |
76 base::OneShotTimer<TapSuppressionController> tap_down_timer_; | 60 base::OneShotTimer<TapSuppressionController> tap_down_timer_; |
77 State state_; | 61 State state_; |
78 | 62 |
79 base::TimeDelta max_cancel_to_down_time_; | |
80 base::TimeDelta max_tap_gap_time_; | |
81 | |
82 // TODO(rjkroege): During debugging, the event times did not prove reliable. | 63 // TODO(rjkroege): During debugging, the event times did not prove reliable. |
83 // Replace the use of base::TimeTicks with an accurate event time when they | 64 // Replace the use of base::TimeTicks with an accurate event time when they |
84 // become available post http://crbug.com/119556. | 65 // become available post http://crbug.com/119556. |
85 base::TimeTicks fling_cancel_time_; | 66 base::TimeTicks fling_cancel_time_; |
86 | 67 |
87 DISALLOW_COPY_AND_ASSIGN(TapSuppressionController); | 68 DISALLOW_COPY_AND_ASSIGN(TapSuppressionController); |
88 }; | 69 }; |
89 | 70 |
90 } // namespace content | 71 } // namespace content |
91 | 72 |
92 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ | 73 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ |
OLD | NEW |