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
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/input/tap_suppression_controller.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "content/browser/renderer_host/input/tap_suppression_controller_client.h"
13 TapSuppressionController::TapSuppressionController(
14 TapSuppressionControllerClient
* client
)
16 state_(TapSuppressionController::NOTHING
) {
19 TapSuppressionController::~TapSuppressionController() {}
21 void TapSuppressionController::GestureFlingCancel() {
25 case LAST_CANCEL_STOPPED_FLING
:
26 state_
= GFC_IN_PROGRESS
;
28 case TAP_DOWN_STASHED
:
33 void TapSuppressionController::GestureFlingCancelAck(bool processed
) {
34 base::TimeTicks event_time
= Now();
40 fling_cancel_time_
= event_time
;
41 state_
= LAST_CANCEL_STOPPED_FLING
;
43 case TAP_DOWN_STASHED
:
45 TRACE_EVENT0("browser",
46 "TapSuppressionController::GestureFlingCancelAck");
48 client_
->ForwardStashedTapDown();
50 } // Else waiting for the timer to release the stashed tap down.
52 case LAST_CANCEL_STOPPED_FLING
:
57 bool TapSuppressionController::ShouldDeferTapDown() {
58 base::TimeTicks event_time
= Now();
63 state_
= TAP_DOWN_STASHED
;
65 base::TimeDelta::FromMilliseconds(client_
->MaxTapGapTimeInMs()));
67 case TAP_DOWN_STASHED
:
68 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state";
71 case LAST_CANCEL_STOPPED_FLING
:
72 if ((event_time
- fling_cancel_time_
).InMilliseconds()
73 < client_
->MaxCancelToDownTimeInMs()) {
74 state_
= TAP_DOWN_STASHED
;
76 base::TimeDelta::FromMilliseconds(client_
->MaxTapGapTimeInMs()));
83 NOTREACHED() << "Invalid state";
87 bool TapSuppressionController::ShouldSuppressTapEnd() {
92 case TAP_DOWN_STASHED
:
95 client_
->DropStashedTapDown();
97 case LAST_CANCEL_STOPPED_FLING
:
98 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state";
103 base::TimeTicks
TapSuppressionController::Now() {
104 return base::TimeTicks::Now();
107 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta
& delay
) {
108 tap_down_timer_
.Start(FROM_HERE
, delay
, this,
109 &TapSuppressionController::TapDownTimerExpired
);
112 void TapSuppressionController::StopTapDownTimer() {
113 tap_down_timer_
.Stop();
116 void TapSuppressionController::TapDownTimerExpired() {
119 case GFC_IN_PROGRESS
:
120 case LAST_CANCEL_STOPPED_FLING
:
121 NOTREACHED() << "Timer fired on invalid state.";
124 case TAP_DOWN_STASHED
:
125 TRACE_EVENT0("browser",
126 "TapSuppressionController::TapDownTimerExpired");
127 client_
->ForwardStashedTapDown();
133 } // namespace content