Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/browser/renderer_host/input/tap_suppression_controller.cc

Issue 260923003: Revert of Consolidate all touch/gesture related constants in content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "content/browser/renderer_host/input/tap_suppression_controller.h" 5 #include "content/browser/renderer_host/input/tap_suppression_controller.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h" 9 #include "content/browser/renderer_host/input/tap_suppression_controller_client. h"
10 10
11 namespace content { 11 namespace content {
12 12
13 TapSuppressionController::Config::Config()
14 : enabled(false),
15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)),
16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(500)) {}
17
18 TapSuppressionController::TapSuppressionController( 13 TapSuppressionController::TapSuppressionController(
19 TapSuppressionControllerClient* client, 14 TapSuppressionControllerClient* client)
20 const Config& config)
21 : client_(client), 15 : client_(client),
22 state_(config.enabled ? NOTHING : DISABLED), 16 state_(TapSuppressionController::NOTHING) {
23 max_cancel_to_down_time_(config.max_cancel_to_down_time), 17 }
24 max_tap_gap_time_(config.max_tap_gap_time) {}
25 18
26 TapSuppressionController::~TapSuppressionController() {} 19 TapSuppressionController::~TapSuppressionController() {}
27 20
28 void TapSuppressionController::GestureFlingCancel() { 21 void TapSuppressionController::GestureFlingCancel() {
29 switch (state_) { 22 switch (state_) {
30 case DISABLED:
31 break;
32 case NOTHING: 23 case NOTHING:
33 case GFC_IN_PROGRESS: 24 case GFC_IN_PROGRESS:
34 case LAST_CANCEL_STOPPED_FLING: 25 case LAST_CANCEL_STOPPED_FLING:
35 state_ = GFC_IN_PROGRESS; 26 state_ = GFC_IN_PROGRESS;
36 break; 27 break;
37 case TAP_DOWN_STASHED: 28 case TAP_DOWN_STASHED:
38 break; 29 break;
39 } 30 }
40 } 31 }
41 32
42 void TapSuppressionController::GestureFlingCancelAck(bool processed) { 33 void TapSuppressionController::GestureFlingCancelAck(bool processed) {
43 base::TimeTicks event_time = Now(); 34 base::TimeTicks event_time = Now();
44 switch (state_) { 35 switch (state_) {
45 case DISABLED:
46 case NOTHING: 36 case NOTHING:
47 break; 37 break;
48 case GFC_IN_PROGRESS: 38 case GFC_IN_PROGRESS:
49 if (processed) 39 if (processed)
50 fling_cancel_time_ = event_time; 40 fling_cancel_time_ = event_time;
51 state_ = LAST_CANCEL_STOPPED_FLING; 41 state_ = LAST_CANCEL_STOPPED_FLING;
52 break; 42 break;
53 case TAP_DOWN_STASHED: 43 case TAP_DOWN_STASHED:
54 if (!processed) { 44 if (!processed) {
55 TRACE_EVENT0("browser", 45 TRACE_EVENT0("browser",
56 "TapSuppressionController::GestureFlingCancelAck"); 46 "TapSuppressionController::GestureFlingCancelAck");
57 StopTapDownTimer(); 47 StopTapDownTimer();
58 client_->ForwardStashedTapDown(); 48 client_->ForwardStashedTapDown();
59 state_ = NOTHING; 49 state_ = NOTHING;
60 } // Else waiting for the timer to release the stashed tap down. 50 } // Else waiting for the timer to release the stashed tap down.
61 break; 51 break;
62 case LAST_CANCEL_STOPPED_FLING: 52 case LAST_CANCEL_STOPPED_FLING:
63 break; 53 break;
64 } 54 }
65 } 55 }
66 56
67 bool TapSuppressionController::ShouldDeferTapDown() { 57 bool TapSuppressionController::ShouldDeferTapDown() {
68 base::TimeTicks event_time = Now(); 58 base::TimeTicks event_time = Now();
69 switch (state_) { 59 switch (state_) {
70 case DISABLED:
71 case NOTHING: 60 case NOTHING:
72 return false; 61 return false;
73 case GFC_IN_PROGRESS: 62 case GFC_IN_PROGRESS:
74 state_ = TAP_DOWN_STASHED; 63 state_ = TAP_DOWN_STASHED;
75 StartTapDownTimer(max_tap_gap_time_); 64 StartTapDownTimer(
65 base::TimeDelta::FromMilliseconds(client_->MaxTapGapTimeInMs()));
76 return true; 66 return true;
77 case TAP_DOWN_STASHED: 67 case TAP_DOWN_STASHED:
78 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state"; 68 NOTREACHED() << "TapDown on TAP_DOWN_STASHED state";
79 state_ = NOTHING; 69 state_ = NOTHING;
80 return false; 70 return false;
81 case LAST_CANCEL_STOPPED_FLING: 71 case LAST_CANCEL_STOPPED_FLING:
82 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) { 72 if ((event_time - fling_cancel_time_).InMilliseconds()
73 < client_->MaxCancelToDownTimeInMs()) {
83 state_ = TAP_DOWN_STASHED; 74 state_ = TAP_DOWN_STASHED;
84 StartTapDownTimer(max_tap_gap_time_); 75 StartTapDownTimer(
76 base::TimeDelta::FromMilliseconds(client_->MaxTapGapTimeInMs()));
85 return true; 77 return true;
86 } else { 78 } else {
87 state_ = NOTHING; 79 state_ = NOTHING;
88 return false; 80 return false;
89 } 81 }
90 } 82 }
91 NOTREACHED() << "Invalid state"; 83 NOTREACHED() << "Invalid state";
92 return false; 84 return false;
93 } 85 }
94 86
95 bool TapSuppressionController::ShouldSuppressTapEnd() { 87 bool TapSuppressionController::ShouldSuppressTapEnd() {
96 switch (state_) { 88 switch (state_) {
97 case DISABLED:
98 case NOTHING: 89 case NOTHING:
99 case GFC_IN_PROGRESS: 90 case GFC_IN_PROGRESS:
100 return false; 91 return false;
101 case TAP_DOWN_STASHED: 92 case TAP_DOWN_STASHED:
102 state_ = NOTHING; 93 state_ = NOTHING;
103 StopTapDownTimer(); 94 StopTapDownTimer();
104 client_->DropStashedTapDown(); 95 client_->DropStashedTapDown();
105 return true; 96 return true;
106 case LAST_CANCEL_STOPPED_FLING: 97 case LAST_CANCEL_STOPPED_FLING:
107 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; 98 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state";
108 } 99 }
109 return false; 100 return false;
110 } 101 }
111 102
112 base::TimeTicks TapSuppressionController::Now() { 103 base::TimeTicks TapSuppressionController::Now() {
113 return base::TimeTicks::Now(); 104 return base::TimeTicks::Now();
114 } 105 }
115 106
116 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { 107 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) {
117 tap_down_timer_.Start(FROM_HERE, delay, this, 108 tap_down_timer_.Start(FROM_HERE, delay, this,
118 &TapSuppressionController::TapDownTimerExpired); 109 &TapSuppressionController::TapDownTimerExpired);
119 } 110 }
120 111
121 void TapSuppressionController::StopTapDownTimer() { 112 void TapSuppressionController::StopTapDownTimer() {
122 tap_down_timer_.Stop(); 113 tap_down_timer_.Stop();
123 } 114 }
124 115
125 void TapSuppressionController::TapDownTimerExpired() { 116 void TapSuppressionController::TapDownTimerExpired() {
126 switch (state_) { 117 switch (state_) {
127 case DISABLED:
128 case NOTHING: 118 case NOTHING:
129 NOTREACHED() << "Timer fired on invalid state.";
130 break;
131 case GFC_IN_PROGRESS: 119 case GFC_IN_PROGRESS:
132 case LAST_CANCEL_STOPPED_FLING: 120 case LAST_CANCEL_STOPPED_FLING:
133 NOTREACHED() << "Timer fired on invalid state."; 121 NOTREACHED() << "Timer fired on invalid state.";
134 state_ = NOTHING; 122 state_ = NOTHING;
135 break; 123 break;
136 case TAP_DOWN_STASHED: 124 case TAP_DOWN_STASHED:
137 TRACE_EVENT0("browser", 125 TRACE_EVENT0("browser",
138 "TapSuppressionController::TapDownTimerExpired"); 126 "TapSuppressionController::TapDownTimerExpired");
139 client_->ForwardStashedTapDown(); 127 client_->ForwardStashedTapDown();
140 state_ = NOTHING; 128 state_ = NOTHING;
141 break; 129 break;
142 } 130 }
143 } 131 }
144 132
145 } // namespace content 133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698