Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_target_aura.cc
blob8bcda99627d4502ce2cb292e91cdfb56be0069bf
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 "third_party/WebKit/public/platform/WebScreenInfo.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_tree_host.h"
13 #include "ui/events/event_processor.h"
14 #include "ui/events/event_utils.h"
15 #include "ui/events/gesture_detection/gesture_configuration.h"
17 using blink::WebTouchEvent;
18 using blink::WebMouseWheelEvent;
20 namespace content {
22 SyntheticGestureTargetAura::SyntheticGestureTargetAura(
23 RenderWidgetHostImpl* host)
24 : SyntheticGestureTargetBase(host) {
25 blink::WebScreenInfo screenInfo;
26 host->GetWebScreenInfo(&screenInfo);
27 device_scale_factor_ = screenInfo.deviceScaleFactor;
30 void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
31 const WebTouchEvent& web_touch,
32 const ui::LatencyInfo& latency_info) {
33 TouchEventWithLatencyInfo touch_with_latency(web_touch, latency_info);
34 for (size_t i = 0; i < touch_with_latency.event.touchesLength; i++) {
35 touch_with_latency.event.touches[i].position.x *= device_scale_factor_;
36 touch_with_latency.event.touches[i].position.y *= device_scale_factor_;
37 touch_with_latency.event.touches[i].radiusX *= device_scale_factor_;
38 touch_with_latency.event.touches[i].radiusY *= device_scale_factor_;
40 ScopedVector<ui::TouchEvent> events;
41 bool conversion_success = MakeUITouchEventsFromWebTouchEvents(
42 touch_with_latency, &events, LOCAL_COORDINATES);
43 DCHECK(conversion_success);
45 aura::Window* window = GetWindow();
46 aura::WindowTreeHost* host = window->GetHost();
47 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
48 end = events.end(); iter != end; ++iter) {
49 (*iter)->ConvertLocationToTarget(window, host->window());
50 ui::EventDispatchDetails details =
51 host->event_processor()->OnEventFromSource(*iter);
52 if (details.dispatcher_destroyed)
53 break;
57 void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
58 const blink::WebMouseWheelEvent& web_wheel,
59 const ui::LatencyInfo&) {
60 gfx::PointF location(web_wheel.x * device_scale_factor_,
61 web_wheel.y * device_scale_factor_);
62 ui::MouseEvent mouse_event(ui::ET_MOUSEWHEEL, location, location,
63 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
64 ui::MouseWheelEvent wheel_event(
65 mouse_event, web_wheel.deltaX, web_wheel.deltaY);
67 aura::Window* window = GetWindow();
68 wheel_event.ConvertLocationToTarget(window, window->GetRootWindow());
69 ui::EventDispatchDetails details =
70 window->GetHost()->event_processor()->OnEventFromSource(&wheel_event);
71 if (details.dispatcher_destroyed)
72 return;
75 namespace {
77 ui::EventType
78 WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type) {
79 switch (web_type) {
80 case blink::WebInputEvent::MouseDown:
81 return ui::ET_MOUSE_PRESSED;
83 case blink::WebInputEvent::MouseUp:
84 return ui::ET_MOUSE_RELEASED;
86 case blink::WebInputEvent::MouseMove:
87 return ui::ET_MOUSE_MOVED;
89 case blink::WebInputEvent::MouseEnter:
90 return ui::ET_MOUSE_ENTERED;
92 case blink::WebInputEvent::MouseLeave:
93 return ui::ET_MOUSE_EXITED;
95 case blink::WebInputEvent::ContextMenu:
96 NOTREACHED() << "WebInputEvent::ContextMenu not supported by"
97 "SyntheticGestureTargetAura";
99 default:
100 NOTREACHED();
103 return ui::ET_UNKNOWN;
106 int WebMouseEventButtonToFlags(blink::WebMouseEvent::Button button) {
107 switch (button) {
108 case blink::WebMouseEvent::ButtonLeft:
109 return ui::EF_LEFT_MOUSE_BUTTON;
111 case blink::WebMouseEvent::ButtonMiddle:
112 return ui::EF_MIDDLE_MOUSE_BUTTON;
114 case blink::WebMouseEvent::ButtonRight:
115 return ui::EF_RIGHT_MOUSE_BUTTON;
117 default:
118 NOTREACHED();
121 return 0;
124 } // namespace
126 void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
127 const blink::WebMouseEvent& web_mouse,
128 const ui::LatencyInfo& latency_info) {
129 gfx::PointF location(web_mouse.x * device_scale_factor_,
130 web_mouse.y * device_scale_factor_);
131 ui::EventType event_type = WebMouseEventTypeToEventType(web_mouse.type);
132 int flags = WebMouseEventButtonToFlags(web_mouse.button);
133 ui::MouseEvent mouse_event(event_type, location, location,
134 ui::EventTimeForNow(), flags, flags);
136 aura::Window* window = GetWindow();
137 mouse_event.ConvertLocationToTarget(window, window->GetRootWindow());
138 ui::EventDispatchDetails details =
139 window->GetHost()->event_processor()->OnEventFromSource(&mouse_event);
140 if (details.dispatcher_destroyed)
141 return;
144 SyntheticGestureParams::GestureSourceType
145 SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const {
146 return SyntheticGestureParams::TOUCH_INPUT;
149 float SyntheticGestureTargetAura::GetTouchSlopInDips() const {
150 // - 1 because Aura considers a pointer to be moving if it has moved at least
151 // 'max_touch_move_in_pixels_for_click' pixels.
152 return ui::GestureConfiguration::GetInstance()
153 ->max_touch_move_in_pixels_for_click() -
157 float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const {
158 return ui::GestureConfiguration::GetInstance()
159 ->min_distance_for_pinch_scroll_in_pixels();
162 aura::Window* SyntheticGestureTargetAura::GetWindow() const {
163 aura::Window* window = render_widget_host()->GetView()->GetNativeView();
164 DCHECK(window);
165 return window;
168 } // namespace content