blob: 5f3854eb333531f2d7ce9653beec1def29308abd (
plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
// Copyright 2015 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 "blimp/net/input_message_converter.h"
#include "base/logging.h"
#include "blimp/common/proto/input.pb.h"
#include "third_party/WebKit/public/platform/WebGestureDevice.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace blimp {
namespace {
scoped_ptr<blink::WebGestureEvent> BuildCommonWebGesture(
const InputMessage& proto,
blink::WebInputEvent::Type type) {
scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
event->type = type;
event->timeStampSeconds = proto.timestamp_seconds();
const GestureCommon& common = proto.gesture_common();
event->x = common.x();
event->y = common.y();
event->globalX = common.global_x();
event->globalY = common.global_y();
event->sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchscreen;
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureScrollBegin(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureScrollBegin));
const GestureScrollBegin& details = proto.gesture_scroll_begin();
event->data.scrollBegin.deltaXHint = details.delta_x_hint();
event->data.scrollBegin.deltaYHint = details.delta_y_hint();
event->data.scrollBegin.targetViewport = details.target_viewport();
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureScrollEnd(
const InputMessage& proto) {
return BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureScrollEnd);
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureScrollUpdate(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureScrollUpdate));
const GestureScrollUpdate& details = proto.gesture_scroll_update();
event->data.scrollUpdate.deltaX = details.delta_x();
event->data.scrollUpdate.deltaY = details.delta_y();
event->data.scrollUpdate.velocityX = details.velocity_x();
event->data.scrollUpdate.velocityY = details.velocity_y();
event->data.scrollUpdate.previousUpdateInSequencePrevented =
details.previous_update_in_sequence_prevented();
event->data.scrollUpdate.preventPropagation = details.prevent_propagation();
event->data.scrollUpdate.inertial = details.inertial();
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureFlingStart(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureFlingStart));
const GestureFlingStart& details = proto.gesture_fling_start();
event->data.flingStart.velocityX = details.velocity_x();
event->data.flingStart.velocityY = details.velocity_y();
event->data.flingStart.targetViewport = details.target_viewport();
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureFlingCancel(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureFlingCancel));
const GestureFlingCancel& details = proto.gesture_fling_cancel();
event->data.flingCancel.preventBoosting = details.prevent_boosting();
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGestureTap(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GestureTap));
const GestureTap& details = proto.gesture_tap();
event->data.tap.tapCount = details.tap_count();
event->data.tap.width = details.width();
event->data.tap.height = details.height();
return event;
}
scoped_ptr<blink::WebGestureEvent> ProtoToGesturePinchBegin(
const InputMessage& proto) {
return BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GesturePinchBegin);
}
scoped_ptr<blink::WebGestureEvent> ProtoToGesturePinchEnd(
const InputMessage& proto) {
return BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GesturePinchEnd);
}
scoped_ptr<blink::WebGestureEvent> ProtoToGesturePinchUpdate(
const InputMessage& proto) {
scoped_ptr<blink::WebGestureEvent> event(
BuildCommonWebGesture(proto,
blink::WebInputEvent::Type::GesturePinchUpdate));
const GesturePinchUpdate& details = proto.gesture_pinch_update();
event->data.pinchUpdate.zoomDisabled = details.zoom_disabled();
event->data.pinchUpdate.scale = details.scale();
return event;
}
} // namespace
InputMessageConverter::InputMessageConverter() {}
InputMessageConverter::~InputMessageConverter() {}
scoped_ptr<blink::WebGestureEvent> InputMessageConverter::ProcessMessage(
const InputMessage& message) {
scoped_ptr<blink::WebGestureEvent> event;
switch (message.type()) {
case InputMessage::Type_GestureScrollBegin:
event = ProtoToGestureScrollBegin(message);
break;
case InputMessage::Type_GestureScrollEnd:
event = ProtoToGestureScrollEnd(message);
break;
case InputMessage::Type_GestureScrollUpdate:
event = ProtoToGestureScrollUpdate(message);
break;
case InputMessage::Type_GestureFlingStart:
event = ProtoToGestureFlingStart(message);
break;
case InputMessage::Type_GestureFlingCancel:
event = ProtoToGestureFlingCancel(message);
break;
case InputMessage::Type_GestureTap:
event = ProtoToGestureTap(message);
break;
case InputMessage::Type_GesturePinchBegin:
event = ProtoToGesturePinchBegin(message);
break;
case InputMessage::Type_GesturePinchEnd:
event = ProtoToGesturePinchEnd(message);
break;
case InputMessage::Type_GesturePinchUpdate:
event = ProtoToGesturePinchUpdate(message);
break;
case InputMessage::UNKNOWN:
DLOG(FATAL) << "Received an InputMessage with an unknown type.";
return nullptr;
}
return event;
}
ui::TextInputType InputMessageConverter::TextInputTypeFromProto(
ImeMessage_InputType type) {
switch (type) {
case ImeMessage_InputType_NONE:
return ui::TEXT_INPUT_TYPE_NONE;
case ImeMessage_InputType_TEXT:
return ui::TEXT_INPUT_TYPE_TEXT;
case ImeMessage_InputType_PASSWORD:
return ui::TEXT_INPUT_TYPE_PASSWORD;
case ImeMessage_InputType_SEARCH:
return ui::TEXT_INPUT_TYPE_SEARCH;
case ImeMessage_InputType_EMAIL:
return ui::TEXT_INPUT_TYPE_EMAIL;
case ImeMessage_InputType_NUMBER:
return ui::TEXT_INPUT_TYPE_NUMBER;
case ImeMessage_InputType_TELEPHONE:
return ui::TEXT_INPUT_TYPE_TELEPHONE;
case ImeMessage_InputType_URL:
return ui::TEXT_INPUT_TYPE_URL;
case ImeMessage_InputType_DATE:
return ui::TEXT_INPUT_TYPE_DATE;
case ImeMessage_InputType_DATE_TIME:
return ui::TEXT_INPUT_TYPE_DATE_TIME;
case ImeMessage_InputType_DATE_TIME_LOCAL:
return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL;
case ImeMessage_InputType_MONTH:
return ui::TEXT_INPUT_TYPE_MONTH;
case ImeMessage_InputType_TIME:
return ui::TEXT_INPUT_TYPE_TIME;
case ImeMessage_InputType_WEEK:
return ui::TEXT_INPUT_TYPE_WEEK;
case ImeMessage_InputType_TEXT_AREA:
return ui::TEXT_INPUT_TYPE_TEXT_AREA;
case ImeMessage_InputType_CONTENT_EDITABLE:
return ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE;
case ImeMessage_InputType_DATE_TIME_FIELD:
return ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD;
}
return ui::TEXT_INPUT_TYPE_NONE;
}
ImeMessage_InputType InputMessageConverter::TextInputTypeToProto(
ui::TextInputType type) {
switch (type) {
case ui::TEXT_INPUT_TYPE_NONE:
NOTREACHED() << "IME needs an editable TextInputType";
return ImeMessage_InputType_NONE;
case ui::TEXT_INPUT_TYPE_TEXT:
return ImeMessage_InputType_TEXT;
case ui::TEXT_INPUT_TYPE_PASSWORD:
return ImeMessage_InputType_PASSWORD;
case ui::TEXT_INPUT_TYPE_SEARCH:
return ImeMessage_InputType_SEARCH;
case ui::TEXT_INPUT_TYPE_EMAIL:
return ImeMessage_InputType_EMAIL;
case ui::TEXT_INPUT_TYPE_NUMBER:
return ImeMessage_InputType_NUMBER;
case ui::TEXT_INPUT_TYPE_TELEPHONE:
return ImeMessage_InputType_TELEPHONE;
case ui::TEXT_INPUT_TYPE_URL:
return ImeMessage_InputType_URL;
case ui::TEXT_INPUT_TYPE_DATE:
return ImeMessage_InputType_DATE;
case ui::TEXT_INPUT_TYPE_DATE_TIME:
return ImeMessage_InputType_DATE_TIME;
case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
return ImeMessage_InputType_DATE_TIME_LOCAL;
case ui::TEXT_INPUT_TYPE_MONTH:
return ImeMessage_InputType_MONTH;
case ui::TEXT_INPUT_TYPE_TIME:
return ImeMessage_InputType_TIME;
case ui::TEXT_INPUT_TYPE_WEEK:
return ImeMessage_InputType_WEEK;
case ui::TEXT_INPUT_TYPE_TEXT_AREA:
return ImeMessage_InputType_TEXT_AREA;
case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
return ImeMessage_InputType_CONTENT_EDITABLE;
case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
return ImeMessage_InputType_DATE_TIME_FIELD;
}
return ImeMessage_InputType_NONE;
}
} // namespace blimp
|