OLD | NEW |
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/touchscreen_tap_suppression_contro
ller.h" | 5 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_contro
ller.h" |
6 | 6 |
7 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 7 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
8 #include "content/browser/renderer_host/input/tap_suppression_controller.h" | |
9 #include "ui/events/gestures/gesture_configuration.h" | |
10 | |
11 #if defined(OS_ANDROID) | |
12 #include "ui/gfx/android/view_configuration.h" | |
13 #endif | |
14 | 8 |
15 using blink::WebInputEvent; | 9 using blink::WebInputEvent; |
16 | 10 |
17 namespace content { | 11 namespace content { |
18 | 12 |
19 TouchscreenTapSuppressionController::TouchscreenTapSuppressionController( | 13 TouchscreenTapSuppressionController::TouchscreenTapSuppressionController( |
20 GestureEventQueue* geq) | 14 GestureEventQueue* geq, |
21 : gesture_event_queue_(geq), | 15 const TapSuppressionController::Config& config) |
22 controller_(new TapSuppressionController(this)) { | 16 : gesture_event_queue_(geq), controller_(this, config) { |
23 } | 17 } |
24 | 18 |
25 TouchscreenTapSuppressionController::~TouchscreenTapSuppressionController() {} | 19 TouchscreenTapSuppressionController::~TouchscreenTapSuppressionController() {} |
26 | 20 |
27 void TouchscreenTapSuppressionController::GestureFlingCancel() { | 21 void TouchscreenTapSuppressionController::GestureFlingCancel() { |
28 controller_->GestureFlingCancel(); | 22 controller_.GestureFlingCancel(); |
29 } | 23 } |
30 | 24 |
31 void TouchscreenTapSuppressionController::GestureFlingCancelAck( | 25 void TouchscreenTapSuppressionController::GestureFlingCancelAck( |
32 bool processed) { | 26 bool processed) { |
33 controller_->GestureFlingCancelAck(processed); | 27 controller_.GestureFlingCancelAck(processed); |
34 } | 28 } |
35 | 29 |
36 bool TouchscreenTapSuppressionController::FilterTapEvent( | 30 bool TouchscreenTapSuppressionController::FilterTapEvent( |
37 const GestureEventWithLatencyInfo& event) { | 31 const GestureEventWithLatencyInfo& event) { |
38 switch (event.event.type) { | 32 switch (event.event.type) { |
39 case WebInputEvent::GestureTapDown: | 33 case WebInputEvent::GestureTapDown: |
40 if (!controller_->ShouldDeferTapDown()) | 34 if (!controller_.ShouldDeferTapDown()) |
41 return false; | 35 return false; |
42 stashed_tap_down_.reset(new GestureEventWithLatencyInfo(event)); | 36 stashed_tap_down_.reset(new GestureEventWithLatencyInfo(event)); |
43 return true; | 37 return true; |
44 | 38 |
45 case WebInputEvent::GestureShowPress: | 39 case WebInputEvent::GestureShowPress: |
46 if (!stashed_tap_down_) | 40 if (!stashed_tap_down_) |
47 return false; | 41 return false; |
48 stashed_show_press_.reset(new GestureEventWithLatencyInfo(event)); | 42 stashed_show_press_.reset(new GestureEventWithLatencyInfo(event)); |
49 return true; | 43 return true; |
50 | 44 |
51 case WebInputEvent::GestureTapUnconfirmed: | 45 case WebInputEvent::GestureTapUnconfirmed: |
52 return stashed_tap_down_; | 46 return stashed_tap_down_; |
53 | 47 |
54 case WebInputEvent::GestureTapCancel: | 48 case WebInputEvent::GestureTapCancel: |
55 case WebInputEvent::GestureTap: | 49 case WebInputEvent::GestureTap: |
56 case WebInputEvent::GestureDoubleTap: | 50 case WebInputEvent::GestureDoubleTap: |
57 return controller_->ShouldSuppressTapEnd(); | 51 return controller_.ShouldSuppressTapEnd(); |
58 | 52 |
59 default: | 53 default: |
60 break; | 54 break; |
61 } | 55 } |
62 return false; | 56 return false; |
63 } | 57 } |
64 | 58 |
65 #if defined(OS_ANDROID) | |
66 // TODO(jdduke): Enable ui::GestureConfiguration on Android and initialize | |
67 // with parameters from ViewConfiguration. | |
68 int TouchscreenTapSuppressionController::MaxCancelToDownTimeInMs() { | |
69 return gfx::ViewConfiguration::GetTapTimeoutInMs(); | |
70 } | |
71 | |
72 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() { | |
73 return gfx::ViewConfiguration::GetLongPressTimeoutInMs(); | |
74 } | |
75 #else | |
76 int TouchscreenTapSuppressionController::MaxCancelToDownTimeInMs() { | |
77 return ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms(); | |
78 } | |
79 | |
80 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() { | |
81 return static_cast<int>( | |
82 ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000); | |
83 } | |
84 #endif | |
85 | |
86 void TouchscreenTapSuppressionController::DropStashedTapDown() { | 59 void TouchscreenTapSuppressionController::DropStashedTapDown() { |
87 stashed_tap_down_.reset(); | 60 stashed_tap_down_.reset(); |
88 stashed_show_press_.reset(); | 61 stashed_show_press_.reset(); |
89 } | 62 } |
90 | 63 |
91 void TouchscreenTapSuppressionController::ForwardStashedTapDown() { | 64 void TouchscreenTapSuppressionController::ForwardStashedTapDown() { |
92 DCHECK(stashed_tap_down_); | 65 DCHECK(stashed_tap_down_); |
93 ScopedGestureEvent tap_down = stashed_tap_down_.Pass(); | 66 ScopedGestureEvent tap_down = stashed_tap_down_.Pass(); |
94 ScopedGestureEvent show_press = stashed_show_press_.Pass(); | 67 ScopedGestureEvent show_press = stashed_show_press_.Pass(); |
95 gesture_event_queue_->ForwardGestureEvent(*tap_down); | 68 gesture_event_queue_->ForwardGestureEvent(*tap_down); |
96 if (show_press) | 69 if (show_press) |
97 gesture_event_queue_->ForwardGestureEvent(*show_press); | 70 gesture_event_queue_->ForwardGestureEvent(*show_press); |
98 } | 71 } |
99 | 72 |
100 } // namespace content | 73 } // namespace content |
OLD | NEW |