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/synthetic_gesture_target_base.h"
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"
15 using blink::WebInputEvent;
16 using blink::WebTouchEvent;
17 using blink::WebMouseEvent;
18 using blink::WebMouseWheelEvent;
23 // This value was determined experimentally. It was sufficient to not cause a
25 const int kPointerAssumedStoppedTimeMs = 50;
27 // SyntheticGestureTargetBase passes input events straight on to the renderer
28 // without going through a gesture recognition framework. There is thus no touch
30 const int kTouchSlopInDips = 0;
34 SyntheticGestureTargetBase::SyntheticGestureTargetBase(
35 RenderWidgetHostImpl* host)
40 SyntheticGestureTargetBase::~SyntheticGestureTargetBase() {
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);
48 if (WebInputEvent::isTouchEventType(event.type)) {
49 DCHECK(SupportsSyntheticGestureSourceType(
50 SyntheticGestureParams::TOUCH_INPUT));
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));
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));
66 const WebMouseEvent& web_mouse =
67 static_cast<const WebMouseEvent&>(event);
68 DispatchWebMouseEventToPlatform(web_mouse, latency_info);
74 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform(
75 const blink::WebTouchEvent& web_touch,
76 const ui::LatencyInfo& latency_info) {
77 host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info);
80 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform(
81 const blink::WebMouseWheelEvent& web_wheel,
82 const ui::LatencyInfo& latency_info) {
83 host_->ForwardWheelEventWithLatencyInfo(web_wheel, latency_info);
86 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform(
87 const blink::WebMouseEvent& web_mouse,
88 const ui::LatencyInfo& latency_info) {
89 host_->ForwardMouseEventWithLatencyInfo(web_mouse, latency_info);
92 void SyntheticGestureTargetBase::OnSyntheticGestureCompleted(
93 SyntheticGesture::Result result) {
94 host_->Send(new InputMsg_SyntheticGestureCompleted(host_->GetRoutingID()));
97 void SyntheticGestureTargetBase::SetNeedsFlush() {
98 host_->SetNeedsFlush();
101 SyntheticGestureParams::GestureSourceType
102 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const {
103 return SyntheticGestureParams::MOUSE_INPUT;
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;
112 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime()
114 return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs);
117 int SyntheticGestureTargetBase::GetTouchSlopInDips() const {
118 return kTouchSlopInDips;
121 } // namespace content