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 InputMessage::Type WebInputEventTypeToProto(blink::WebInputEvent::Type type) { | |
| 16 switch (type) { | |
| 17 case blink::WebInputEvent::Type::GestureScrollBegin: | |
| 18 return InputMessage::Type_GestureScrollBegin; | |
| 19 case blink::WebInputEvent::Type::GestureScrollEnd: | |
| 20 return InputMessage::Type_GestureScrollEnd; | |
| 21 case blink::WebInputEvent::Type::GestureScrollUpdate: | |
| 22 return InputMessage::Type_GestureScrollUpdate; | |
| 23 case blink::WebInputEvent::Type::GestureFlingStart: | |
| 24 return InputMessage::Type_GestureFlingStart; | |
| 25 case blink::WebInputEvent::Type::GestureFlingCancel: | |
| 26 return InputMessage::Type_GestureFlingCancel; | |
| 27 case blink::WebInputEvent::Type::GestureShowPress: | |
| 28 return InputMessage::Type_GestureShowPress; | |
| 29 case blink::WebInputEvent::Type::GestureTap: | |
| 30 return InputMessage::Type_GestureTap; | |
| 31 case blink::WebInputEvent::Type::GestureTapUnconfirmed: | |
| 32 return InputMessage::Type_GestureTapUnconfirmed; | |
| 33 case blink::WebInputEvent::Type::GestureTapDown: | |
| 34 return InputMessage::Type_GestureTapDown; | |
| 35 case blink::WebInputEvent::Type::GestureTapCancel: | |
| 36 return InputMessage::Type_GestureTapCancel; | |
| 37 case blink::WebInputEvent::Type::GestureDoubleTap: | |
| 38 return InputMessage::Type_GestureDoubleTap; | |
| 39 case blink::WebInputEvent::Type::GestureTwoFingerTap: | |
| 40 return InputMessage::Type_GestureTwoFingerTap; | |
| 41 case blink::WebInputEvent::Type::GestureLongPress: | |
| 42 return InputMessage::Type_GestureLongPress; | |
| 43 case blink::WebInputEvent::Type::GestureLongTap: | |
| 44 return InputMessage::Type_GestureLongTap; | |
| 45 case blink::WebInputEvent::Type::GesturePinchBegin: | |
| 46 return InputMessage::Type_GesturePinchBegin; | |
| 47 case blink::WebInputEvent::Type::GesturePinchEnd: | |
| 48 return InputMessage::Type_GesturePinchEnd; | |
| 49 case blink::WebInputEvent::Type::GesturePinchUpdate: | |
| 50 return InputMessage::Type_GesturePinchUpdate; | |
| 51 case blink::WebInputEvent::Type::Undefined: | |
| 52 default: | |
| 53 return InputMessage::Type_Undefined; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 blimp::WebGestureDevice WebGestureDeviceToProto( | |
| 58 const blink::WebGestureDevice& type) { | |
| 59 switch (type) { | |
| 60 case blink::WebGestureDevice::WebGestureDeviceUninitialized: | |
| 61 return WebGestureDevice::WebGestureDevice_Uninitialized; | |
| 62 case blink::WebGestureDevice::WebGestureDeviceTouchpad: | |
| 63 return WebGestureDevice::WebGestureDevice_Touchpad; | |
| 64 case blink::WebGestureDevice::WebGestureDeviceTouchscreen: | |
| 65 return WebGestureDevice::WebGestureDevice_Touchscreen; | |
| 66 } | |
| 67 return WebGestureDevice::WebGestureDevice_Uninitialized; | |
| 68 } | |
| 69 | |
| 70 void WebGestureEventToProto(const blink::WebGestureEvent& event, | |
| 71 GestureArgs* proto) { | |
| 72 proto->set_x(event.x); | |
| 73 proto->set_y(event.y); | |
| 74 proto->set_global_x(event.globalX); | |
| 75 proto->set_global_y(event.globalY); | |
| 76 proto->set_source_device(WebGestureDeviceToProto(event.sourceDevice)); | |
| 77 | |
| 78 if (event.type == blink::WebInputEvent::GestureTap || | |
| 79 event.type == blink::WebInputEvent::GestureTapUnconfirmed || | |
| 80 event.type == blink::WebInputEvent::GestureDoubleTap) { | |
| 81 GestureArgs::Tap* args = proto->mutable_tap(); | |
| 82 args->set_tap_count(event.data.tap.tapCount); | |
| 83 args->set_width(event.data.tap.width); | |
| 84 args->set_height(event.data.tap.height); | |
| 85 } else if (event.type == blink::WebInputEvent::GestureTapDown) { | |
| 86 GestureArgs::TapDown* args = proto->mutable_tap_down(); | |
| 87 args->set_width(event.data.tapDown.width); | |
| 88 args->set_height(event.data.tapDown.height); | |
| 89 } else if (event.type == blink::WebInputEvent::GestureShowPress) { | |
| 90 GestureArgs::ShowPress* args = proto->mutable_show_press(); | |
| 91 args->set_width(event.data.showPress.width); | |
| 92 args->set_height(event.data.showPress.height); | |
| 93 } else if (event.type == blink::WebInputEvent::GestureLongPress) { | |
| 94 GestureArgs::LongPress* args = proto->mutable_long_press(); | |
| 95 args->set_width(event.data.longPress.width); | |
| 96 args->set_height(event.data.longPress.height); | |
| 97 } else if (event.type == blink::WebInputEvent::GestureTwoFingerTap) { | |
| 98 GestureArgs::TwoFingerTap* args = proto->mutable_two_finger_tap(); | |
| 99 args->set_first_finger_width(event.data.twoFingerTap.firstFingerWidth); | |
| 100 args->set_first_finger_height( | |
| 101 event.data.twoFingerTap.firstFingerHeight); | |
| 102 } else if (event.type == blink::WebInputEvent::GestureScrollBegin) { | |
| 103 GestureArgs::ScrollBegin* args = proto->mutable_scroll_begin(); | |
| 104 args->set_delta_x_hint(event.data.scrollBegin.deltaXHint); | |
| 105 args->set_delta_y_hint(event.data.scrollBegin.deltaYHint); | |
| 106 args->set_target_viewport(event.data.scrollBegin.targetViewport); | |
| 107 } else if (event.type == blink::WebInputEvent::GestureScrollUpdate) { | |
| 108 GestureArgs::ScrollUpdate* args = proto->mutable_scroll_update(); | |
| 109 args->set_delta_x(event.data.scrollUpdate.deltaX); | |
| 110 args->set_delta_y(event.data.scrollUpdate.deltaY); | |
| 111 args->set_velocity_x(event.data.scrollUpdate.velocityX); | |
| 112 args->set_velocity_y(event.data.scrollUpdate.velocityY); | |
| 113 args->set_previous_update_in_sequence_prevented( | |
| 114 event.data.scrollUpdate.previousUpdateInSequencePrevented); | |
| 115 args->set_prevent_propagation( | |
| 116 event.data.scrollUpdate.preventPropagation); | |
| 117 args->set_inertial(event.data.scrollUpdate.inertial); | |
| 118 } else if (event.type == blink::WebInputEvent::GestureFlingStart) { | |
| 119 GestureArgs::FlingStart* args = proto->mutable_fling_start(); | |
| 120 args->set_velocity_x(event.data.flingStart.velocityX); | |
| 121 args->set_velocity_y(event.data.flingStart.velocityY); | |
| 122 args->set_target_viewport(event.data.flingStart.targetViewport); | |
| 123 } else if (event.type == blink::WebInputEvent::GestureFlingCancel) { | |
| 124 GestureArgs::FlingCancel* args = proto->mutable_fling_cancel(); | |
| 125 args->set_prevent_boosting(event.data.flingCancel.preventBoosting); | |
| 126 } else if (event.type == blink::WebInputEvent::GesturePinchUpdate) { | |
| 127 GestureArgs::PinchUpdate* args = proto->mutable_pinch_update(); | |
| 128 args->set_zoom_disabled(event.data.pinchUpdate.zoomDisabled); | |
| 129 args->set_scale(event.data.pinchUpdate.scale); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 } // namespace | |
| 134 | |
| 135 InputMessageGenerator::InputMessageGenerator() {} | |
| 136 | |
| 137 InputMessageGenerator::~InputMessageGenerator() {} | |
| 138 | |
| 139 void InputMessageGenerator::GenerateMessage(const blink::WebInputEvent& event, | |
| 140 InputMessage* message) { | |
| 141 // Serialize the common WebInputEvent fields. | |
| 142 message->set_type(WebInputEventTypeToProto(event.type)); | |
|
Wez
2015/11/18 02:18:32
Check that the type is not "undefined" here?
David Trainor- moved to gerrit
2015/11/19 00:49:43
Removed a lot of this stuff. Don't need undefined
| |
| 143 message->set_timestamp_seconds(event.timeStampSeconds); | |
| 144 | |
| 145 // Serialize the specific WebInputEvent fields. | |
| 146 if (event.type >= blink::WebInputEvent::Type::GestureTypeFirst && | |
| 147 event.type <= blink::WebInputEvent::Type::GestureTypeLast) { | |
|
Wez
2015/11/18 02:18:32
Wouldn't this work better as a switch that off-loa
David Trainor- moved to gerrit
2015/11/18 08:26:30
Sounds good. That also lets me more explicitly no
David Trainor- moved to gerrit
2015/11/19 00:49:43
Done.
| |
| 148 WebGestureEventToProto(*static_cast<const blink::WebGestureEvent*>(&event), | |
| 149 message->mutable_gesture()); | |
| 150 } else { | |
| 151 NOTIMPLEMENTED(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 } // namespace blimp | |
| OLD | NEW |