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_aura.h" |
| 6 |
| 7 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 8 #include "content/browser/renderer_host/ui_events_helper.h" |
| 9 #include "content/common/input/input_event.h" |
| 10 #include "ui/aura/root_window.h" |
| 11 #include "ui/aura/window.h" |
| 12 |
| 13 using WebKit::WebInputEvent; |
| 14 using WebKit::WebTouchEvent; |
| 15 |
| 16 namespace content { |
| 17 |
| 18 namespace { |
| 19 |
| 20 // How many milliseconds apart synthetic scroll messages should be sent. |
| 21 const int kSyntheticGestureMessageIntervalMs = 7; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 SyntheticGestureTargetAura::SyntheticGestureTargetAura( |
| 26 RenderWidgetHostViewAura* render_view) |
| 27 : render_view_(render_view) { |
| 28 } |
| 29 |
| 30 void SyntheticGestureTargetAura::QueueInputEventToPlatform( |
| 31 const InputEvent& event) { |
| 32 aura::Window* window = render_view_->GetNativeView(); |
| 33 aura::RootWindow* root_window = window->GetRootWindow(); |
| 34 if (!root_window) |
| 35 return; |
| 36 |
| 37 aura::RootWindowHostDelegate* root_window_host_delegate = |
| 38 root_window->AsRootWindowHostDelegate(); |
| 39 |
| 40 const WebInputEvent* web_event = event.web_event.get(); |
| 41 if (WebInputEvent::isTouchEventType(web_event->type)) { |
| 42 ScopedVector<ui::TouchEvent> events; |
| 43 |
| 44 const WebTouchEvent* web_touch = |
| 45 static_cast<const WebTouchEvent*>(web_event); |
| 46 |
| 47 TouchEventWithLatencyInfo touch_with_latency( |
| 48 *web_touch, event.latency_info); |
| 49 |
| 50 // SyntheticGesture may skip calculating screenPosition, so we will fill it |
| 51 // in here. "screenPosition" is converted from "position". |
| 52 const unsigned num_touches = touch_with_latency.event.touchesLength; |
| 53 for (unsigned i = 0; i < num_touches; ++ i) { |
| 54 WebKit::WebTouchPoint* point = &touch_with_latency.event.touches[i]; |
| 55 gfx::Point position(point->position.x, point->position.y); |
| 56 aura::Window::ConvertPointToTarget(window, root_window, &position); |
| 57 root_window->ConvertPointToHost(&position); |
| 58 point->screenPosition.x = position.x(); |
| 59 point->screenPosition.y = position.y(); |
| 60 } |
| 61 |
| 62 if (!MakeUITouchEventsFromWebTouchEvents(touch_with_latency, &events, |
| 63 SCREEN_COORDINATES)) |
| 64 return; |
| 65 |
| 66 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(), |
| 67 end = events.end(); iter != end; ++iter) { |
| 68 root_window_host_delegate->OnHostTouchEvent(*iter); |
| 69 } |
| 70 } else |
| 71 NOTREACHED(); // FIXME: implement other types (MouseWheel?) |
| 72 } |
| 73 |
| 74 void SyntheticGestureTargetAura::OnSyntheticGestureCompleted( |
| 75 SyntheticGestureNew::Result result) { |
| 76 } |
| 77 |
| 78 base::TimeDelta |
| 79 SyntheticGestureTargetAura::GetSyntheticGestureUpdateRate() const { |
| 80 return base::TimeDelta::FromMilliseconds(kSyntheticGestureMessageIntervalMs); |
| 81 } |
| 82 |
| 83 SyntheticGestureParams::GestureSourceType |
| 84 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const { |
| 85 return SyntheticGestureParams::TOUCH_INPUT; |
| 86 } |
| 87 |
| 88 bool SyntheticGestureTargetAura::SupportsSyntheticGestureSourceType( |
| 89 SyntheticGestureParams::GestureSourceType gesture_source_type) const { |
| 90 // FIXME: add support for mouse |
| 91 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT; |
| 92 } |
| 93 |
| 94 } // namespace content |
OLD | NEW |