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_processor.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 blink::WebInputEvent::Type ProtoToWebInputEventType(InputMessage::Type type) { | |
| 16 switch (type) { | |
| 17 case InputMessage::Type_GestureScrollBegin: | |
| 18 return blink::WebInputEvent::Type::GestureScrollBegin; | |
| 19 case InputMessage::Type_GestureScrollEnd: | |
| 20 return blink::WebInputEvent::Type::GestureScrollEnd; | |
| 21 case InputMessage::Type_GestureScrollUpdate: | |
| 22 return blink::WebInputEvent::Type::GestureScrollUpdate; | |
| 23 case InputMessage::Type_GestureFlingStart: | |
| 24 return blink::WebInputEvent::Type::GestureFlingStart; | |
| 25 case InputMessage::Type_GestureFlingCancel: | |
| 26 return blink::WebInputEvent::Type::GestureFlingCancel; | |
| 27 case InputMessage::Type_GestureShowPress: | |
| 28 return blink::WebInputEvent::Type::GestureShowPress; | |
| 29 case InputMessage::Type_GestureTap: | |
| 30 return blink::WebInputEvent::Type::GestureTap; | |
| 31 case InputMessage::Type_GestureTapUnconfirmed: | |
| 32 return blink::WebInputEvent::Type::GestureTapUnconfirmed; | |
| 33 case InputMessage::Type_GestureTapDown: | |
| 34 return blink::WebInputEvent::Type::GestureTapDown; | |
| 35 case InputMessage::Type_GestureTapCancel: | |
| 36 return blink::WebInputEvent::Type::GestureTapCancel; | |
| 37 case InputMessage::Type_GestureDoubleTap: | |
| 38 return blink::WebInputEvent::Type::GestureDoubleTap; | |
| 39 case InputMessage::Type_GestureTwoFingerTap: | |
| 40 return blink::WebInputEvent::Type::GestureTwoFingerTap; | |
| 41 case InputMessage::Type_GestureLongPress: | |
| 42 return blink::WebInputEvent::Type::GestureLongPress; | |
| 43 case InputMessage::Type_GestureLongTap: | |
| 44 return blink::WebInputEvent::Type::GestureLongTap; | |
| 45 case InputMessage::Type_GesturePinchBegin: | |
| 46 return blink::WebInputEvent::Type::GesturePinchBegin; | |
| 47 case InputMessage::Type_GesturePinchEnd: | |
| 48 return blink::WebInputEvent::Type::GesturePinchEnd; | |
| 49 case InputMessage::Type_GesturePinchUpdate: | |
| 50 return blink::WebInputEvent::Type::GesturePinchUpdate; | |
| 51 case InputMessage::Type_Undefined: | |
| 52 default: | |
| 53 return blink::WebInputEvent::Type::Undefined; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 blink::WebGestureDevice ProtoToWebGestureDevice( | |
| 58 const blimp::WebGestureDevice& type) { | |
| 59 switch (type) { | |
| 60 case WebGestureDevice::WebGestureDevice_Uninitialized: | |
| 61 return blink::WebGestureDevice::WebGestureDeviceUninitialized; | |
| 62 case WebGestureDevice::WebGestureDevice_Touchpad: | |
| 63 return blink::WebGestureDevice::WebGestureDeviceTouchpad; | |
| 64 case WebGestureDevice::WebGestureDevice_Touchscreen: | |
| 65 return blink::WebGestureDevice::WebGestureDeviceTouchscreen; | |
| 66 } | |
| 67 return blink::WebGestureDevice::WebGestureDeviceUninitialized; | |
| 68 } | |
| 69 | |
| 70 scoped_ptr<blink::WebInputEvent> ProtoToWebGestureEvent( | |
| 71 const GestureArgs& proto) { | |
| 72 scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent); | |
| 73 event->x = proto.x(); | |
| 74 event->y = proto.y(); | |
| 75 event->globalX = proto.global_x(); | |
| 76 event->globalY = proto.global_y(); | |
| 77 event->sourceDevice = ProtoToWebGestureDevice(proto.source_device()); | |
| 78 | |
| 79 if (proto.has_tap()) { | |
| 80 event->data.tap.tapCount = proto.tap().tap_count(); | |
| 81 event->data.tap.width = proto.tap().width(); | |
| 82 event->data.tap.height = proto.tap().height(); | |
| 83 } else if (proto.has_tap_down()) { | |
| 84 event->data.tapDown.width = proto.tap_down().width(); | |
| 85 event->data.tapDown.height = proto.tap_down().height(); | |
| 86 } else if (proto.has_show_press()) { | |
| 87 event->data.showPress.width = proto.show_press().width(); | |
| 88 event->data.showPress.height = proto.show_press().height(); | |
| 89 } else if (proto.has_long_press()) { | |
| 90 event->data.longPress.width = proto.long_press().width(); | |
| 91 event->data.longPress.height = proto.long_press().height(); | |
| 92 } else if (proto.has_two_finger_tap()) { | |
| 93 event->data.twoFingerTap.firstFingerWidth = | |
| 94 proto.two_finger_tap().first_finger_width(); | |
| 95 event->data.twoFingerTap.firstFingerHeight = | |
| 96 proto.two_finger_tap().first_finger_height(); | |
| 97 } else if (proto.has_scroll_begin()) { | |
| 98 event->data.scrollBegin.deltaXHint = proto.scroll_begin().delta_x_hint(); | |
| 99 event->data.scrollBegin.deltaYHint = proto.scroll_begin().delta_y_hint(); | |
| 100 event->data.scrollBegin.targetViewport = | |
| 101 proto.scroll_begin().target_viewport(); | |
| 102 } else if (proto.has_scroll_update()) { | |
| 103 event->data.scrollUpdate.deltaX = proto.scroll_update().delta_x(); | |
| 104 event->data.scrollUpdate.deltaY = proto.scroll_update().delta_y(); | |
| 105 event->data.scrollUpdate.velocityX = proto.scroll_update().velocity_x(); | |
| 106 event->data.scrollUpdate.velocityY = proto.scroll_update().velocity_y(); | |
| 107 event->data.scrollUpdate.previousUpdateInSequencePrevented = | |
| 108 proto.scroll_update().previous_update_in_sequence_prevented(); | |
| 109 event->data.scrollUpdate.preventPropagation = | |
| 110 proto.scroll_update().prevent_propagation(); | |
| 111 event->data.scrollUpdate.inertial = proto.scroll_update().inertial(); | |
| 112 } else if (proto.has_fling_start()) { | |
| 113 event->data.flingStart.velocityX = proto.fling_start().velocity_x(); | |
| 114 event->data.flingStart.velocityY = proto.fling_start().velocity_y(); | |
| 115 event->data.flingStart.targetViewport = | |
| 116 proto.fling_start().target_viewport(); | |
| 117 } else if (proto.has_fling_cancel()) { | |
| 118 event->data.flingCancel.preventBoosting = | |
| 119 proto.fling_cancel().prevent_boosting(); | |
| 120 } else if (proto.has_pinch_update()) { | |
| 121 event->data.pinchUpdate.zoomDisabled = proto.pinch_update().zoom_disabled(); | |
| 122 event->data.pinchUpdate.scale = proto.pinch_update().scale(); | |
| 123 } | |
| 124 | |
| 125 return event.Pass(); | |
| 126 } | |
| 127 | |
| 128 } // namespace | |
| 129 | |
| 130 InputMessageProcessor::InputMessageProcessor() {} | |
| 131 | |
| 132 InputMessageProcessor::~InputMessageProcessor() {} | |
| 133 | |
| 134 scoped_ptr<blink::WebInputEvent> InputMessageProcessor::ProcessMessage( | |
| 135 const InputMessage& message) { | |
| 136 blink::WebInputEvent::Type type = ProtoToWebInputEventType(message.type()); | |
| 137 | |
| 138 scoped_ptr<blink::WebInputEvent> event; | |
| 139 | |
| 140 // Build the specific type of WebInputEvent and deserialize the specific | |
| 141 // fields. | |
| 142 if (type >= blink::WebInputEvent::Type::GestureTypeFirst && | |
| 143 type <= blink::WebInputEvent::Type::GestureTypeLast) { | |
|
Wez
2015/11/18 02:18:32
See comments in the generator - could we replace t
David Trainor- moved to gerrit
2015/11/19 00:49:43
Done.
| |
| 144 DCHECK(message.has_gesture()); | |
| 145 event = ProtoToWebGestureEvent(message.gesture()).Pass(); | |
| 146 } else { | |
| 147 NOTIMPLEMENTED(); | |
| 148 return nullptr; | |
| 149 } | |
| 150 | |
| 151 // Deserialize the common WebInputEvent fields. | |
| 152 event->type = type; | |
| 153 event->timeStampSeconds = message.timestamp_seconds(); | |
| 154 | |
| 155 return event; | |
| 156 } | |
| 157 | |
| 158 } // namespace blimp | |
| OLD | NEW |