Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2986)

Unified Diff: blimp/net/input_message_processor.cc

Issue 1426993008: Serialize a subset of WebInputEvents to protobufs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split serialization and deserialization to message generators/processors. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/net/input_message_processor.cc
diff --git a/blimp/net/input_message_processor.cc b/blimp/net/input_message_processor.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1269fe1ed0f8ad45d8226b192c5f53e224194b0b
--- /dev/null
+++ b/blimp/net/input_message_processor.cc
@@ -0,0 +1,158 @@
+// 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_processor.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 {
+
+blink::WebInputEvent::Type ProtoToWebInputEventType(InputMessage::Type type) {
+ switch (type) {
+ case InputMessage::Type_GestureScrollBegin:
+ return blink::WebInputEvent::Type::GestureScrollBegin;
+ case InputMessage::Type_GestureScrollEnd:
+ return blink::WebInputEvent::Type::GestureScrollEnd;
+ case InputMessage::Type_GestureScrollUpdate:
+ return blink::WebInputEvent::Type::GestureScrollUpdate;
+ case InputMessage::Type_GestureFlingStart:
+ return blink::WebInputEvent::Type::GestureFlingStart;
+ case InputMessage::Type_GestureFlingCancel:
+ return blink::WebInputEvent::Type::GestureFlingCancel;
+ case InputMessage::Type_GestureShowPress:
+ return blink::WebInputEvent::Type::GestureShowPress;
+ case InputMessage::Type_GestureTap:
+ return blink::WebInputEvent::Type::GestureTap;
+ case InputMessage::Type_GestureTapUnconfirmed:
+ return blink::WebInputEvent::Type::GestureTapUnconfirmed;
+ case InputMessage::Type_GestureTapDown:
+ return blink::WebInputEvent::Type::GestureTapDown;
+ case InputMessage::Type_GestureTapCancel:
+ return blink::WebInputEvent::Type::GestureTapCancel;
+ case InputMessage::Type_GestureDoubleTap:
+ return blink::WebInputEvent::Type::GestureDoubleTap;
+ case InputMessage::Type_GestureTwoFingerTap:
+ return blink::WebInputEvent::Type::GestureTwoFingerTap;
+ case InputMessage::Type_GestureLongPress:
+ return blink::WebInputEvent::Type::GestureLongPress;
+ case InputMessage::Type_GestureLongTap:
+ return blink::WebInputEvent::Type::GestureLongTap;
+ case InputMessage::Type_GesturePinchBegin:
+ return blink::WebInputEvent::Type::GesturePinchBegin;
+ case InputMessage::Type_GesturePinchEnd:
+ return blink::WebInputEvent::Type::GesturePinchEnd;
+ case InputMessage::Type_GesturePinchUpdate:
+ return blink::WebInputEvent::Type::GesturePinchUpdate;
+ case InputMessage::Type_Undefined:
+ default:
+ return blink::WebInputEvent::Type::Undefined;
+ }
+}
+
+blink::WebGestureDevice ProtoToWebGestureDevice(
+ const blimp::WebGestureDevice& type) {
+ switch (type) {
+ case WebGestureDevice::WebGestureDevice_Uninitialized:
+ return blink::WebGestureDevice::WebGestureDeviceUninitialized;
+ case WebGestureDevice::WebGestureDevice_Touchpad:
+ return blink::WebGestureDevice::WebGestureDeviceTouchpad;
+ case WebGestureDevice::WebGestureDevice_Touchscreen:
+ return blink::WebGestureDevice::WebGestureDeviceTouchscreen;
+ }
+ return blink::WebGestureDevice::WebGestureDeviceUninitialized;
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToWebGestureEvent(
+ const GestureArgs& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->x = proto.x();
+ event->y = proto.y();
+ event->globalX = proto.global_x();
+ event->globalY = proto.global_y();
+ event->sourceDevice = ProtoToWebGestureDevice(proto.source_device());
+
+ if (proto.has_tap()) {
+ event->data.tap.tapCount = proto.tap().tap_count();
+ event->data.tap.width = proto.tap().width();
+ event->data.tap.height = proto.tap().height();
+ } else if (proto.has_tap_down()) {
+ event->data.tapDown.width = proto.tap_down().width();
+ event->data.tapDown.height = proto.tap_down().height();
+ } else if (proto.has_show_press()) {
+ event->data.showPress.width = proto.show_press().width();
+ event->data.showPress.height = proto.show_press().height();
+ } else if (proto.has_long_press()) {
+ event->data.longPress.width = proto.long_press().width();
+ event->data.longPress.height = proto.long_press().height();
+ } else if (proto.has_two_finger_tap()) {
+ event->data.twoFingerTap.firstFingerWidth =
+ proto.two_finger_tap().first_finger_width();
+ event->data.twoFingerTap.firstFingerHeight =
+ proto.two_finger_tap().first_finger_height();
+ } else if (proto.has_scroll_begin()) {
+ event->data.scrollBegin.deltaXHint = proto.scroll_begin().delta_x_hint();
+ event->data.scrollBegin.deltaYHint = proto.scroll_begin().delta_y_hint();
+ event->data.scrollBegin.targetViewport =
+ proto.scroll_begin().target_viewport();
+ } else if (proto.has_scroll_update()) {
+ event->data.scrollUpdate.deltaX = proto.scroll_update().delta_x();
+ event->data.scrollUpdate.deltaY = proto.scroll_update().delta_y();
+ event->data.scrollUpdate.velocityX = proto.scroll_update().velocity_x();
+ event->data.scrollUpdate.velocityY = proto.scroll_update().velocity_y();
+ event->data.scrollUpdate.previousUpdateInSequencePrevented =
+ proto.scroll_update().previous_update_in_sequence_prevented();
+ event->data.scrollUpdate.preventPropagation =
+ proto.scroll_update().prevent_propagation();
+ event->data.scrollUpdate.inertial = proto.scroll_update().inertial();
+ } else if (proto.has_fling_start()) {
+ event->data.flingStart.velocityX = proto.fling_start().velocity_x();
+ event->data.flingStart.velocityY = proto.fling_start().velocity_y();
+ event->data.flingStart.targetViewport =
+ proto.fling_start().target_viewport();
+ } else if (proto.has_fling_cancel()) {
+ event->data.flingCancel.preventBoosting =
+ proto.fling_cancel().prevent_boosting();
+ } else if (proto.has_pinch_update()) {
+ event->data.pinchUpdate.zoomDisabled = proto.pinch_update().zoom_disabled();
+ event->data.pinchUpdate.scale = proto.pinch_update().scale();
+ }
+
+ return event.Pass();
+}
+
+} // namespace
+
+InputMessageProcessor::InputMessageProcessor() {}
+
+InputMessageProcessor::~InputMessageProcessor() {}
+
+scoped_ptr<blink::WebInputEvent> InputMessageProcessor::ProcessMessage(
+ const InputMessage& message) {
+ blink::WebInputEvent::Type type = ProtoToWebInputEventType(message.type());
+
+ scoped_ptr<blink::WebInputEvent> event;
+
+ // Build the specific type of WebInputEvent and deserialize the specific
+ // fields.
+ if (type >= blink::WebInputEvent::Type::GestureTypeFirst &&
+ 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.
+ DCHECK(message.has_gesture());
+ event = ProtoToWebGestureEvent(message.gesture()).Pass();
+ } else {
+ NOTIMPLEMENTED();
+ return nullptr;
+ }
+
+ // Deserialize the common WebInputEvent fields.
+ event->type = type;
+ event->timeStampSeconds = message.timestamp_seconds();
+
+ return event;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698