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

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

Issue 2542453003: Suppress LongPress/Tap, and TwoFingerTap when TapDown cancels a fling. (Closed)
Patch Set: Created 4 years 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/logging.h" 7 #include "base/logging.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.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 // 500ms is the timeout for long press. The max_tap_gap_time should be large
14 // enough to suppress the long press if needed. 50ms extra delay is added to
15 // make sure that the stashed tap down event is not forwarded before
16 // suppressing the long press.
tdresser 2016/12/07 19:53:21 Clarify this comment - the long press could happen
sahel 2016/12/09 16:49:12 Done.
13 TapSuppressionController::Config::Config() 17 TapSuppressionController::Config::Config()
14 : enabled(false), 18 : enabled(false),
15 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)), 19 max_cancel_to_down_time(base::TimeDelta::FromMilliseconds(180)),
16 max_tap_gap_time(base::TimeDelta::FromMilliseconds(500)) { 20 max_tap_gap_time(base::TimeDelta::FromMilliseconds(550)) {}
tdresser 2016/12/07 19:53:21 Should the long press time be passed in as a param
sahel 2016/12/09 16:49:12 Done.
17 }
18 21
19 TapSuppressionController::TapSuppressionController( 22 TapSuppressionController::TapSuppressionController(
20 TapSuppressionControllerClient* client, 23 TapSuppressionControllerClient* client,
21 const Config& config) 24 const Config& config)
22 : client_(client), 25 : client_(client),
23 state_(config.enabled ? NOTHING : DISABLED), 26 state_(config.enabled ? NOTHING : DISABLED),
24 max_cancel_to_down_time_(config.max_cancel_to_down_time), 27 max_cancel_to_down_time_(config.max_cancel_to_down_time),
25 max_tap_gap_time_(config.max_tap_gap_time) { 28 max_tap_gap_time_(config.max_tap_gap_time) {
26 } 29 }
27 30
28 TapSuppressionController::~TapSuppressionController() {} 31 TapSuppressionController::~TapSuppressionController() {}
29 32
30 void TapSuppressionController::GestureFlingCancel() { 33 void TapSuppressionController::GestureFlingCancel() {
31 switch (state_) { 34 switch (state_) {
32 case DISABLED: 35 case DISABLED:
33 break; 36 break;
34 case NOTHING: 37 case NOTHING:
35 case GFC_IN_PROGRESS: 38 case GFC_IN_PROGRESS:
36 case LAST_CANCEL_STOPPED_FLING: 39 case LAST_CANCEL_STOPPED_FLING:
40 case SUPPRESSING_TAPS:
37 state_ = GFC_IN_PROGRESS; 41 state_ = GFC_IN_PROGRESS;
38 break; 42 break;
39 case TAP_DOWN_STASHED: 43 case TAP_DOWN_STASHED:
40 break; 44 break;
41 } 45 }
42 } 46 }
43 47
44 void TapSuppressionController::GestureFlingCancelAck(bool processed) { 48 void TapSuppressionController::GestureFlingCancelAck(bool processed) {
45 base::TimeTicks event_time = Now(); 49 base::TimeTicks event_time = Now();
46 switch (state_) { 50 switch (state_) {
47 case DISABLED: 51 case DISABLED:
48 case NOTHING: 52 case NOTHING:
53 case SUPPRESSING_TAPS:
49 break; 54 break;
50 case GFC_IN_PROGRESS: 55 case GFC_IN_PROGRESS:
51 if (processed) 56 if (processed)
52 fling_cancel_time_ = event_time; 57 fling_cancel_time_ = event_time;
53 state_ = LAST_CANCEL_STOPPED_FLING; 58 state_ = LAST_CANCEL_STOPPED_FLING;
54 break; 59 break;
55 case TAP_DOWN_STASHED: 60 case TAP_DOWN_STASHED:
56 if (!processed) { 61 if (!processed) {
57 TRACE_EVENT0("browser", 62 TRACE_EVENT0("browser",
58 "TapSuppressionController::GestureFlingCancelAck"); 63 "TapSuppressionController::GestureFlingCancelAck");
59 StopTapDownTimer(); 64 StopTapDownTimer();
60 client_->ForwardStashedTapDown(); 65 // If the fling cancel is not processed, forward all stashed
66 // gesture events.
67 client_->ForwardStashedGestureEvents();
61 state_ = NOTHING; 68 state_ = NOTHING;
62 } // Else waiting for the timer to release the stashed tap down. 69 } // Else waiting for the timer to release the stashed tap down.
63 break; 70 break;
64 case LAST_CANCEL_STOPPED_FLING: 71 case LAST_CANCEL_STOPPED_FLING:
65 break; 72 break;
66 } 73 }
67 } 74 }
68 75
69 bool TapSuppressionController::ShouldDeferTapDown() { 76 bool TapSuppressionController::ShouldDeferTapDown() {
70 base::TimeTicks event_time = Now(); 77 base::TimeTicks event_time = Now();
(...skipping 11 matching lines...) Expand all
82 return false; 89 return false;
83 case LAST_CANCEL_STOPPED_FLING: 90 case LAST_CANCEL_STOPPED_FLING:
84 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) { 91 if ((event_time - fling_cancel_time_) < max_cancel_to_down_time_) {
85 state_ = TAP_DOWN_STASHED; 92 state_ = TAP_DOWN_STASHED;
86 StartTapDownTimer(max_tap_gap_time_); 93 StartTapDownTimer(max_tap_gap_time_);
87 return true; 94 return true;
88 } else { 95 } else {
89 state_ = NOTHING; 96 state_ = NOTHING;
90 return false; 97 return false;
91 } 98 }
99 // Stop suppressing tap end events.
100 case SUPPRESSING_TAPS:
101 state_ = NOTHING;
102 return false;
92 } 103 }
93 NOTREACHED() << "Invalid state"; 104 NOTREACHED() << "Invalid state";
94 return false; 105 return false;
95 } 106 }
96 107
97 bool TapSuppressionController::ShouldSuppressTapEnd() { 108 bool TapSuppressionController::ShouldSuppressTapEnd() {
98 switch (state_) { 109 switch (state_) {
99 case DISABLED: 110 case DISABLED:
100 case NOTHING: 111 case NOTHING:
101 case GFC_IN_PROGRESS: 112 case GFC_IN_PROGRESS:
102 return false; 113 return false;
103 case TAP_DOWN_STASHED: 114 case TAP_DOWN_STASHED:
104 state_ = NOTHING; 115 // A tap cancel happens before long tap and two finger tap events. To
116 // drop the latter events as well as the tap cancel, change the state
117 // to "SUPPRESSING_TAPS" when the stashed tap down is dropped.
118 state_ = SUPPRESSING_TAPS;
105 StopTapDownTimer(); 119 StopTapDownTimer();
106 client_->DropStashedTapDown(); 120 client_->DropStashedTapDown();
107 return true; 121 return true;
108 case LAST_CANCEL_STOPPED_FLING: 122 case LAST_CANCEL_STOPPED_FLING:
109 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state"; 123 NOTREACHED() << "Invalid tap end on LAST_CANCEL_STOPPED_FLING state";
124 case SUPPRESSING_TAPS:
125 return true;
110 } 126 }
111 return false; 127 return false;
112 } 128 }
113 129
114 base::TimeTicks TapSuppressionController::Now() { 130 base::TimeTicks TapSuppressionController::Now() {
115 return base::TimeTicks::Now(); 131 return base::TimeTicks::Now();
116 } 132 }
117 133
118 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) { 134 void TapSuppressionController::StartTapDownTimer(const base::TimeDelta& delay) {
119 tap_down_timer_.Start(FROM_HERE, delay, this, 135 tap_down_timer_.Start(FROM_HERE, delay, this,
120 &TapSuppressionController::TapDownTimerExpired); 136 &TapSuppressionController::TapDownTimerExpired);
121 } 137 }
122 138
123 void TapSuppressionController::StopTapDownTimer() { 139 void TapSuppressionController::StopTapDownTimer() {
124 tap_down_timer_.Stop(); 140 tap_down_timer_.Stop();
125 } 141 }
126 142
127 void TapSuppressionController::TapDownTimerExpired() { 143 void TapSuppressionController::TapDownTimerExpired() {
128 switch (state_) { 144 switch (state_) {
129 case DISABLED: 145 case DISABLED:
130 case NOTHING: 146 case NOTHING:
147 case SUPPRESSING_TAPS:
131 NOTREACHED() << "Timer fired on invalid state."; 148 NOTREACHED() << "Timer fired on invalid state.";
132 break; 149 break;
133 case GFC_IN_PROGRESS: 150 case GFC_IN_PROGRESS:
134 case LAST_CANCEL_STOPPED_FLING: 151 case LAST_CANCEL_STOPPED_FLING:
135 NOTREACHED() << "Timer fired on invalid state."; 152 NOTREACHED() << "Timer fired on invalid state.";
136 state_ = NOTHING; 153 state_ = NOTHING;
137 break; 154 break;
138 case TAP_DOWN_STASHED: 155 case TAP_DOWN_STASHED:
139 TRACE_EVENT0("browser", 156 TRACE_EVENT0("browser",
140 "TapSuppressionController::TapDownTimerExpired"); 157 "TapSuppressionController::TapDownTimerExpired");
158 // When the timer expires, only forward the stashed tap down event, and
159 // drop other stashed gesture events (show press or long press).
141 client_->ForwardStashedTapDown(); 160 client_->ForwardStashedTapDown();
142 state_ = NOTHING; 161 state_ = SUPPRESSING_TAPS;
143 break; 162 break;
144 } 163 }
145 } 164 }
146 165
147 } // namespace content 166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698