Chromium Code Reviews| 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/proto/input.pb.h" | |
| 9 #include "third_party/WebKit/public/platform/WebGestureDevice.h" | |
| 10 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace { | |
| 14 | |
| 15 void WebGestureEventBaseToProto(const blink::WebGestureEvent* event, | |
|
Wez
2015/11/23 22:41:41
const WebGestureEvent& here and below?
David Trainor- moved to gerrit
2015/11/24 20:08:28
Done.
| |
| 16 GestureBaseProperties* proto) { | |
| 17 proto->set_x(event->x); | |
| 18 proto->set_y(event->y); | |
| 19 proto->set_global_x(event->globalX); | |
| 20 proto->set_global_y(event->globalY); | |
| 21 } | |
| 22 | |
| 23 void GestureScrollBeginToProto(const blink::WebGestureEvent* event, | |
| 24 InputMessage* proto) { | |
| 25 proto->set_type(InputMessage::Type_GestureScrollBegin); | |
| 26 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 27 | |
| 28 GestureScrollBegin* details = proto->mutable_gesture_scroll_begin(); | |
| 29 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 30 details->set_delta_x_hint(event->data.scrollBegin.deltaXHint); | |
| 31 details->set_delta_y_hint(event->data.scrollBegin.deltaYHint); | |
| 32 details->set_target_viewport(event->data.scrollBegin.targetViewport); | |
| 33 } | |
| 34 | |
| 35 void GestureScrollEndToProto(const blink::WebGestureEvent* event, | |
| 36 InputMessage* proto) { | |
| 37 proto->set_type(InputMessage::Type_GestureScrollEnd); | |
| 38 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 39 | |
| 40 GestureScrollEnd* details = proto->mutable_gesture_scroll_end(); | |
| 41 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 42 } | |
| 43 | |
| 44 void GestureScrollUpdateToProto(const blink::WebGestureEvent* event, | |
| 45 InputMessage* proto) { | |
| 46 proto->set_type(InputMessage::Type_GestureScrollUpdate); | |
| 47 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 48 | |
| 49 GestureScrollUpdate* details = proto->mutable_gesture_scroll_update(); | |
| 50 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 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.inertial); | |
| 60 } | |
| 61 | |
| 62 void GestureFlingStartToProto(const blink::WebGestureEvent* event, | |
| 63 InputMessage* proto) { | |
| 64 proto->set_type(InputMessage::Type_GestureFlingStart); | |
| 65 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 66 | |
| 67 GestureFlingStart* details = proto->mutable_gesture_fling_start(); | |
| 68 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 69 details->set_velocity_x(event->data.flingStart.velocityX); | |
| 70 details->set_velocity_y(event->data.flingStart.velocityY); | |
| 71 details->set_target_viewport(event->data.flingStart.targetViewport); | |
| 72 } | |
| 73 | |
| 74 void GestureFlingCancelToProto(const blink::WebGestureEvent* event, | |
| 75 InputMessage* proto) { | |
| 76 proto->set_type(InputMessage::Type_GestureFlingCancel); | |
| 77 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 78 | |
| 79 GestureFlingCancel* details = proto->mutable_gesture_fling_cancel(); | |
| 80 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 81 details->set_prevent_boosting(event->data.flingCancel.preventBoosting); | |
| 82 } | |
| 83 | |
| 84 void GestureTapToProto(const blink::WebGestureEvent* event, | |
| 85 InputMessage* proto) { | |
| 86 proto->set_type(InputMessage::Type_GestureTap); | |
| 87 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 88 | |
| 89 GestureTap* details = proto->mutable_gesture_tap(); | |
| 90 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 91 details->set_tap_count(event->data.tap.tapCount); | |
| 92 details->set_width(event->data.tap.width); | |
| 93 details->set_height(event->data.tap.height); | |
| 94 } | |
| 95 | |
| 96 void GesturePinchBeginToProto(const blink::WebGestureEvent* event, | |
| 97 InputMessage* proto) { | |
| 98 proto->set_type(InputMessage::Type_GesturePinchBegin); | |
| 99 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 100 | |
| 101 GesturePinchBegin* details = proto->mutable_gesture_pinch_begin(); | |
| 102 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 103 } | |
| 104 | |
| 105 void GesturePinchEndToProto(const blink::WebGestureEvent* event, | |
| 106 InputMessage* proto) { | |
| 107 proto->set_type(InputMessage::Type_GesturePinchEnd); | |
| 108 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 109 | |
| 110 GesturePinchEnd* details = proto->mutable_gesture_pinch_end(); | |
| 111 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 112 } | |
| 113 | |
| 114 void GesturePinchUpdateToProto(const blink::WebGestureEvent* event, | |
| 115 InputMessage* proto) { | |
| 116 proto->set_type(InputMessage::Type_GesturePinchUpdate); | |
| 117 proto->set_timestamp_seconds(event->timeStampSeconds); | |
| 118 | |
| 119 GesturePinchUpdate* details = proto->mutable_gesture_pinch_update(); | |
| 120 WebGestureEventBaseToProto(event, details->mutable_base()); | |
| 121 details->set_zoom_disabled(event->data.pinchUpdate.zoomDisabled); | |
| 122 details->set_scale(event->data.pinchUpdate.scale); | |
| 123 } | |
| 124 | |
| 125 } // namespace | |
| 126 | |
| 127 InputMessageGenerator::InputMessageGenerator() {} | |
| 128 | |
| 129 InputMessageGenerator::~InputMessageGenerator() {} | |
| 130 | |
| 131 bool InputMessageGenerator::GenerateMessage(const blink::WebInputEvent* event, | |
| 132 InputMessage* proto) { | |
| 133 switch (event->type) { | |
| 134 case blink::WebInputEvent::Type::GestureScrollBegin: | |
| 135 GestureScrollBeginToProto( | |
| 136 static_cast<const blink::WebGestureEvent*>(event), | |
| 137 proto); | |
| 138 break; | |
| 139 case blink::WebInputEvent::Type::GestureScrollEnd: | |
| 140 GestureScrollEndToProto(static_cast<const blink::WebGestureEvent*>(event), | |
| 141 proto); | |
| 142 break; | |
| 143 case blink::WebInputEvent::Type::GestureScrollUpdate: | |
| 144 GestureScrollUpdateToProto( | |
| 145 static_cast<const blink::WebGestureEvent*>(event), | |
| 146 proto); | |
| 147 break; | |
| 148 case blink::WebInputEvent::Type::GestureFlingStart: | |
| 149 GestureFlingStartToProto( | |
| 150 static_cast<const blink::WebGestureEvent*>(event), | |
| 151 proto); | |
| 152 break; | |
| 153 case blink::WebInputEvent::Type::GestureFlingCancel: | |
| 154 GestureFlingCancelToProto( | |
| 155 static_cast<const blink::WebGestureEvent*>(event), | |
| 156 proto); | |
| 157 break; | |
| 158 case blink::WebInputEvent::Type::GestureTap: | |
| 159 GestureTapToProto(static_cast<const blink::WebGestureEvent*>(event), | |
| 160 proto); | |
| 161 break; | |
| 162 case blink::WebInputEvent::Type::GesturePinchBegin: | |
| 163 GesturePinchBeginToProto( | |
| 164 static_cast<const blink::WebGestureEvent*>(event), | |
| 165 proto); | |
| 166 break; | |
| 167 case blink::WebInputEvent::Type::GesturePinchEnd: | |
| 168 GesturePinchEndToProto(static_cast<const blink::WebGestureEvent*>(event), | |
| 169 proto); | |
| 170 break; | |
| 171 case blink::WebInputEvent::Type::GesturePinchUpdate: | |
| 172 GesturePinchUpdateToProto( | |
| 173 static_cast<const blink::WebGestureEvent*>(event), | |
| 174 proto); | |
| 175 break; | |
| 176 default: | |
| 177 // Unsupported WebInputEvent. | |
|
Wez
2015/11/23 22:41:41
Could we instead list the events that we ignore ex
David Trainor- moved to gerrit
2015/11/24 20:08:27
Done.
| |
| 178 return false; | |
| 179 } | |
| 180 | |
| 181 return true; | |
| 182 } | |
| 183 | |
| 184 } // namespace blimp | |
| OLD | NEW |