OLD | NEW |
| (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_generator.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "blimp/common/create_blimp_message.h" | |
9 #include "blimp/common/proto/blimp_message.pb.h" | |
10 #include "blimp/common/proto/input.pb.h" | |
11 #include "blimp/net/blimp_message_processor.h" | |
12 #include "third_party/WebKit/public/platform/WebGestureDevice.h" | |
13 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | |
14 | |
15 namespace blimp { | |
16 namespace { | |
17 | |
18 void CommonWebGestureToProto(const blink::WebGestureEvent& event, | |
19 InputMessage::Type type, | |
20 InputMessage* proto) { | |
21 proto->set_type(type); | |
22 proto->set_timestamp_seconds(event.timeStampSeconds()); | |
23 | |
24 GestureCommon* common = proto->mutable_gesture_common(); | |
25 common->set_x(event.x); | |
26 common->set_y(event.y); | |
27 common->set_global_x(event.globalX); | |
28 common->set_global_y(event.globalY); | |
29 } | |
30 | |
31 void GestureScrollBeginToProto(const blink::WebGestureEvent& event, | |
32 InputMessage* proto) { | |
33 CommonWebGestureToProto(event, InputMessage::Type_GestureScrollBegin, proto); | |
34 | |
35 GestureScrollBegin* details = proto->mutable_gesture_scroll_begin(); | |
36 details->set_delta_x_hint(event.data.scrollBegin.deltaXHint); | |
37 details->set_delta_y_hint(event.data.scrollBegin.deltaYHint); | |
38 details->set_target_viewport(event.data.scrollBegin.targetViewport); | |
39 } | |
40 | |
41 void GestureScrollEndToProto(const blink::WebGestureEvent& event, | |
42 InputMessage* proto) { | |
43 CommonWebGestureToProto(event, InputMessage::Type_GestureScrollEnd, proto); | |
44 } | |
45 | |
46 void GestureScrollUpdateToProto(const blink::WebGestureEvent& event, | |
47 InputMessage* proto) { | |
48 CommonWebGestureToProto(event, InputMessage::Type_GestureScrollUpdate, proto); | |
49 | |
50 GestureScrollUpdate* details = proto->mutable_gesture_scroll_update(); | |
51 details->set_delta_x(event.data.scrollUpdate.deltaX); | |
52 details->set_delta_y(event.data.scrollUpdate.deltaY); | |
53 details->set_velocity_x(event.data.scrollUpdate.velocityX); | |
54 details->set_velocity_y(event.data.scrollUpdate.velocityY); | |
55 details->set_previous_update_in_sequence_prevented( | |
56 event.data.scrollUpdate.previousUpdateInSequencePrevented); | |
57 details->set_prevent_propagation( | |
58 event.data.scrollUpdate.preventPropagation); | |
59 details->set_inertial(event.data.scrollUpdate.inertialPhase == | |
60 blink::WebGestureEvent::MomentumPhase); | |
61 } | |
62 | |
63 void GestureFlingStartToProto(const blink::WebGestureEvent& event, | |
64 InputMessage* proto) { | |
65 CommonWebGestureToProto(event, InputMessage::Type_GestureFlingStart, proto); | |
66 | |
67 GestureFlingStart* details = proto->mutable_gesture_fling_start(); | |
68 details->set_velocity_x(event.data.flingStart.velocityX); | |
69 details->set_velocity_y(event.data.flingStart.velocityY); | |
70 details->set_target_viewport(event.data.flingStart.targetViewport); | |
71 } | |
72 | |
73 void GestureFlingCancelToProto(const blink::WebGestureEvent& event, | |
74 InputMessage* proto) { | |
75 CommonWebGestureToProto(event, InputMessage::Type_GestureFlingCancel, proto); | |
76 | |
77 GestureFlingCancel* details = proto->mutable_gesture_fling_cancel(); | |
78 details->set_prevent_boosting(event.data.flingCancel.preventBoosting); | |
79 } | |
80 | |
81 void GestureTapToProto(const blink::WebGestureEvent& event, | |
82 InputMessage* proto) { | |
83 CommonWebGestureToProto(event, InputMessage::Type_GestureTap, proto); | |
84 | |
85 GestureTap* details = proto->mutable_gesture_tap(); | |
86 details->set_tap_count(event.data.tap.tapCount); | |
87 details->set_width(event.data.tap.width); | |
88 details->set_height(event.data.tap.height); | |
89 } | |
90 | |
91 void GesturePinchBeginToProto(const blink::WebGestureEvent& event, | |
92 InputMessage* proto) { | |
93 CommonWebGestureToProto(event, InputMessage::Type_GesturePinchBegin, proto); | |
94 } | |
95 | |
96 void GesturePinchEndToProto(const blink::WebGestureEvent& event, | |
97 InputMessage* proto) { | |
98 CommonWebGestureToProto(event, InputMessage::Type_GesturePinchEnd, proto); | |
99 } | |
100 | |
101 void GesturePinchUpdateToProto(const blink::WebGestureEvent& event, | |
102 InputMessage* proto) { | |
103 CommonWebGestureToProto(event, InputMessage::Type_GesturePinchUpdate, proto); | |
104 | |
105 GesturePinchUpdate* details = proto->mutable_gesture_pinch_update(); | |
106 details->set_zoom_disabled(event.data.pinchUpdate.zoomDisabled); | |
107 details->set_scale(event.data.pinchUpdate.scale); | |
108 } | |
109 | |
110 void GestureTapDownToProto(const blink::WebGestureEvent& event, | |
111 InputMessage* proto) { | |
112 CommonWebGestureToProto(event, InputMessage::Type_GestureTapDown, proto); | |
113 | |
114 GestureTapDown* details = proto->mutable_gesture_tap_down(); | |
115 details->set_width(event.data.tapDown.width); | |
116 details->set_height(event.data.tapDown.height); | |
117 } | |
118 | |
119 void GestureTapCancelToProto(const blink::WebGestureEvent& event, | |
120 InputMessage* proto) { | |
121 CommonWebGestureToProto(event, InputMessage::Type_GestureTapCancel, proto); | |
122 } | |
123 | |
124 void GestureTapUnconfirmedToProto(const blink::WebGestureEvent& event, | |
125 InputMessage* proto) { | |
126 CommonWebGestureToProto(event, InputMessage::Type_GestureTapUnconfirmed, | |
127 proto); | |
128 | |
129 GestureTap* details = proto->mutable_gesture_tap(); | |
130 details->set_tap_count(event.data.tap.tapCount); | |
131 details->set_width(event.data.tap.width); | |
132 details->set_height(event.data.tap.height); | |
133 } | |
134 | |
135 void GestureShowPressToProto(const blink::WebGestureEvent& event, | |
136 InputMessage* proto) { | |
137 CommonWebGestureToProto(event, InputMessage::Type_GestureShowPress, proto); | |
138 | |
139 GestureShowPress* details = proto->mutable_gesture_show_press(); | |
140 details->set_width(event.data.showPress.width); | |
141 details->set_height(event.data.showPress.height); | |
142 } | |
143 | |
144 } // namespace | |
145 | |
146 InputMessageGenerator::InputMessageGenerator() {} | |
147 | |
148 InputMessageGenerator::~InputMessageGenerator() {} | |
149 | |
150 std::unique_ptr<BlimpMessage> InputMessageGenerator::GenerateMessage( | |
151 const blink::WebGestureEvent& event) { | |
152 InputMessage* details; | |
153 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&details); | |
154 | |
155 switch (event.type()) { | |
156 case blink::WebInputEvent::Type::GestureScrollBegin: | |
157 GestureScrollBeginToProto(event, details); | |
158 break; | |
159 case blink::WebInputEvent::Type::GestureScrollEnd: | |
160 GestureScrollEndToProto(event, details); | |
161 break; | |
162 case blink::WebInputEvent::Type::GestureScrollUpdate: | |
163 GestureScrollUpdateToProto(event, details); | |
164 break; | |
165 case blink::WebInputEvent::Type::GestureFlingStart: | |
166 GestureFlingStartToProto(event, details); | |
167 break; | |
168 case blink::WebInputEvent::Type::GestureFlingCancel: | |
169 GestureFlingCancelToProto(event, details); | |
170 break; | |
171 case blink::WebInputEvent::Type::GestureTap: | |
172 GestureTapToProto(event, details); | |
173 break; | |
174 case blink::WebInputEvent::Type::GesturePinchBegin: | |
175 GesturePinchBeginToProto(event, details); | |
176 break; | |
177 case blink::WebInputEvent::Type::GesturePinchEnd: | |
178 GesturePinchEndToProto(event, details); | |
179 break; | |
180 case blink::WebInputEvent::Type::GesturePinchUpdate: | |
181 GesturePinchUpdateToProto(event, details); | |
182 break; | |
183 case blink::WebInputEvent::Type::GestureShowPress: | |
184 GestureShowPressToProto(event, details); | |
185 break; | |
186 case blink::WebInputEvent::Type::GestureTapUnconfirmed: | |
187 GestureTapUnconfirmedToProto(event, details); | |
188 break; | |
189 case blink::WebInputEvent::Type::GestureTapDown: | |
190 GestureTapDownToProto(event, details); | |
191 break; | |
192 case blink::WebInputEvent::Type::GestureTapCancel: | |
193 GestureTapCancelToProto(event, details); | |
194 break; | |
195 | |
196 // Unsupported types: | |
197 case blink::WebInputEvent::Type::Undefined: | |
198 case blink::WebInputEvent::Type::MouseDown: | |
199 case blink::WebInputEvent::Type::MouseUp: | |
200 case blink::WebInputEvent::Type::MouseMove: | |
201 case blink::WebInputEvent::Type::MouseEnter: | |
202 case blink::WebInputEvent::Type::MouseLeave: | |
203 case blink::WebInputEvent::Type::ContextMenu: | |
204 case blink::WebInputEvent::Type::MouseWheel: | |
205 case blink::WebInputEvent::Type::RawKeyDown: | |
206 case blink::WebInputEvent::Type::KeyDown: | |
207 case blink::WebInputEvent::Type::KeyUp: | |
208 case blink::WebInputEvent::Type::Char: | |
209 case blink::WebInputEvent::Type::GestureDoubleTap: | |
210 case blink::WebInputEvent::Type::GestureTwoFingerTap: | |
211 case blink::WebInputEvent::Type::GestureLongPress: | |
212 case blink::WebInputEvent::Type::GestureLongTap: | |
213 case blink::WebInputEvent::Type::TouchStart: | |
214 case blink::WebInputEvent::Type::TouchMove: | |
215 case blink::WebInputEvent::Type::TouchEnd: | |
216 case blink::WebInputEvent::Type::TouchCancel: | |
217 case blink::WebInputEvent::Type::TouchScrollStarted: | |
218 DVLOG(1) << "Unsupported WebInputEvent type " << event.type(); | |
219 return nullptr; | |
220 } | |
221 | |
222 return message; | |
223 } | |
224 | |
225 } // namespace blimp | |
OLD | NEW |