| 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 WebKit::WebInputEvent; |
| 14 using WebKit::WebTouchEvent; |
| 15 using WebKit::WebMouseEvent; |
| 16 using WebKit::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 void SyntheticGestureTargetBase::QueueInputEventToPlatform( |
| 33 const InputEvent& event) { |
| 34 const WebInputEvent* web_event = event.web_event.get(); |
| 35 if (WebInputEvent::isTouchEventType(web_event->type)) { |
| 36 DCHECK(SupportsSyntheticGestureSourceType( |
| 37 SyntheticGestureParams::TOUCH_INPUT)); |
| 38 |
| 39 const WebTouchEvent* web_touch = |
| 40 static_cast<const WebTouchEvent*>(web_event); |
| 41 QueueWebTouchEventToPlatform(*web_touch, event.latency_info); |
| 42 } else if (web_event->type == WebInputEvent::MouseWheel) { |
| 43 DCHECK(SupportsSyntheticGestureSourceType( |
| 44 SyntheticGestureParams::MOUSE_INPUT)); |
| 45 |
| 46 const WebMouseWheelEvent* web_wheel = |
| 47 static_cast<const WebMouseWheelEvent*>(web_event); |
| 48 QueueWebMouseWheelEventToPlatform(*web_wheel, event.latency_info); |
| 49 } else if (WebInputEvent::isMouseEventType(web_event->type)) { |
| 50 DCHECK(SupportsSyntheticGestureSourceType( |
| 51 SyntheticGestureParams::MOUSE_INPUT)); |
| 52 |
| 53 const WebMouseEvent* web_mouse = |
| 54 static_cast<const WebMouseEvent*>(web_event); |
| 55 QueueWebMouseEventToPlatform(*web_mouse, event.latency_info); |
| 56 } else |
| 57 NOTREACHED(); |
| 58 } |
| 59 |
| 60 void SyntheticGestureTargetBase::QueueWebTouchEventToPlatform( |
| 61 const WebKit::WebTouchEvent& web_touch, |
| 62 const ui::LatencyInfo& latency_info) { |
| 63 host_->ForwardTouchEventWithLatencyInfo(web_touch, latency_info); |
| 64 } |
| 65 |
| 66 void SyntheticGestureTargetBase::QueueWebMouseWheelEventToPlatform( |
| 67 const WebKit::WebMouseWheelEvent& web_wheel, |
| 68 const ui::LatencyInfo& latency_info) { |
| 69 host_->ForwardWheelEventWithLatencyInfo( |
| 70 MouseWheelEventWithLatencyInfo(web_wheel, latency_info)); |
| 71 } |
| 72 |
| 73 void SyntheticGestureTargetBase::QueueWebMouseEventToPlatform( |
| 74 const WebKit::WebMouseEvent& web_mouse, |
| 75 const ui::LatencyInfo& latency_info) { |
| 76 host_->ForwardMouseEventWithLatencyInfo( |
| 77 MouseEventWithLatencyInfo(web_mouse, latency_info)); |
| 78 } |
| 79 |
| 80 void SyntheticGestureTargetBase::OnSyntheticGestureCompleted( |
| 81 SyntheticGestureNew::Result result) { |
| 82 } |
| 83 |
| 84 base::TimeDelta |
| 85 SyntheticGestureTargetBase::GetSyntheticGestureUpdateRate() const { |
| 86 return base::TimeDelta::FromMilliseconds(kSyntheticGestureMessageIntervalMs); |
| 87 } |
| 88 |
| 89 SyntheticGestureParams::GestureSourceType |
| 90 SyntheticGestureTargetBase::GetDefaultSyntheticGestureSourceType() const { |
| 91 return SyntheticGestureParams::MOUSE_INPUT; |
| 92 } |
| 93 |
| 94 bool SyntheticGestureTargetBase::SupportsSyntheticGestureSourceType( |
| 95 SyntheticGestureParams::GestureSourceType gesture_source_type) const { |
| 96 return gesture_source_type == SyntheticGestureParams::MOUSE_INPUT || |
| 97 gesture_source_type == SyntheticGestureParams::TOUCH_INPUT; |
| 98 } |
| 99 |
| 100 } // namespace content |
| OLD | NEW |