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/touchscreen_tap_suppression_controller.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"
11 #if defined(OS_ANDROID)
12 #include "ui/gfx/android/view_configuration.h"
17 TouchscreenTapSuppressionController::TouchscreenTapSuppressionController(
18 GestureEventQueue* geq)
19 : gesture_event_queue_(geq),
20 controller_(new TapSuppressionController(this)) {
23 TouchscreenTapSuppressionController::~TouchscreenTapSuppressionController() {}
25 void TouchscreenTapSuppressionController::GestureFlingCancel() {
26 controller_->GestureFlingCancel();
29 void TouchscreenTapSuppressionController::GestureFlingCancelAck(
31 controller_->GestureFlingCancelAck(processed);
34 bool TouchscreenTapSuppressionController::ShouldDeferGestureTapDown(
35 const GestureEventWithLatencyInfo& event) {
36 bool should_defer = controller_->ShouldDeferTapDown();
38 stashed_tap_down_.reset(new GestureEventWithLatencyInfo(event));
42 bool TouchscreenTapSuppressionController::ShouldDeferGestureShowPress(
43 const GestureEventWithLatencyInfo& event) {
44 if (!stashed_tap_down_)
47 stashed_show_press_.reset(new GestureEventWithLatencyInfo(event));
51 bool TouchscreenTapSuppressionController::ShouldSuppressGestureTapEnd() {
52 return controller_->ShouldSuppressTapEnd();
55 #if defined(OS_ANDROID)
56 // TODO(jdduke): Enable ui::GestureConfiguration on Android and initialize
57 // with parameters from ViewConfiguration.
58 int TouchscreenTapSuppressionController::MaxCancelToDownTimeInMs() {
59 return gfx::ViewConfiguration::GetTapTimeoutInMs();
62 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() {
63 return gfx::ViewConfiguration::GetLongPressTimeoutInMs();
66 int TouchscreenTapSuppressionController::MaxCancelToDownTimeInMs() {
67 return ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms();
70 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() {
71 return static_cast<int>(
72 ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000);
76 void TouchscreenTapSuppressionController::DropStashedTapDown() {
77 stashed_tap_down_.reset();
78 stashed_show_press_.reset();
81 void TouchscreenTapSuppressionController::ForwardStashedTapDown() {
82 DCHECK(stashed_tap_down_);
83 ScopedGestureEvent tap_down = stashed_tap_down_.Pass();
84 ScopedGestureEvent show_press = stashed_show_press_.Pass();
85 gesture_event_queue_->ForwardGestureEvent(*tap_down);
87 gesture_event_queue_->ForwardGestureEvent(*show_press);
90 } // namespace content