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

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: Removed unused type enum 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..aec29835f2e70080aca7c0bf38dbc97597af6410
--- /dev/null
+++ b/blimp/net/input_message_processor.cc
@@ -0,0 +1,198 @@
+// 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 {
+
+void ProtoToBaseWebGesture(const GestureBaseProperties& proto,
+ blink::WebGestureEvent* event) {
+ event->x = proto.x();
+ event->y = proto.y();
+ event->globalX = proto.global_x();
+ event->globalY = proto.global_y();
+ event->sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchscreen;
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollBegin(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
nyquist 2015/11/24 08:12:43 Optional nit: Did you investigate if the code was
David Trainor- moved to gerrit 2015/11/24 20:08:28 Done.
+ event->type = blink::WebInputEvent::Type::GestureScrollBegin;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureScrollBegin& details = proto.gesture_scroll_begin();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.scrollBegin.deltaXHint = details.delta_x_hint();
+ event->data.scrollBegin.deltaYHint = details.delta_y_hint();
+ event->data.scrollBegin.targetViewport = details.target_viewport();
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollEnd(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GestureScrollEnd;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureScrollEnd& details = proto.gesture_scroll_end();
+ ProtoToBaseWebGesture(details.base(), event.get());
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureScrollUpdate(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GestureScrollUpdate;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureScrollUpdate& details = proto.gesture_scroll_update();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.scrollUpdate.deltaX = details.delta_x();
+ event->data.scrollUpdate.deltaY = details.delta_y();
+ event->data.scrollUpdate.velocityX = details.velocity_x();
+ event->data.scrollUpdate.velocityY = details.velocity_y();
+ event->data.scrollUpdate.previousUpdateInSequencePrevented =
+ details.previous_update_in_sequence_prevented();
+ event->data.scrollUpdate.preventPropagation = details.prevent_propagation();
+ event->data.scrollUpdate.inertial = details.inertial();
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureFlingStart(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GestureFlingStart;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureFlingStart& details = proto.gesture_fling_start();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.flingStart.velocityX = details.velocity_x();
+ event->data.flingStart.velocityY = details.velocity_y();
+ event->data.flingStart.targetViewport = details.target_viewport();
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureFlingCancel(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GestureFlingCancel;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureFlingCancel& details = proto.gesture_fling_cancel();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.flingCancel.preventBoosting = details.prevent_boosting();
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGestureTap(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GestureTap;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GestureTap& details = proto.gesture_tap();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.tap.tapCount = details.tap_count();
+ event->data.tap.width = details.width();
+ event->data.tap.height = details.height();
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchBegin(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GesturePinchBegin;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GesturePinchBegin& details = proto.gesture_pinch_begin();
+ ProtoToBaseWebGesture(details.base(), event.get());
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchEnd(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GesturePinchEnd;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GesturePinchEnd& details = proto.gesture_pinch_end();
+ ProtoToBaseWebGesture(details.base(), event.get());
+
+ return event.Pass();
+}
+
+scoped_ptr<blink::WebInputEvent> ProtoToGesturePinchUpdate(
+ const InputMessage& proto) {
+ scoped_ptr<blink::WebGestureEvent> event(new blink::WebGestureEvent);
+ event->type = blink::WebInputEvent::Type::GesturePinchUpdate;
+ event->timeStampSeconds = proto.timestamp_seconds();
+
+ const GesturePinchUpdate& details = proto.gesture_pinch_update();
+ ProtoToBaseWebGesture(details.base(), event.get());
+ event->data.pinchUpdate.zoomDisabled = details.zoom_disabled();
+ event->data.pinchUpdate.scale = details.scale();
+
+ return event.Pass();
+}
+
+} // namespace
+
+InputMessageProcessor::InputMessageProcessor() {}
+
+InputMessageProcessor::~InputMessageProcessor() {}
+
+scoped_ptr<blink::WebInputEvent> InputMessageProcessor::ProcessMessage(
+ const InputMessage& message) {
+ scoped_ptr<blink::WebInputEvent> event;
+
+ switch (message.type()) {
+ case InputMessage::Type_GestureScrollBegin:
+ event = ProtoToGestureScrollBegin(message).Pass();
+ break;
+ case InputMessage::Type_GestureScrollEnd:
+ event = ProtoToGestureScrollEnd(message).Pass();
+ break;
+ case InputMessage::Type_GestureScrollUpdate:
+ event = ProtoToGestureScrollUpdate(message).Pass();
+ break;
+ case InputMessage::Type_GestureFlingStart:
+ event = ProtoToGestureFlingStart(message).Pass();
+ break;
+ case InputMessage::Type_GestureFlingCancel:
+ event = ProtoToGestureFlingCancel(message).Pass();
+ break;
+ case InputMessage::Type_GestureTap:
+ event = ProtoToGestureTap(message).Pass();
+ break;
+ case InputMessage::Type_GesturePinchBegin:
+ event = ProtoToGesturePinchBegin(message).Pass();
+ break;
+ case InputMessage::Type_GesturePinchEnd:
+ event = ProtoToGesturePinchEnd(message).Pass();
+ break;
+ case InputMessage::Type_GesturePinchUpdate:
+ event = ProtoToGesturePinchUpdate(message).Pass();
+ break;
+ default:
+ // Unsupported WebInputEvent.
Wez 2015/11/23 22:41:41 Now that the UNKNOWN enum value CL has landed, let
David Trainor- moved to gerrit 2015/11/24 20:08:28 Done.
+ return nullptr;
+ }
+
+ return event;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698