Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: blimp/net/input_message_converter.cc

Issue 2632803002: Remove all blimp network code. (Closed)
Patch Set: merge from origin/master for good measure Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/net/input_message_converter.h ('k') | blimp/net/input_message_generator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "blimp/net/input_message_converter.h"
6
7 #include "base/logging.h"
8 #include "blimp/common/proto/input.pb.h"
9 #include "third_party/WebKit/public/platform/WebGestureDevice.h"
10 #include "third_party/WebKit/public/platform/WebGestureEvent.h"
11
12 namespace blimp {
13 namespace {
14
15 std::unique_ptr<blink::WebGestureEvent> BuildCommonWebGesture(
16 const InputMessage& proto,
17 blink::WebInputEvent::Type type) {
18 std::unique_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent(
19 type, blink::WebInputEvent::NoModifiers, proto.timestamp_seconds()));
20
21 const GestureCommon& common = proto.gesture_common();
22 event->x = common.x();
23 event->y = common.y();
24 event->globalX = common.global_x();
25 event->globalY = common.global_y();
26 event->sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchscreen;
27 return event;
28 }
29
30 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureScrollBegin(
31 const InputMessage& proto) {
32 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
33 proto, blink::WebInputEvent::Type::GestureScrollBegin));
34
35 const GestureScrollBegin& details = proto.gesture_scroll_begin();
36 event->data.scrollBegin.deltaXHint = details.delta_x_hint();
37 event->data.scrollBegin.deltaYHint = details.delta_y_hint();
38 event->data.scrollBegin.targetViewport = details.target_viewport();
39
40 return event;
41 }
42
43 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureScrollEnd(
44 const InputMessage& proto) {
45 return BuildCommonWebGesture(proto,
46 blink::WebInputEvent::Type::GestureScrollEnd);
47 }
48
49 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureScrollUpdate(
50 const InputMessage& proto) {
51 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
52 proto, blink::WebInputEvent::Type::GestureScrollUpdate));
53
54 const GestureScrollUpdate& details = proto.gesture_scroll_update();
55 event->data.scrollUpdate.deltaX = details.delta_x();
56 event->data.scrollUpdate.deltaY = details.delta_y();
57 event->data.scrollUpdate.velocityX = details.velocity_x();
58 event->data.scrollUpdate.velocityY = details.velocity_y();
59 event->data.scrollUpdate.previousUpdateInSequencePrevented =
60 details.previous_update_in_sequence_prevented();
61 event->data.scrollUpdate.preventPropagation = details.prevent_propagation();
62 event->data.scrollUpdate.inertialPhase =
63 details.inertial() ? blink::WebGestureEvent::MomentumPhase
64 : blink::WebGestureEvent::UnknownMomentumPhase;
65
66 return event;
67 }
68
69 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureFlingStart(
70 const InputMessage& proto) {
71 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
72 proto, blink::WebInputEvent::Type::GestureFlingStart));
73
74 const GestureFlingStart& details = proto.gesture_fling_start();
75 event->data.flingStart.velocityX = details.velocity_x();
76 event->data.flingStart.velocityY = details.velocity_y();
77 event->data.flingStart.targetViewport = details.target_viewport();
78
79 return event;
80 }
81
82 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureFlingCancel(
83 const InputMessage& proto) {
84 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
85 proto, blink::WebInputEvent::Type::GestureFlingCancel));
86
87 const GestureFlingCancel& details = proto.gesture_fling_cancel();
88 event->data.flingCancel.preventBoosting = details.prevent_boosting();
89
90 return event;
91 }
92
93 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureTap(
94 const InputMessage& proto) {
95 std::unique_ptr<blink::WebGestureEvent> event(
96 BuildCommonWebGesture(proto, blink::WebInputEvent::Type::GestureTap));
97
98 const GestureTap& details = proto.gesture_tap();
99 event->data.tap.tapCount = details.tap_count();
100 event->data.tap.width = details.width();
101 event->data.tap.height = details.height();
102
103 return event;
104 }
105
106 std::unique_ptr<blink::WebGestureEvent> ProtoToGesturePinchBegin(
107 const InputMessage& proto) {
108 return BuildCommonWebGesture(proto,
109 blink::WebInputEvent::Type::GesturePinchBegin);
110 }
111
112 std::unique_ptr<blink::WebGestureEvent> ProtoToGesturePinchEnd(
113 const InputMessage& proto) {
114 return BuildCommonWebGesture(proto,
115 blink::WebInputEvent::Type::GesturePinchEnd);
116 }
117
118 std::unique_ptr<blink::WebGestureEvent> ProtoToGesturePinchUpdate(
119 const InputMessage& proto) {
120 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
121 proto, blink::WebInputEvent::Type::GesturePinchUpdate));
122
123 const GesturePinchUpdate& details = proto.gesture_pinch_update();
124 event->data.pinchUpdate.zoomDisabled = details.zoom_disabled();
125 event->data.pinchUpdate.scale = details.scale();
126
127 return event;
128 }
129
130 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureTapDown(
131 const InputMessage& proto) {
132 std::unique_ptr<blink::WebGestureEvent> event(
133 BuildCommonWebGesture(proto, blink::WebInputEvent::Type::GestureTapDown));
134
135 const GestureTapDown& details = proto.gesture_tap_down();
136 event->data.tapDown.width = details.width();
137 event->data.tapDown.height = details.height();
138
139 return event;
140 }
141
142 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureTapCancel(
143 const InputMessage& proto) {
144 return BuildCommonWebGesture(proto,
145 blink::WebInputEvent::Type::GestureTapCancel);
146 }
147
148 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureTapUnconfirmed(
149 const InputMessage& proto) {
150 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
151 proto, blink::WebInputEvent::Type::GestureTapUnconfirmed));
152
153 const GestureTap& details = proto.gesture_tap();
154 event->data.tap.tapCount = details.tap_count();
155 event->data.tap.width = details.width();
156 event->data.tap.height = details.height();
157
158 return event;
159 }
160
161 std::unique_ptr<blink::WebGestureEvent> ProtoToGestureShowPress(
162 const InputMessage& proto) {
163 std::unique_ptr<blink::WebGestureEvent> event(BuildCommonWebGesture(
164 proto, blink::WebInputEvent::Type::GestureShowPress));
165
166 const GestureShowPress& details = proto.gesture_show_press();
167 event->data.showPress.width = details.width();
168 event->data.showPress.height = details.height();
169
170 return event;
171 }
172
173 } // namespace
174
175 InputMessageConverter::InputMessageConverter() {}
176
177 InputMessageConverter::~InputMessageConverter() {}
178
179 std::unique_ptr<blink::WebGestureEvent> InputMessageConverter::ProcessMessage(
180 const InputMessage& message) {
181 std::unique_ptr<blink::WebGestureEvent> event;
182
183 switch (message.type()) {
184 case InputMessage::Type_GestureScrollBegin:
185 event = ProtoToGestureScrollBegin(message);
186 break;
187 case InputMessage::Type_GestureScrollEnd:
188 event = ProtoToGestureScrollEnd(message);
189 break;
190 case InputMessage::Type_GestureScrollUpdate:
191 event = ProtoToGestureScrollUpdate(message);
192 break;
193 case InputMessage::Type_GestureFlingStart:
194 event = ProtoToGestureFlingStart(message);
195 break;
196 case InputMessage::Type_GestureFlingCancel:
197 event = ProtoToGestureFlingCancel(message);
198 break;
199 case InputMessage::Type_GestureTap:
200 event = ProtoToGestureTap(message);
201 break;
202 case InputMessage::Type_GesturePinchBegin:
203 event = ProtoToGesturePinchBegin(message);
204 break;
205 case InputMessage::Type_GesturePinchEnd:
206 event = ProtoToGesturePinchEnd(message);
207 break;
208 case InputMessage::Type_GesturePinchUpdate:
209 event = ProtoToGesturePinchUpdate(message);
210 break;
211 case InputMessage::Type_GestureTapDown:
212 event = ProtoToGestureTapDown(message);
213 break;
214 case InputMessage::Type_GestureTapCancel:
215 event = ProtoToGestureTapCancel(message);
216 break;
217 case InputMessage::Type_GestureTapUnconfirmed:
218 event = ProtoToGestureTapUnconfirmed(message);
219 break;
220 case InputMessage::Type_GestureShowPress:
221 event = ProtoToGestureShowPress(message);
222 break;
223 case InputMessage::UNKNOWN:
224 DLOG(FATAL) << "Received an InputMessage with an unknown type.";
225 return nullptr;
226 }
227
228 return event;
229 }
230
231 ui::TextInputType InputMessageConverter::TextInputTypeFromProto(
232 ImeMessage_InputType type) {
233 switch (type) {
234 case ImeMessage_InputType_NONE:
235 return ui::TEXT_INPUT_TYPE_NONE;
236 case ImeMessage_InputType_TEXT:
237 return ui::TEXT_INPUT_TYPE_TEXT;
238 case ImeMessage_InputType_PASSWORD:
239 return ui::TEXT_INPUT_TYPE_PASSWORD;
240 case ImeMessage_InputType_SEARCH:
241 return ui::TEXT_INPUT_TYPE_SEARCH;
242 case ImeMessage_InputType_EMAIL:
243 return ui::TEXT_INPUT_TYPE_EMAIL;
244 case ImeMessage_InputType_NUMBER:
245 return ui::TEXT_INPUT_TYPE_NUMBER;
246 case ImeMessage_InputType_TELEPHONE:
247 return ui::TEXT_INPUT_TYPE_TELEPHONE;
248 case ImeMessage_InputType_URL:
249 return ui::TEXT_INPUT_TYPE_URL;
250 case ImeMessage_InputType_DATE:
251 return ui::TEXT_INPUT_TYPE_DATE;
252 case ImeMessage_InputType_DATE_TIME:
253 return ui::TEXT_INPUT_TYPE_DATE_TIME;
254 case ImeMessage_InputType_DATE_TIME_LOCAL:
255 return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL;
256 case ImeMessage_InputType_MONTH:
257 return ui::TEXT_INPUT_TYPE_MONTH;
258 case ImeMessage_InputType_TIME:
259 return ui::TEXT_INPUT_TYPE_TIME;
260 case ImeMessage_InputType_WEEK:
261 return ui::TEXT_INPUT_TYPE_WEEK;
262 case ImeMessage_InputType_TEXT_AREA:
263 return ui::TEXT_INPUT_TYPE_TEXT_AREA;
264 case ImeMessage_InputType_CONTENT_EDITABLE:
265 return ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE;
266 case ImeMessage_InputType_DATE_TIME_FIELD:
267 return ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD;
268 }
269 return ui::TEXT_INPUT_TYPE_NONE;
270 }
271
272 ImeMessage_InputType InputMessageConverter::TextInputTypeToProto(
273 ui::TextInputType type) {
274 switch (type) {
275 case ui::TEXT_INPUT_TYPE_NONE:
276 NOTREACHED() << "IME needs an editable TextInputType";
277 return ImeMessage_InputType_NONE;
278 case ui::TEXT_INPUT_TYPE_TEXT:
279 return ImeMessage_InputType_TEXT;
280 case ui::TEXT_INPUT_TYPE_PASSWORD:
281 return ImeMessage_InputType_PASSWORD;
282 case ui::TEXT_INPUT_TYPE_SEARCH:
283 return ImeMessage_InputType_SEARCH;
284 case ui::TEXT_INPUT_TYPE_EMAIL:
285 return ImeMessage_InputType_EMAIL;
286 case ui::TEXT_INPUT_TYPE_NUMBER:
287 return ImeMessage_InputType_NUMBER;
288 case ui::TEXT_INPUT_TYPE_TELEPHONE:
289 return ImeMessage_InputType_TELEPHONE;
290 case ui::TEXT_INPUT_TYPE_URL:
291 return ImeMessage_InputType_URL;
292 case ui::TEXT_INPUT_TYPE_DATE:
293 return ImeMessage_InputType_DATE;
294 case ui::TEXT_INPUT_TYPE_DATE_TIME:
295 return ImeMessage_InputType_DATE_TIME;
296 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
297 return ImeMessage_InputType_DATE_TIME_LOCAL;
298 case ui::TEXT_INPUT_TYPE_MONTH:
299 return ImeMessage_InputType_MONTH;
300 case ui::TEXT_INPUT_TYPE_TIME:
301 return ImeMessage_InputType_TIME;
302 case ui::TEXT_INPUT_TYPE_WEEK:
303 return ImeMessage_InputType_WEEK;
304 case ui::TEXT_INPUT_TYPE_TEXT_AREA:
305 return ImeMessage_InputType_TEXT_AREA;
306 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
307 return ImeMessage_InputType_CONTENT_EDITABLE;
308 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
309 return ImeMessage_InputType_DATE_TIME_FIELD;
310 }
311 return ImeMessage_InputType_NONE;
312 }
313
314 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/net/input_message_converter.h ('k') | blimp/net/input_message_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698