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::Config::Config()
15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)),
16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(500)) {
19 TapSuppressionController::TapSuppressionController(
20 TapSuppressionControllerClient* client,
23 state_(config.enabled ? NOTHING : DISABLED),
24 max_cancel_to_down_time_(config.max_cancel_to_down_time),
25 max_tap_gap_time_(config.max_tap_gap_time) {
28 TapSuppressionController::~TapSuppressionController() {}
30 void TapSuppressionController::GestureFlingCancel() {
36 case LAST_CANCEL_STOPPED_FLING:
37 state_ = GFC_IN_PROGRESS;
39 case TAP_DOWN_STASHED:
44 void TapSuppressionController::GestureFlingCancelAck(bool processed) {
45 base::TimeTicks event_time = Now();
52 fling_cancel_time_ = event_time;
53 state_ = LAST_CANCEL_STOPPED_FLING;
55 case TAP_DOWN_STASHED:
57 TRACE_EVENT0("browser",
58 "TapSuppressionController::GestureFlingCancelAck");
60 client_->ForwardStashedTapDown();
62 } // Else waiting for the timer to release the stashed tap down.
64 case LAST_CANCEL_STOPPED_FLING:
69 bool TapSuppressionController::ShouldDeferTapDown() {
70 base::TimeTicks event_time = Now();
76 state_ = TAP_DOWN_STASHED;
77 StartTapDownTimer(max_tap_gap_time_);
79 case TAP_DOWN_STASHED:
80 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state";
83 case LAST_CANCEL_STOPPED_FLING:
84 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) {
85 state_ = TAP_DOWN_STASHED;
86 StartTapDownTimer(max_tap_gap_time_);
93 NOTREACHED() << "Invalid state";
97 bool TapSuppressionController::ShouldSuppressTapEnd() {
101 case GFC_IN_PROGRESS:
103 case TAP_DOWN_STASHED:
106 client_->DropStashedTapDown();
108 case LAST_CANCEL_STOPPED_FLING:
109 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state";
114 base::TimeTicks TapSuppressionController::Now() {
115 return base::TimeTicks::Now();
118 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) {
119 tap_down_timer_.Start(FROM_HERE, delay, this,
120 &TapSuppressionController::TapDownTimerExpired);
123 void TapSuppressionController::StopTapDownTimer() {
124 tap_down_timer_.Stop();
127 void TapSuppressionController::TapDownTimerExpired() {
131 NOTREACHED() << "Timer fired on invalid state.";
133 case GFC_IN_PROGRESS:
134 case LAST_CANCEL_STOPPED_FLING:
135 NOTREACHED() << "Timer fired on invalid state.";
138 case TAP_DOWN_STASHED:
139 TRACE_EVENT0("browser",
140 "TapSuppressionController::TapDownTimerExpired");
141 client_->ForwardStashedTapDown();
147 } // namespace content