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..09457da762c6510af81e37256867ce911e52ed43 |
| --- /dev/null |
| +++ b/blimp/net/input_message_generator.cc |
| @@ -0,0 +1,184 @@ |
| +// 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 { |
| + |
| +void WebGestureEventBaseToProto(const blink::WebGestureEvent* event, |
|
Wez
2015/11/23 22:41:41
const WebGestureEvent& here and below?
David Trainor- moved to gerrit
2015/11/24 20:08:28
Done.
|
| + GestureBaseProperties* proto) { |
| + proto->set_x(event->x); |
| + proto->set_y(event->y); |
| + proto->set_global_x(event->globalX); |
| + proto->set_global_y(event->globalY); |
| +} |
| + |
| +void GestureScrollBeginToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureScrollBegin); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureScrollBegin* details = proto->mutable_gesture_scroll_begin(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_delta_x_hint(event->data.scrollBegin.deltaXHint); |
| + details->set_delta_y_hint(event->data.scrollBegin.deltaYHint); |
| + details->set_target_viewport(event->data.scrollBegin.targetViewport); |
| +} |
| + |
| +void GestureScrollEndToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureScrollEnd); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureScrollEnd* details = proto->mutable_gesture_scroll_end(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| +} |
| + |
| +void GestureScrollUpdateToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureScrollUpdate); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureScrollUpdate* details = proto->mutable_gesture_scroll_update(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_delta_x(event->data.scrollUpdate.deltaX); |
| + details->set_delta_y(event->data.scrollUpdate.deltaY); |
| + details->set_velocity_x(event->data.scrollUpdate.velocityX); |
| + details->set_velocity_y(event->data.scrollUpdate.velocityY); |
| + details->set_previous_update_in_sequence_prevented( |
| + event->data.scrollUpdate.previousUpdateInSequencePrevented); |
| + details->set_prevent_propagation( |
| + event->data.scrollUpdate.preventPropagation); |
| + details->set_inertial(event->data.scrollUpdate.inertial); |
| +} |
| + |
| +void GestureFlingStartToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureFlingStart); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureFlingStart* details = proto->mutable_gesture_fling_start(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_velocity_x(event->data.flingStart.velocityX); |
| + details->set_velocity_y(event->data.flingStart.velocityY); |
| + details->set_target_viewport(event->data.flingStart.targetViewport); |
| +} |
| + |
| +void GestureFlingCancelToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureFlingCancel); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureFlingCancel* details = proto->mutable_gesture_fling_cancel(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_prevent_boosting(event->data.flingCancel.preventBoosting); |
| +} |
| + |
| +void GestureTapToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GestureTap); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GestureTap* details = proto->mutable_gesture_tap(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_tap_count(event->data.tap.tapCount); |
| + details->set_width(event->data.tap.width); |
| + details->set_height(event->data.tap.height); |
| +} |
| + |
| +void GesturePinchBeginToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GesturePinchBegin); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GesturePinchBegin* details = proto->mutable_gesture_pinch_begin(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| +} |
| + |
| +void GesturePinchEndToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GesturePinchEnd); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GesturePinchEnd* details = proto->mutable_gesture_pinch_end(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| +} |
| + |
| +void GesturePinchUpdateToProto(const blink::WebGestureEvent* event, |
| + InputMessage* proto) { |
| + proto->set_type(InputMessage::Type_GesturePinchUpdate); |
| + proto->set_timestamp_seconds(event->timeStampSeconds); |
| + |
| + GesturePinchUpdate* details = proto->mutable_gesture_pinch_update(); |
| + WebGestureEventBaseToProto(event, details->mutable_base()); |
| + details->set_zoom_disabled(event->data.pinchUpdate.zoomDisabled); |
| + details->set_scale(event->data.pinchUpdate.scale); |
| +} |
| + |
| +} // namespace |
| + |
| +InputMessageGenerator::InputMessageGenerator() {} |
| + |
| +InputMessageGenerator::~InputMessageGenerator() {} |
| + |
| +bool InputMessageGenerator::GenerateMessage(const blink::WebInputEvent* event, |
| + InputMessage* proto) { |
| + switch (event->type) { |
| + case blink::WebInputEvent::Type::GestureScrollBegin: |
| + GestureScrollBeginToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GestureScrollEnd: |
| + GestureScrollEndToProto(static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GestureScrollUpdate: |
| + GestureScrollUpdateToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GestureFlingStart: |
| + GestureFlingStartToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GestureFlingCancel: |
| + GestureFlingCancelToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GestureTap: |
| + GestureTapToProto(static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GesturePinchBegin: |
| + GesturePinchBeginToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GesturePinchEnd: |
| + GesturePinchEndToProto(static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + case blink::WebInputEvent::Type::GesturePinchUpdate: |
| + GesturePinchUpdateToProto( |
| + static_cast<const blink::WebGestureEvent*>(event), |
| + proto); |
| + break; |
| + default: |
| + // Unsupported WebInputEvent. |
|
Wez
2015/11/23 22:41:41
Could we instead list the events that we ignore ex
David Trainor- moved to gerrit
2015/11/24 20:08:27
Done.
|
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace blimp |