c9879f634c39a3ae4d5b60d2ab6808ba71984168
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / input / synthetic_gesture_target_base.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/synthetic_gesture_target_base.h"
6
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/browser/renderer_host/ui_events_helper.h"
10 #include "content/common/input_messages.h"
11 #include "third_party/WebKit/public/web/WebInputEvent.h"
12 #include "ui/events/event.h"
13 #include "ui/events/latency_info.h"
14
15 using blink::WebInputEvent;
16 using blink::WebTouchEvent;
17 using blink::WebMouseEvent;
18 using blink::WebMouseWheelEvent;
19
20 namespace content {
21 namespace {
22
23 // This value was determined experimentally. It was sufficient to not cause a
24 // fling on Android.
25 const int kPointerAssumedStoppedTimeMs = 50;
26
27 // SyntheticGestureTargetBase passes input events straight on to the renderer
28 // without going through a gesture recognition framework. There is thus no touch
29 // slop.
30 const int kTouchSlopInDips = 0;
31
32 }  // namespace
33
34 SyntheticGestureTargetBase::SyntheticGestureTargetBase(
35     RenderWidgetHostImpl* host)
36     : host_(host) {
37   DCHECK(host);
38 }
39
40 SyntheticGestureTargetBase::~SyntheticGestureTargetBase() {
41 }
42
43 void SyntheticGestureTargetBase::DispatchInputEventToPlatform(
44     const WebInputEvent& event) {
45   ui::LatencyInfo latency_info;
46   latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
47
48   if (WebInputEvent::isTouchEventType(event.type)) {
49     DCHECK(SupportsSyntheticGestureSourceType(
50             SyntheticGestureParams::TOUCH_INPUT));
51
52     const WebTouchEvent& web_touch =
53         static_cast<const WebTouchEvent&>(event);
54     DispatchWebTouchEventToPlatform(web_touch, latency_info);
55   } else if (event.type == WebInputEvent::MouseWheel) {
56     DCHECK(SupportsSyntheticGestureSourceType(
57             SyntheticGestureParams::MOUSE_INPUT));
58
59     const WebMouseWheelEvent& web_wheel =
60         static_cast<const WebMouseWheelEvent&>(event);
61     DispatchWebMouseWheelEventToPlatform(web_wheel, latency_info);
62   } else if (WebInputEvent::isMouseEventType(event.type)) {
63     DCHECK(SupportsSyntheticGestureSourceType(
64             SyntheticGestureParams::MOUSE_INPUT));
65
66     const WebMouseEvent& web_mouse =
67         static_cast<const WebMouseEvent&>(event);
68     DispatchWebMouseEventToPlatform(web_mouse, latency_info);
69   } else {
70     NOTREACHED();
71   }
72 }
73
74 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform(
75       const blink::WebTouchEvent& web_touch,
76       const ui::LatencyInfo& latency_info) {
77   host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info);
78 }
79
80 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform(
81       const blink::WebMouseWheelEvent& web_wheel,
82       const ui::LatencyInfo& latency_info) {
83   host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info);
84 }
85
86 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform(
87       const blink::WebMouseEvent& web_mouse,
88       const ui::LatencyInfo& latency_info) {
89   host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info);
90 }
91
92 void SyntheticGestureTargetBase::OnSyntheticGestureCompleted(
93     SyntheticGesture::Result result) {
94   host_->Send(new InputMsg_SyntheticGestureCompleted(host_->GetRoutingID()));
95 }
96
97 void SyntheticGestureTargetBase::SetNeedsFlush() {
98   host_->SetNeedsFlush();
99 }
100
101 SyntheticGestureParams::GestureSourceType
102 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const {
103   return SyntheticGestureParams::MOUSE_INPUT;
104 }
105
106 bool SyntheticGestureTargetBase::SupportsSyntheticGestureSourceType(
107     SyntheticGestureParams::GestureSourceType gesture_source_type) const {
108   return gesture_source_type == SyntheticGestureParams::MOUSE_INPUT ||
109       gesture_source_type == SyntheticGestureParams::TOUCH_INPUT;
110 }
111
112 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime()
113     const {
114   return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs);
115 }
116
117 int SyntheticGestureTargetBase::GetTouchSlopInDips() const {
118   return kTouchSlopInDips;
119 }
120
121 }  // namespace content