1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "content/browser/renderer_host/ui_events_helper.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
using blink::WebTouchEvent;
using blink::WebMouseWheelEvent;
namespace content {
SyntheticGestureTargetAura::SyntheticGestureTargetAura(
RenderWidgetHostImpl* host)
: SyntheticGestureTargetBase(host) {
blink::WebScreenInfo screenInfo;
host->GetWebScreenInfo(&screenInfo);
device_scale_factor_ = screenInfo.deviceScaleFactor;
}
void SyntheticGestureTargetAura::DispatchWebTouchEventToPlatform(
const WebTouchEvent& web_touch,
const ui::LatencyInfo& latency_info) {
TouchEventWithLatencyInfo touch_with_latency(web_touch, latency_info);
for (size_t i = 0; i < touch_with_latency.event.touchesLength; i++) {
touch_with_latency.event.touches[i].position.x *= device_scale_factor_;
touch_with_latency.event.touches[i].position.y *= device_scale_factor_;
touch_with_latency.event.touches[i].radiusX *= device_scale_factor_;
touch_with_latency.event.touches[i].radiusY *= device_scale_factor_;
}
ScopedVector<ui::TouchEvent> events;
bool conversion_success = MakeUITouchEventsFromWebTouchEvents(
touch_with_latency, &events, LOCAL_COORDINATES);
DCHECK(conversion_success);
aura::Window* window = GetWindow();
aura::WindowTreeHost* host = window->GetHost();
for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
end = events.end(); iter != end; ++iter) {
(*iter)->ConvertLocationToTarget(window, host->window());
ui::EventDispatchDetails details =
host->event_processor()->OnEventFromSource(*iter);
if (details.dispatcher_destroyed)
break;
}
}
void SyntheticGestureTargetAura::DispatchWebMouseWheelEventToPlatform(
const blink::WebMouseWheelEvent& web_wheel,
const ui::LatencyInfo&) {
ui::MouseEvent mouse_event(ui::ET_MOUSEWHEEL, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
gfx::PointF location(web_wheel.x * device_scale_factor_,
web_wheel.y * device_scale_factor_);
mouse_event.set_location_f(location);
mouse_event.set_root_location_f(location);
ui::MouseWheelEvent wheel_event(
mouse_event, web_wheel.deltaX, web_wheel.deltaY);
aura::Window* window = GetWindow();
wheel_event.ConvertLocationToTarget(window, window->GetRootWindow());
ui::EventDispatchDetails details =
window->GetHost()->event_processor()->OnEventFromSource(&wheel_event);
if (details.dispatcher_destroyed)
return;
}
namespace {
ui::EventType
WebMouseEventTypeToEventType(blink::WebInputEvent::Type web_type) {
switch (web_type) {
case blink::WebInputEvent::MouseDown:
return ui::ET_MOUSE_PRESSED;
case blink::WebInputEvent::MouseUp:
return ui::ET_MOUSE_RELEASED;
case blink::WebInputEvent::MouseMove:
return ui::ET_MOUSE_MOVED;
case blink::WebInputEvent::MouseEnter:
return ui::ET_MOUSE_ENTERED;
case blink::WebInputEvent::MouseLeave:
return ui::ET_MOUSE_EXITED;
case blink::WebInputEvent::ContextMenu:
NOTREACHED() << "WebInputEvent::ContextMenu not supported by"
"SyntheticGestureTargetAura";
default:
NOTREACHED();
}
return ui::ET_UNKNOWN;
}
int WebMouseEventButtonToFlags(blink::WebMouseEvent::Button button) {
switch (button) {
case blink::WebMouseEvent::ButtonLeft:
return ui::EF_LEFT_MOUSE_BUTTON;
case blink::WebMouseEvent::ButtonMiddle:
return ui::EF_MIDDLE_MOUSE_BUTTON;
case blink::WebMouseEvent::ButtonRight:
return ui::EF_RIGHT_MOUSE_BUTTON;
default:
NOTREACHED();
}
return 0;
}
} // namespace
void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
const blink::WebMouseEvent& web_mouse,
const ui::LatencyInfo& latency_info) {
ui::EventType event_type = WebMouseEventTypeToEventType(web_mouse.type);
int flags = WebMouseEventButtonToFlags(web_mouse.button);
ui::MouseEvent mouse_event(event_type, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), flags, flags);
gfx::PointF location(web_mouse.x * device_scale_factor_,
web_mouse.y * device_scale_factor_);
mouse_event.set_location_f(location);
mouse_event.set_root_location_f(location);
aura::Window* window = GetWindow();
mouse_event.ConvertLocationToTarget(window, window->GetRootWindow());
ui::EventDispatchDetails details =
window->GetHost()->event_processor()->OnEventFromSource(&mouse_event);
if (details.dispatcher_destroyed)
return;
}
SyntheticGestureParams::GestureSourceType
SyntheticGestureTargetAura::GetDefaultSyntheticGestureSourceType() const {
return SyntheticGestureParams::TOUCH_INPUT;
}
float SyntheticGestureTargetAura::GetTouchSlopInDips() const {
// - 1 because Aura considers a pointer to be moving if it has moved at least
// 'max_touch_move_in_pixels_for_click' pixels.
return ui::GestureConfiguration::GetInstance()
->max_touch_move_in_pixels_for_click() -
1;
}
float SyntheticGestureTargetAura::GetMinScalingSpanInDips() const {
return ui::GestureConfiguration::GetInstance()
->min_distance_for_pinch_scroll_in_pixels();
}
aura::Window* SyntheticGestureTargetAura::GetWindow() const {
aura::Window* window = render_widget_host()->GetView()->GetNativeView();
DCHECK(window);
return window;
}
} // namespace content
|