Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / input / touchscreen_tap_suppression_controller.cc
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.
4
5 #include "content/browser/renderer_host/input/touchscreen_tap_suppression_controller.h"
6
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
15 namespace content {
16
17 TouchscreenTapSuppressionController::TouchscreenTapSuppressionController(
18     GestureEventQueue* geq)
19     : gesture_event_queue_(geq),
20       controller_(new TapSuppressionController(this)) {
21 }
22
23 TouchscreenTapSuppressionController::~TouchscreenTapSuppressionController() {}
24
25 void TouchscreenTapSuppressionController::GestureFlingCancel() {
26   controller_->GestureFlingCancel();
27 }
28
29 void TouchscreenTapSuppressionController::GestureFlingCancelAck(
30     bool processed) {
31   controller_->GestureFlingCancelAck(processed);
32 }
33
34 bool TouchscreenTapSuppressionController::ShouldDeferGestureTapDown(
35     const GestureEventWithLatencyInfo& event) {
36   bool should_defer = controller_->ShouldDeferTapDown();
37   if (should_defer)
38     stashed_tap_down_.reset(new GestureEventWithLatencyInfo(event));
39   return should_defer;
40 }
41
42 bool TouchscreenTapSuppressionController::ShouldDeferGestureShowPress(
43     const GestureEventWithLatencyInfo& event) {
44   if (!stashed_tap_down_)
45     return false;
46
47   stashed_show_press_.reset(new GestureEventWithLatencyInfo(event));
48   return true;
49 }
50
51 bool TouchscreenTapSuppressionController::ShouldSuppressGestureTapEnd() {
52   return controller_->ShouldSuppressTapEnd();
53 }
54
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();
60 }
61
62 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() {
63   return gfx::ViewConfiguration::GetLongPressTimeoutInMs();
64 }
65 #else
66 int TouchscreenTapSuppressionController::MaxCancelToDownTimeInMs() {
67   return ui::GestureConfiguration::fling_max_cancel_to_down_time_in_ms();
68 }
69
70 int TouchscreenTapSuppressionController::MaxTapGapTimeInMs() {
71   return static_cast<int>(
72       ui::GestureConfiguration::semi_long_press_time_in_seconds() * 1000);
73 }
74 #endif
75
76 void TouchscreenTapSuppressionController::DropStashedTapDown() {
77   stashed_tap_down_.reset();
78   stashed_show_press_.reset();
79 }
80
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);
86   if (show_press)
87     gesture_event_queue_->ForwardGestureEvent(*show_press);
88 }
89
90 }  // namespace content