Chromium Code Reviews| Index: blimp/net/input_message_generator.cc |
| diff --git a/blimp/net/input_message_generator.cc b/blimp/net/input_message_generator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc32599a45fd27fdba62dfa95c31752331b6d917 |
| --- /dev/null |
| +++ b/blimp/net/input_message_generator.cc |
| @@ -0,0 +1,155 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/net/input_message_generator.h" |
| + |
| +#include "base/logging.h" |
| +#include "blimp/common/proto/input.pb.h" |
| +#include "third_party/WebKit/public/platform/WebGestureDevice.h" |
| +#include "third_party/WebKit/public/web/WebInputEvent.h" |
| + |
| +namespace blimp { |
| +namespace { |
| + |
| +InputMessage::Type WebInputEventTypeToProto(blink::WebInputEvent::Type type) { |
| + switch (type) { |
| + case blink::WebInputEvent::Type::GestureScrollBegin: |
| + return InputMessage::Type_GestureScrollBegin; |
| + case blink::WebInputEvent::Type::GestureScrollEnd: |
| + return InputMessage::Type_GestureScrollEnd; |
| + case blink::WebInputEvent::Type::GestureScrollUpdate: |
| + return InputMessage::Type_GestureScrollUpdate; |
| + case blink::WebInputEvent::Type::GestureFlingStart: |
| + return InputMessage::Type_GestureFlingStart; |
| + case blink::WebInputEvent::Type::GestureFlingCancel: |
| + return InputMessage::Type_GestureFlingCancel; |
| + case blink::WebInputEvent::Type::GestureShowPress: |
| + return InputMessage::Type_GestureShowPress; |
| + case blink::WebInputEvent::Type::GestureTap: |
| + return InputMessage::Type_GestureTap; |
| + case blink::WebInputEvent::Type::GestureTapUnconfirmed: |
| + return InputMessage::Type_GestureTapUnconfirmed; |
| + case blink::WebInputEvent::Type::GestureTapDown: |
| + return InputMessage::Type_GestureTapDown; |
| + case blink::WebInputEvent::Type::GestureTapCancel: |
| + return InputMessage::Type_GestureTapCancel; |
| + case blink::WebInputEvent::Type::GestureDoubleTap: |
| + return InputMessage::Type_GestureDoubleTap; |
| + case blink::WebInputEvent::Type::GestureTwoFingerTap: |
| + return InputMessage::Type_GestureTwoFingerTap; |
| + case blink::WebInputEvent::Type::GestureLongPress: |
| + return InputMessage::Type_GestureLongPress; |
| + case blink::WebInputEvent::Type::GestureLongTap: |
| + return InputMessage::Type_GestureLongTap; |
| + case blink::WebInputEvent::Type::GesturePinchBegin: |
| + return InputMessage::Type_GesturePinchBegin; |
| + case blink::WebInputEvent::Type::GesturePinchEnd: |
| + return InputMessage::Type_GesturePinchEnd; |
| + case blink::WebInputEvent::Type::GesturePinchUpdate: |
| + return InputMessage::Type_GesturePinchUpdate; |
| + case blink::WebInputEvent::Type::Undefined: |
| + default: |
| + return InputMessage::Type_Undefined; |
| + } |
| +} |
| + |
| +blimp::WebGestureDevice WebGestureDeviceToProto( |
| + const blink::WebGestureDevice& type) { |
| + switch (type) { |
| + case blink::WebGestureDevice::WebGestureDeviceUninitialized: |
| + return WebGestureDevice::WebGestureDevice_Uninitialized; |
| + case blink::WebGestureDevice::WebGestureDeviceTouchpad: |
| + return WebGestureDevice::WebGestureDevice_Touchpad; |
| + case blink::WebGestureDevice::WebGestureDeviceTouchscreen: |
| + return WebGestureDevice::WebGestureDevice_Touchscreen; |
| + } |
| + return WebGestureDevice::WebGestureDevice_Uninitialized; |
| +} |
| + |
| +void WebGestureEventToProto(const blink::WebGestureEvent& event, |
| + GestureArgs* proto) { |
| + proto->set_x(event.x); |
| + proto->set_y(event.y); |
| + proto->set_global_x(event.globalX); |
| + proto->set_global_y(event.globalY); |
| + proto->set_source_device(WebGestureDeviceToProto(event.sourceDevice)); |
| + |
| + if (event.type == blink::WebInputEvent::GestureTap || |
| + event.type == blink::WebInputEvent::GestureTapUnconfirmed || |
| + event.type == blink::WebInputEvent::GestureDoubleTap) { |
| + GestureArgs::Tap* args = proto->mutable_tap(); |
| + args->set_tap_count(event.data.tap.tapCount); |
| + args->set_width(event.data.tap.width); |
| + args->set_height(event.data.tap.height); |
| + } else if (event.type == blink::WebInputEvent::GestureTapDown) { |
| + GestureArgs::TapDown* args = proto->mutable_tap_down(); |
| + args->set_width(event.data.tapDown.width); |
| + args->set_height(event.data.tapDown.height); |
| + } else if (event.type == blink::WebInputEvent::GestureShowPress) { |
| + GestureArgs::ShowPress* args = proto->mutable_show_press(); |
| + args->set_width(event.data.showPress.width); |
| + args->set_height(event.data.showPress.height); |
| + } else if (event.type == blink::WebInputEvent::GestureLongPress) { |
| + GestureArgs::LongPress* args = proto->mutable_long_press(); |
| + args->set_width(event.data.longPress.width); |
| + args->set_height(event.data.longPress.height); |
| + } else if (event.type == blink::WebInputEvent::GestureTwoFingerTap) { |
| + GestureArgs::TwoFingerTap* args = proto->mutable_two_finger_tap(); |
| + args->set_first_finger_width(event.data.twoFingerTap.firstFingerWidth); |
| + args->set_first_finger_height( |
| + event.data.twoFingerTap.firstFingerHeight); |
| + } else if (event.type == blink::WebInputEvent::GestureScrollBegin) { |
| + GestureArgs::ScrollBegin* args = proto->mutable_scroll_begin(); |
| + args->set_delta_x_hint(event.data.scrollBegin.deltaXHint); |
| + args->set_delta_y_hint(event.data.scrollBegin.deltaYHint); |
| + args->set_target_viewport(event.data.scrollBegin.targetViewport); |
| + } else if (event.type == blink::WebInputEvent::GestureScrollUpdate) { |
| + GestureArgs::ScrollUpdate* args = proto->mutable_scroll_update(); |
| + args->set_delta_x(event.data.scrollUpdate.deltaX); |
| + args->set_delta_y(event.data.scrollUpdate.deltaY); |
| + args->set_velocity_x(event.data.scrollUpdate.velocityX); |
| + args->set_velocity_y(event.data.scrollUpdate.velocityY); |
| + args->set_previous_update_in_sequence_prevented( |
| + event.data.scrollUpdate.previousUpdateInSequencePrevented); |
| + args->set_prevent_propagation( |
| + event.data.scrollUpdate.preventPropagation); |
| + args->set_inertial(event.data.scrollUpdate.inertial); |
| + } else if (event.type == blink::WebInputEvent::GestureFlingStart) { |
| + GestureArgs::FlingStart* args = proto->mutable_fling_start(); |
| + args->set_velocity_x(event.data.flingStart.velocityX); |
| + args->set_velocity_y(event.data.flingStart.velocityY); |
| + args->set_target_viewport(event.data.flingStart.targetViewport); |
| + } else if (event.type == blink::WebInputEvent::GestureFlingCancel) { |
| + GestureArgs::FlingCancel* args = proto->mutable_fling_cancel(); |
| + args->set_prevent_boosting(event.data.flingCancel.preventBoosting); |
| + } else if (event.type == blink::WebInputEvent::GesturePinchUpdate) { |
| + GestureArgs::PinchUpdate* args = proto->mutable_pinch_update(); |
| + args->set_zoom_disabled(event.data.pinchUpdate.zoomDisabled); |
| + args->set_scale(event.data.pinchUpdate.scale); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +InputMessageGenerator::InputMessageGenerator() {} |
| + |
| +InputMessageGenerator::~InputMessageGenerator() {} |
| + |
| +void InputMessageGenerator::GenerateMessage(const blink::WebInputEvent& event, |
| + InputMessage* message) { |
| + // Serialize the common WebInputEvent fields. |
| + 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
|
| + message->set_timestamp_seconds(event.timeStampSeconds); |
| + |
| + // Serialize the specific WebInputEvent fields. |
| + if (event.type >= blink::WebInputEvent::Type::GestureTypeFirst && |
| + 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.
|
| + WebGestureEventToProto(*static_cast<const blink::WebGestureEvent*>(&event), |
| + message->mutable_gesture()); |
| + } else { |
| + NOTIMPLEMENTED(); |
| + } |
| +} |
| + |
| +} // namespace blimp |