| 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 scoped_ptr<blink::WebGestureEvent> BuildCommonWebGesture( |
| 16 const InputMessage& proto, |
| 17 blink::WebInputEvent::Type type) { |
| 18 scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent); |
| 19 event->type = type; |
| 20 event->timeStampSeconds = proto.timestamp_seconds(); |
| 21 |
| 22 const GestureCommon& common = proto.gesture_common(); |
| 23 event->x = common.x(); |
| 24 event->y = common.y(); |
| 25 event->globalX = common.global_x(); |
| 26 event->globalY = common.global_y(); |
| 27 event->sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchscreen; |
| 28 return event; |
| 29 } |
| 30 |
| 31 scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollBegin( |
| 32 const InputMessage& proto) { |
| 33 scoped_ptr<blink::WebGestureEvent> event( |
| 34 BuildCommonWebGesture(proto, |
| 35 blink::WebInputEvent::Type::GestureScrollBegin)); |
| 36 |
| 37 const GestureScrollBegin& details = proto.gesture_scroll_begin(); |
| 38 event->data.scrollBegin.deltaXHint = details.delta_x_hint(); |
| 39 event->data.scrollBegin.deltaYHint = details.delta_y_hint(); |
| 40 event->data.scrollBegin.targetViewport = details.target_viewport(); |
| 41 |
| 42 return std::move(event); |
| 43 } |
| 44 |
| 45 scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollEnd( |
| 46 const InputMessage& proto) { |
| 47 return BuildCommonWebGesture(proto, |
| 48 blink::WebInputEvent::Type::GestureScrollEnd); |
| 49 } |
| 50 |
| 51 scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollUpdate( |
| 52 const InputMessage& proto) { |
| 53 scoped_ptr<blink::WebGestureEvent> event( |
| 54 BuildCommonWebGesture(proto, |
| 55 blink::WebInputEvent::Type::GestureScrollUpdate)); |
| 56 |
| 57 const GestureScrollUpdate& details = proto.gesture_scroll_update(); |
| 58 event->data.scrollUpdate.deltaX = details.delta_x(); |
| 59 event->data.scrollUpdate.deltaY = details.delta_y(); |
| 60 event->data.scrollUpdate.velocityX = details.velocity_x(); |
| 61 event->data.scrollUpdate.velocityY = details.velocity_y(); |
| 62 event->data.scrollUpdate.previousUpdateInSequencePrevented = |
| 63 details.previous_update_in_sequence_prevented(); |
| 64 event->data.scrollUpdate.preventPropagation = details.prevent_propagation(); |
| 65 event->data.scrollUpdate.inertial = details.inertial(); |
| 66 |
| 67 return std::move(event); |
| 68 } |
| 69 |
| 70 scoped_ptr<blink::WebInputEvent> ProtoToGestureFlingStart( |
| 71 const InputMessage& proto) { |
| 72 scoped_ptr<blink::WebGestureEvent> event( |
| 73 BuildCommonWebGesture(proto, |
| 74 blink::WebInputEvent::Type::GestureFlingStart)); |
| 75 |
| 76 const GestureFlingStart& details = proto.gesture_fling_start(); |
| 77 event->data.flingStart.velocityX = details.velocity_x(); |
| 78 event->data.flingStart.velocityY = details.velocity_y(); |
| 79 event->data.flingStart.targetViewport = details.target_viewport(); |
| 80 |
| 81 return std::move(event); |
| 82 } |
| 83 |
| 84 scoped_ptr<blink::WebInputEvent> ProtoToGestureFlingCancel( |
| 85 const InputMessage& proto) { |
| 86 scoped_ptr<blink::WebGestureEvent> event( |
| 87 BuildCommonWebGesture(proto, |
| 88 blink::WebInputEvent::Type::GestureFlingCancel)); |
| 89 |
| 90 const GestureFlingCancel& details = proto.gesture_fling_cancel(); |
| 91 event->data.flingCancel.preventBoosting = details.prevent_boosting(); |
| 92 |
| 93 return std::move(event); |
| 94 } |
| 95 |
| 96 scoped_ptr<blink::WebInputEvent> ProtoToGestureTap( |
| 97 const InputMessage& proto) { |
| 98 scoped_ptr<blink::WebGestureEvent> event( |
| 99 BuildCommonWebGesture(proto, |
| 100 blink::WebInputEvent::Type::GestureTap)); |
| 101 |
| 102 const GestureTap& details = proto.gesture_tap(); |
| 103 event->data.tap.tapCount = details.tap_count(); |
| 104 event->data.tap.width = details.width(); |
| 105 event->data.tap.height = details.height(); |
| 106 |
| 107 return std::move(event); |
| 108 } |
| 109 |
| 110 scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchBegin( |
| 111 const InputMessage& proto) { |
| 112 return BuildCommonWebGesture(proto, |
| 113 blink::WebInputEvent::Type::GesturePinchBegin); |
| 114 } |
| 115 |
| 116 scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchEnd( |
| 117 const InputMessage& proto) { |
| 118 return BuildCommonWebGesture(proto, |
| 119 blink::WebInputEvent::Type::GesturePinchEnd); |
| 120 } |
| 121 |
| 122 scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchUpdate( |
| 123 const InputMessage& proto) { |
| 124 scoped_ptr<blink::WebGestureEvent> event( |
| 125 BuildCommonWebGesture(proto, |
| 126 blink::WebInputEvent::Type::GesturePinchUpdate)); |
| 127 |
| 128 const GesturePinchUpdate& details = proto.gesture_pinch_update(); |
| 129 event->data.pinchUpdate.zoomDisabled = details.zoom_disabled(); |
| 130 event->data.pinchUpdate.scale = details.scale(); |
| 131 |
| 132 return std::move(event); |
| 133 } |
| 134 |
| 135 } // namespace |
| 136 |
| 137 InputMessageProcessor::InputMessageProcessor() {} |
| 138 |
| 139 InputMessageProcessor::~InputMessageProcessor() {} |
| 140 |
| 141 scoped_ptr<blink::WebInputEvent> InputMessageProcessor::ProcessMessage( |
| 142 const InputMessage& message) { |
| 143 scoped_ptr<blink::WebInputEvent> event; |
| 144 |
| 145 switch (message.type()) { |
| 146 case InputMessage::Type_GestureScrollBegin: |
| 147 event = ProtoToGestureScrollBegin(message); |
| 148 break; |
| 149 case InputMessage::Type_GestureScrollEnd: |
| 150 event = ProtoToGestureScrollEnd(message); |
| 151 break; |
| 152 case InputMessage::Type_GestureScrollUpdate: |
| 153 event = ProtoToGestureScrollUpdate(message); |
| 154 break; |
| 155 case InputMessage::Type_GestureFlingStart: |
| 156 event = ProtoToGestureFlingStart(message); |
| 157 break; |
| 158 case InputMessage::Type_GestureFlingCancel: |
| 159 event = ProtoToGestureFlingCancel(message); |
| 160 break; |
| 161 case InputMessage::Type_GestureTap: |
| 162 event = ProtoToGestureTap(message); |
| 163 break; |
| 164 case InputMessage::Type_GesturePinchBegin: |
| 165 event = ProtoToGesturePinchBegin(message); |
| 166 break; |
| 167 case InputMessage::Type_GesturePinchEnd: |
| 168 event = ProtoToGesturePinchEnd(message); |
| 169 break; |
| 170 case InputMessage::Type_GesturePinchUpdate: |
| 171 event = ProtoToGesturePinchUpdate(message); |
| 172 break; |
| 173 case InputMessage::UNKNOWN: |
| 174 DLOG(FATAL) << "Received an InputMessage with an unknown type."; |
| 175 return nullptr; |
| 176 } |
| 177 |
| 178 return event; |
| 179 } |
| 180 |
| 181 } // namespace blimp |
| OLD | NEW |