OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
rjkroege
2013/02/05 16:00:07
you need this on windows and aura. So it is misnam
mohsen
2013/02/06 16:13:06
Isn't it the case for touchpad TSC, too? Don't we
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/touchscreen_tap_suppression_controller.h " | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/debug/trace_event.h" | |
9 #include "base/logging.h" | |
10 #include "base/string_number_conversions.h" | |
11 #include "content/browser/renderer_host/gesture_event_filter.h" | |
12 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
13 #include "content/public/common/content_switches.h" | |
14 #include "ui/base/gestures/gesture_configuration.h" | |
15 | |
16 namespace content { | |
17 | |
18 TouchscreenTapSuppressionController::TouchscreenTapSuppressionController( | |
19 RenderWidgetHostImpl* rwhv, | |
20 GestureEventFilter* gef) | |
21 : render_widget_host_(rwhv), | |
22 gesture_event_filter_(gef), | |
23 state_(TouchscreenTapSuppressionController::NOTHING) { | |
24 } | |
25 | |
26 TouchscreenTapSuppressionController::~TouchscreenTapSuppressionController() { } | |
27 | |
28 void TouchscreenTapSuppressionController::GestureFlingCancel( | |
29 double cancel_time) { | |
30 switch (state_) { | |
31 case NOTHING: | |
32 case GFC_IN_PROGRESS: | |
33 case LAST_CANCEL_STOPPED_FLING: | |
34 state_ = GFC_IN_PROGRESS; | |
35 break; | |
36 case GTD_STASHED: | |
37 break; | |
38 } | |
39 } | |
40 | |
41 void TouchscreenTapSuppressionController::GestureFlingCancelAck( | |
42 bool processed) { | |
43 switch (state_) { | |
44 case NOTHING: | |
45 NOTREACHED() << "GFC_Ack without a GFC"; | |
46 break; | |
47 case GFC_IN_PROGRESS: | |
48 if (processed) | |
49 fling_cancel_time_ = base::TimeTicks::Now(); | |
50 state_ = LAST_CANCEL_STOPPED_FLING; | |
51 break; | |
52 case GTD_STASHED: | |
53 if (!processed) { | |
54 TRACE_EVENT0( | |
55 "browser", | |
56 "TouchscreenTapSuppressionController::GestureFlingCancelAck"); | |
57 tap_down_timer_.Stop(); | |
58 gesture_event_filter_->ForwardGestureEventForDeferral( | |
59 stashed_tap_down_); | |
60 state_ = NOTHING; | |
61 } // Else waiting for the timer to release the mouse event. | |
62 break; | |
63 case LAST_CANCEL_STOPPED_FLING: | |
64 break; | |
65 } | |
66 } | |
67 | |
68 bool TouchscreenTapSuppressionController::ShouldDeferGestureTapDown( | |
69 const WebKit::WebGestureEvent& event) { | |
70 switch (state_) { | |
71 case NOTHING: | |
72 return false; | |
73 case GFC_IN_PROGRESS: | |
74 tap_down_timer_.Start( | |
75 FROM_HERE, | |
76 base::TimeDelta::FromMilliseconds( | |
77 ui::GestureConfiguration::semi_long_press_time_in_seconds() * | |
78 1000), | |
79 this, | |
80 &TouchscreenTapSuppressionController::GestureTapDownTimerExpired); | |
81 stashed_tap_down_ = event; | |
82 state_ = GTD_STASHED; | |
83 return true; | |
84 case GTD_STASHED: | |
85 NOTREACHED() << "GestureTapDown on GTD_STASHED state"; | |
86 state_ = NOTHING; | |
87 return false; | |
88 case LAST_CANCEL_STOPPED_FLING: | |
89 if ((base::TimeTicks::Now() - fling_cancel_time_).InMilliseconds() | |
90 < ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms()) { | |
91 state_ = GTD_STASHED; | |
92 tap_down_timer_.Start( | |
93 FROM_HERE, | |
94 base::TimeDelta::FromMilliseconds( | |
95 ui::GestureConfiguration::semi_long_press_time_in_seconds() * | |
96 1000), | |
97 this, | |
98 &TouchscreenTapSuppressionController::GestureTapDownTimerExpired); | |
99 stashed_tap_down_ = event; | |
100 return true; | |
101 } | |
102 state_ = NOTHING; | |
103 return false; | |
104 } | |
105 NOTREACHED() << "Invalid state"; | |
106 return false; | |
107 } | |
108 | |
109 bool TouchscreenTapSuppressionController::ShouldSuppressGestureTap() { | |
110 switch (state_) { | |
111 case NOTHING: | |
112 case GFC_IN_PROGRESS: | |
113 return false; | |
114 case GTD_STASHED: | |
115 tap_down_timer_.Stop(); | |
116 state_ = NOTHING; | |
117 return true; | |
118 case LAST_CANCEL_STOPPED_FLING: | |
119 NOTREACHED() << "Invalid GestureTap on LAST_CANCEL_STOPPED_FLING state"; | |
120 return false; | |
121 } | |
122 NOTREACHED() << "Invalid state"; | |
123 return false; | |
124 } | |
125 | |
126 bool TouchscreenTapSuppressionController::ShouldSuppressGestureTapCancel() { | |
127 switch (state_) { | |
128 case NOTHING: | |
129 case GFC_IN_PROGRESS: | |
130 return false; | |
131 case GTD_STASHED: | |
132 tap_down_timer_.Stop(); | |
133 state_ = NOTHING; | |
134 return true; | |
135 case LAST_CANCEL_STOPPED_FLING: | |
136 NOTREACHED() << "GestureTapCancel on LAST_CANCEL_STOPPED_FLING state"; | |
137 return false; | |
138 } | |
139 NOTREACHED() << "Invalid state"; | |
140 return false; | |
141 } | |
142 | |
143 void TouchscreenTapSuppressionController::GestureTapDownTimerExpired() { | |
144 switch (state_) { | |
145 case NOTHING: | |
146 case GFC_IN_PROGRESS: | |
147 case LAST_CANCEL_STOPPED_FLING: | |
148 NOTREACHED() << "Timer fired on invalid state."; | |
149 state_ = NOTHING; | |
150 break; | |
151 case GTD_STASHED: | |
152 TRACE_EVENT0( | |
153 "browser", | |
154 "TouchscreenTapSuppressionController::GestureTapDownTimerExpired"); | |
155 gesture_event_filter_->ForwardGestureEventSkipDeferral(stashed_tap_down_); | |
156 state_ = NOTHING; | |
157 break; | |
158 } | |
159 } | |
160 | |
161 } // namespace content | |
OLD | NEW |