IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_target_aura.cc
blobb234666d1d2388ed3ada56339504ca4f36db7e1e
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_aura.h"
7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "content/browser/renderer_host/ui_events_helper.h"
10 #include "content/common/input/input_event.h"
11 #include "ui/aura/client/screen_position_client.h"
12 #include "ui/aura/root_window.h"
13 #include "ui/aura/window.h"
14 #include "ui/events/gestures/gesture_configuration.h"
16 using blink::WebTouchEvent;
17 using blink::WebMouseWheelEvent;
19 namespace content {
21 SyntheticGestureTargetAura::SyntheticGestureTargetAura(
22 RenderWidgetHostImpl* host)
23 : SyntheticGestureTargetBase(host) {
26 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
27 const WebTouchEvent& web_touch,
28 const ui::LatencyInfo& latency_info) {
29 aura::Window* window = GetWindow();
30 aura::client::ScreenPositionClient* position_client =
31 GetScreenPositionClient();
33 TouchEventWithLatencyInfo touch_with_latency(web_touch, latency_info);
35 // SyntheticGesture may skip calculating screenPosition, so we will fill it
36 // in here. "screenPosition" is converted from "position".
37 const size_t num_touches = touch_with_latency.event.touchesLength;
38 for (size_t i = 0; i < num_touches; ++ i) {
39 blink::WebTouchPoint* point = &touch_with_latency.event.touches[i];
40 gfx::Point position(point->position.x, point->position.y);
41 position_client->ConvertPointToScreen(window, &position);
42 point->screenPosition.x = position.x();
43 point->screenPosition.y = position.y();
46 ScopedVector<ui::TouchEvent> events;
47 bool conversion_success = MakeUITouchEventsFromWebTouchEvents(
48 touch_with_latency, &events, SCREEN_COORDINATES);
49 DCHECK(conversion_success);
51 aura::WindowTreeHostDelegate* root_window_host_delegate =
52 GetWindowTreeHostDelegate();
53 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
54 end = events.end(); iter != end; ++iter) {
55 root_window_host_delegate->OnHostTouchEvent(*iter);
59 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
60 const blink::WebMouseWheelEvent& web_wheel,
61 const ui::LatencyInfo&) {
62 aura::Window* window = GetWindow();
63 aura::client::ScreenPositionClient* position_client =
64 GetScreenPositionClient();
65 gfx::Point location(web_wheel.x, web_wheel.y);
66 position_client->ConvertPointToScreen(window, &location);
68 ui::MouseEvent mouse_event(
69 ui::ET_MOUSEWHEEL, location, location, ui::EF_NONE, ui::EF_NONE);
70 ui::MouseWheelEvent wheel_event(
71 mouse_event, web_wheel.deltaX, web_wheel.deltaY);
73 GetWindowTreeHostDelegate()->OnHostMouseEvent(&wheel_event);
76 namespace {
78 ui::EventType
79 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type) {
80 switch (web_type) {
81 case blink::WebInputEvent::MouseDown:
82 return ui::ET_MOUSE_PRESSED;
84 case blink::WebInputEvent::MouseUp:
85 return ui::ET_MOUSE_RELEASED;
87 case blink::WebInputEvent::MouseMove:
88 return ui::ET_MOUSE_MOVED;
90 case blink::WebInputEvent::MouseEnter:
91 return ui::ET_MOUSE_ENTERED;
93 case blink::WebInputEvent::MouseLeave:
94 return ui::ET_MOUSE_EXITED;
96 case blink::WebInputEvent::ContextMenu:
97 NOTREACHED() << "WebInputEvent::ContextMenu not supported by"
98 "SyntheticGestureTargetAura";
100 default:
101 NOTREACHED();
104 return ui::ET_UNKNOWN;
107 int WebMouseEventButtonToFlags(blink::WebMouseEvent::Button button) {
108 switch (button) {
109 case blink::WebMouseEvent::ButtonLeft:
110 return ui::EF_LEFT_MOUSE_BUTTON;
112 case blink::WebMouseEvent::ButtonMiddle:
113 return ui::EF_MIDDLE_MOUSE_BUTTON;
115 case blink::WebMouseEvent::ButtonRight:
116 return ui::EF_RIGHT_MOUSE_BUTTON;
118 default:
119 NOTREACHED();
122 return 0;
125 } // namespace
127 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
128 const blink::WebMouseEvent& web_mouse,
129 const ui::LatencyInfo& latency_info) {
130 aura::Window* window = GetWindow();
131 aura::client::ScreenPositionClient* position_client =
132 GetScreenPositionClient();
133 gfx::Point location(web_mouse.x, web_mouse.y);
134 position_client->ConvertPointToScreen(window, &location);
136 ui::EventType event_type = WebMouseEventTypeToEventType(web_mouse.type);
137 int flags = WebMouseEventButtonToFlags(web_mouse.button);
138 ui::MouseEvent mouse_event(event_type, location, location, flags, flags);
140 GetWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_event);
143 SyntheticGestureParams::GestureSourceType
144 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const {
145 return SyntheticGestureParams::MOUSE_INPUT;
148 bool SyntheticGestureTargetAura::SupportsSyntheticGestureSourceType(
149 SyntheticGestureParams::GestureSourceType gesture_source_type) const {
150 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT ||
151 gesture_source_type == SyntheticGestureParams::MOUSE_INPUT;
154 int SyntheticGestureTargetAura::GetTouchSlopInDips() const {
155 // - 1 because Aura considers a pointer to be moving if it has moved at least
156 // 'max_touch_move_in_pixels_for_click' pixels.
157 return ui::GestureConfiguration::max_touch_move_in_pixels_for_click() - 1;
160 aura::Window* SyntheticGestureTargetAura::GetWindow() const {
161 aura::Window* window = render_widget_host()->GetView()->GetNativeView();
162 DCHECK(window);
163 return window;
166 aura::WindowTreeHostDelegate*
167 SyntheticGestureTargetAura::GetWindowTreeHostDelegate() const {
168 aura::Window* root_window = GetWindow()->GetRootWindow();
169 aura::WindowTreeHostDelegate* root_window_host_delegate =
170 root_window->GetDispatcher()->AsWindowTreeHostDelegate();
171 DCHECK(root_window_host_delegate);
172 return root_window_host_delegate;
175 aura::client::ScreenPositionClient*
176 SyntheticGestureTargetAura::GetScreenPositionClient() const {
177 aura::Window* root_window = GetWindow()->GetRootWindow();
178 aura::client::ScreenPositionClient* position_client =
179 aura::client::GetScreenPositionClient(root_window);
180 DCHECK(position_client);
181 return position_client;
184 } // namespace content