IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_target_base.cc
blob0938eebb64978e2dec98d61d065625d0b9460b2c
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/input_event.h"
11 #include "content/common/input_messages.h"
12 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 #include "ui/events/event.h"
14 #include "ui/events/latency_info.h"
16 using blink::WebInputEvent;
17 using blink::WebTouchEvent;
18 using blink::WebMouseEvent;
19 using blink::WebMouseWheelEvent;
21 namespace content {
22 namespace {
24 // This value was determined experimentally. It was sufficient to not cause a
25 // fling on Android.
26 const int kPointerAssumedStoppedTimeMs = 50;
28 // SyntheticGestureTargetBase passes input events straight on to the renderer
29 // without going through a gesture recognition framework. There is thus no touch
30 // slop.
31 const int kTouchSlopInDips = 0;
33 } // namespace
35 SyntheticGestureTargetBase::SyntheticGestureTargetBase(
36 RenderWidgetHostImpl* host)
37 : host_(host) {
38 DCHECK(host);
41 SyntheticGestureTargetBase::~SyntheticGestureTargetBase() {
44 void SyntheticGestureTargetBase::DispatchInputEventToPlatform(
45 const InputEvent& event) {
46 const WebInputEvent* web_event = event.web_event.get();
47 if (WebInputEvent::isTouchEventType(web_event->type)) {
48 DCHECK(SupportsSyntheticGestureSourceType(
49 SyntheticGestureParams::TOUCH_INPUT));
51 const WebTouchEvent* web_touch =
52 static_cast<const WebTouchEvent*>(web_event);
53 DispatchWebTouchEventToPlatform(*web_touch, event.latency_info);
54 } else if (web_event->type == WebInputEvent::MouseWheel) {
55 DCHECK(SupportsSyntheticGestureSourceType(
56 SyntheticGestureParams::MOUSE_INPUT));
58 const WebMouseWheelEvent* web_wheel =
59 static_cast<const WebMouseWheelEvent*>(web_event);
60 DispatchWebMouseWheelEventToPlatform(*web_wheel, event.latency_info);
61 } else if (WebInputEvent::isMouseEventType(web_event->type)) {
62 DCHECK(SupportsSyntheticGestureSourceType(
63 SyntheticGestureParams::MOUSE_INPUT));
65 const WebMouseEvent* web_mouse =
66 static_cast<const WebMouseEvent*>(web_event);
67 DispatchWebMouseEventToPlatform(*web_mouse, event.latency_info);
68 } else {
69 NOTREACHED();
73 void SyntheticGestureTargetBase::DispatchWebTouchEventToPlatform(
74 const blink::WebTouchEvent& web_touch,
75 const ui::LatencyInfo& latency_info) {
76 host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info);
79 void SyntheticGestureTargetBase::DispatchWebMouseWheelEventToPlatform(
80 const blink::WebMouseWheelEvent& web_wheel,
81 const ui::LatencyInfo& latency_info) {
82 host_->ForwardWheelEventWithLatencyInfo(
83 MouseWheelEventWithLatencyInfo(web_wheel, latency_info));
86 void SyntheticGestureTargetBase::DispatchWebMouseEventToPlatform(
87 const blink::WebMouseEvent& web_mouse,
88 const ui::LatencyInfo& latency_info) {
89 host_->ForwardMouseEventWithLatencyInfo(
90 MouseEventWithLatencyInfo(web_mouse, latency_info));
93 void SyntheticGestureTargetBase::OnSyntheticGestureCompleted(
94 SyntheticGesture::Result result) {
95 host_->Send(new InputMsg_SyntheticGestureCompleted(host_->GetRoutingID()));
98 void SyntheticGestureTargetBase::SetNeedsFlush() {
99 host_->SetNeedsFlush();
102 SyntheticGestureParams::GestureSourceType
103 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const {
104 return SyntheticGestureParams::MOUSE_INPUT;
107 bool SyntheticGestureTargetBase::SupportsSyntheticGestureSourceType(
108 SyntheticGestureParams::GestureSourceType gesture_source_type) const {
109 return gesture_source_type == SyntheticGestureParams::MOUSE_INPUT ||
110 gesture_source_type == SyntheticGestureParams::TOUCH_INPUT;
113 base::TimeDelta SyntheticGestureTargetBase::PointerAssumedStoppedTime()
114 const {
115 return base::TimeDelta::FromMilliseconds(kPointerAssumedStoppedTimeMs);
118 int SyntheticGestureTargetBase::GetTouchSlopInDips() const {
119 return kTouchSlopInDips;
122 } // namespace content