| 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 explicit TapSuppressionController(TapSuppressionControllerClient* client); | 22 struct CONTENT_EXPORT Config { |
| 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); |
| 23 virtual ~TapSuppressionController(); | 38 virtual ~TapSuppressionController(); |
| 24 | 39 |
| 25 // Should be called whenever a GestureFlingCancel event is received. | 40 // Should be called whenever a GestureFlingCancel event is received. |
| 26 void GestureFlingCancel(); | 41 void GestureFlingCancel(); |
| 27 | 42 |
| 28 // Should be called whenever an ACK for a GestureFlingCancel event is | 43 // Should be called whenever an ACK for a GestureFlingCancel event is |
| 29 // received. |processed| is true when the GestureFlingCancel actually stopped | 44 // received. |processed| is true when the GestureFlingCancel actually stopped |
| 30 // a fling and therefore should suppress the forwarding of the following tap. | 45 // a fling and therefore should suppress the forwarding of the following tap. |
| 31 void GestureFlingCancelAck(bool processed); | 46 void GestureFlingCancelAck(bool processed); |
| 32 | 47 |
| 33 // Should be called whenever a tap down (touchpad or touchscreen) is received. | 48 // Should be called whenever a tap down (touchpad or touchscreen) is received. |
| 34 // Returns true if the tap down should be deferred. The caller is responsible | 49 // Returns true if the tap down should be deferred. The caller is responsible |
| 35 // for keeping the event for later release, if needed. | 50 // for keeping the event for later release, if needed. |
| 36 bool ShouldDeferTapDown(); | 51 bool ShouldDeferTapDown(); |
| 37 | 52 |
| 38 // Should be called whenever a tap ending event is received. Returns true if | 53 // Should be called whenever a tap ending event is received. Returns true if |
| 39 // the tap event should be suppressed. | 54 // the tap event should be suppressed. |
| 40 bool ShouldSuppressTapEnd(); | 55 bool ShouldSuppressTapEnd(); |
| 41 | 56 |
| 42 protected: | 57 protected: |
| 43 virtual base::TimeTicks Now(); | 58 virtual base::TimeTicks Now(); |
| 44 virtual void StartTapDownTimer(const base::TimeDelta& delay); | 59 virtual void StartTapDownTimer(const base::TimeDelta& delay); |
| 45 virtual void StopTapDownTimer(); | 60 virtual void StopTapDownTimer(); |
| 46 void TapDownTimerExpired(); | 61 void TapDownTimerExpired(); |
| 47 | 62 |
| 48 private: | 63 private: |
| 49 friend class MockTapSuppressionController; | 64 friend class MockTapSuppressionController; |
| 50 | 65 |
| 51 enum State { | 66 enum State { |
| 67 DISABLED, |
| 52 NOTHING, | 68 NOTHING, |
| 53 GFC_IN_PROGRESS, | 69 GFC_IN_PROGRESS, |
| 54 TAP_DOWN_STASHED, | 70 TAP_DOWN_STASHED, |
| 55 LAST_CANCEL_STOPPED_FLING, | 71 LAST_CANCEL_STOPPED_FLING, |
| 56 }; | 72 }; |
| 57 | 73 |
| 58 | 74 |
| 59 TapSuppressionControllerClient* client_; | 75 TapSuppressionControllerClient* client_; |
| 60 base::OneShotTimer<TapSuppressionController> tap_down_timer_; | 76 base::OneShotTimer<TapSuppressionController> tap_down_timer_; |
| 61 State state_; | 77 State state_; |
| 62 | 78 |
| 79 bool enabled_; |
| 80 base::TimeDelta max_cancel_to_down_time_; |
| 81 base::TimeDelta max_tap_gap_time_; |
| 82 |
| 63 // TODO(rjkroege): During debugging, the event times did not prove reliable. | 83 // TODO(rjkroege): During debugging, the event times did not prove reliable. |
| 64 // Replace the use of base::TimeTicks with an accurate event time when they | 84 // Replace the use of base::TimeTicks with an accurate event time when they |
| 65 // become available post http://crbug.com/119556. | 85 // become available post http://crbug.com/119556. |
| 66 base::TimeTicks fling_cancel_time_; | 86 base::TimeTicks fling_cancel_time_; |
| 67 | 87 |
| 68 DISALLOW_COPY_AND_ASSIGN(TapSuppressionController); | 88 DISALLOW_COPY_AND_ASSIGN(TapSuppressionController); |
| 69 }; | 89 }; |
| 70 | 90 |
| 71 } // namespace content | 91 } // namespace content |
| 72 | 92 |
| 73 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ | 93 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TAP_SUPPRESSION_CONTROLLER_H_ |
| OLD | NEW |