OLD | NEW |
(Empty) | |
| 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/ui_events_helper.h" |
| 9 #include "content/common/input/input_event.h" |
| 10 #include "ui/events/event.h" |
| 11 #include "ui/events/latency_info.h" |
| 12 |
| 13 using blink::WebInputEvent; |
| 14 using blink::WebTouchEvent; |
| 15 using blink::WebMouseEvent; |
| 16 using blink::WebMouseWheelEvent; |
| 17 |
| 18 namespace content { |
| 19 |
| 20 namespace { |
| 21 |
| 22 // How many milliseconds apart synthetic scroll messages should be sent. |
| 23 const int kSyntheticGestureMessageIntervalMs = 16; |
| 24 |
| 25 } // namespace |
| 26 |
| 27 SyntheticGestureTargetBase::SyntheticGestureTargetBase( |
| 28 RenderWidgetHostImpl* host) |
| 29 : host_(host) { |
| 30 } |
| 31 |
| 32 SyntheticGestureTargetBase::~SyntheticGestureTargetBase() { |
| 33 } |
| 34 |
| 35 void SyntheticGestureTargetBase::QueueInputEventToPlatform( |
| 36 const InputEvent& event) { |
| 37 const WebInputEvent* web_event = event.web_event.get(); |
| 38 if (WebInputEvent::isTouchEventType(web_event->type)) { |
| 39 DCHECK(SupportsSyntheticGestureSourceType( |
| 40 SyntheticGestureParams::TOUCH_INPUT)); |
| 41 |
| 42 const WebTouchEvent* web_touch = |
| 43 static_cast<const WebTouchEvent*>(web_event); |
| 44 QueueWebTouchEventToPlatform(*web_touch, event.latency_info); |
| 45 } else if (web_event->type == WebInputEvent::MouseWheel) { |
| 46 DCHECK(SupportsSyntheticGestureSourceType( |
| 47 SyntheticGestureParams::MOUSE_INPUT)); |
| 48 |
| 49 const WebMouseWheelEvent* web_wheel = |
| 50 static_cast<const WebMouseWheelEvent*>(web_event); |
| 51 QueueWebMouseWheelEventToPlatform(*web_wheel, event.latency_info); |
| 52 } else if (WebInputEvent::isMouseEventType(web_event->type)) { |
| 53 DCHECK(SupportsSyntheticGestureSourceType( |
| 54 SyntheticGestureParams::MOUSE_INPUT)); |
| 55 |
| 56 const WebMouseEvent* web_mouse = |
| 57 static_cast<const WebMouseEvent*>(web_event); |
| 58 QueueWebMouseEventToPlatform(*web_mouse, event.latency_info); |
| 59 } else { |
| 60 NOTREACHED(); |
| 61 } |
| 62 } |
| 63 |
| 64 void SyntheticGestureTargetBase::QueueWebTouchEventToPlatform( |
| 65 const blink::WebTouchEvent& web_touch, |
| 66 const ui::LatencyInfo& latency_info) { |
| 67 host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info); |
| 68 } |
| 69 |
| 70 void SyntheticGestureTargetBase::QueueWebMouseWheelEventToPlatform( |
| 71 const blink::WebMouseWheelEvent& web_wheel, |
| 72 const ui::LatencyInfo& latency_info) { |
| 73 host_->ForwardWheelEventWithLatencyInfo( |
| 74 MouseWheelEventWithLatencyInfo(web_wheel, latency_info)); |
| 75 } |
| 76 |
| 77 void SyntheticGestureTargetBase::QueueWebMouseEventToPlatform( |
| 78 const blink::WebMouseEvent& web_mouse, |
| 79 const ui::LatencyInfo& latency_info) { |
| 80 host_->ForwardMouseEventWithLatencyInfo( |
| 81 MouseEventWithLatencyInfo(web_mouse, latency_info)); |
| 82 } |
| 83 |
| 84 void SyntheticGestureTargetBase::OnSyntheticGestureCompleted( |
| 85 SyntheticGestureNew::Result result) { |
| 86 } |
| 87 |
| 88 base::TimeDelta |
| 89 SyntheticGestureTargetBase::GetSyntheticGestureUpdateRate() const { |
| 90 return base::TimeDelta::FromMilliseconds(kSyntheticGestureMessageIntervalMs); |
| 91 } |
| 92 |
| 93 SyntheticGestureParams::GestureSourceType |
| 94 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { |
| 95 return SyntheticGestureParams::MOUSE_INPUT; |
| 96 } |
| 97 |
| 98 bool SyntheticGestureTargetBase::SupportsSyntheticGestureSourceType( |
| 99 SyntheticGestureParams::GestureSourceType gesture_source_type) const { |
| 100 return gesture_source_type == SyntheticGestureParams::MOUSE_INPUT || |
| 101 gesture_source_type == SyntheticGestureParams::TOUCH_INPUT; |
| 102 } |
| 103 |
| 104 } // namespace content |
OLD | NEW |