1 // Copyright (c) 2012 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/tap_suppression_controller.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "content/browser/renderer_host/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_
->ForwardStashedTapDownForDeferral();
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::ShouldSuppressTapUp() {
92 case TAP_DOWN_STASHED
:
95 client_
->DropStashedTapDown();
97 case LAST_CANCEL_STOPPED_FLING
:
98 NOTREACHED() << "Invalid TapUp on LAST_CANCEL_STOPPED_FLING state";
103 bool TapSuppressionController::ShouldSuppressTapCancel() {
106 case GFC_IN_PROGRESS
:
108 case TAP_DOWN_STASHED
:
111 client_
->DropStashedTapDown();
113 case LAST_CANCEL_STOPPED_FLING
:
114 NOTREACHED() << "Invalid TapCancel on LAST_CANCEL_STOPPED_FLING state";
119 base::TimeTicks
TapSuppressionController::Now() {
120 return base::TimeTicks::Now();
123 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta
& delay
) {
124 tap_down_timer_
.Start(FROM_HERE
, delay
, this,
125 &TapSuppressionController::TapDownTimerExpired
);
128 void TapSuppressionController::StopTapDownTimer() {
129 tap_down_timer_
.Stop();
132 void TapSuppressionController::TapDownTimerExpired() {
135 case GFC_IN_PROGRESS
:
136 case LAST_CANCEL_STOPPED_FLING
:
137 NOTREACHED() << "Timer fired on invalid state.";
140 case TAP_DOWN_STASHED
:
141 TRACE_EVENT0("browser",
142 "TapSuppressionController::TapDownTimerExpired");
143 client_
->ForwardStashedTapDownSkipDeferral();
149 } // namespace content