| Index: device/gamepad/public/interfaces/webgamepad_struct_traits.cc
|
| diff --git a/device/gamepad/public/interfaces/webgamepad_struct_traits.cc b/device/gamepad/public/interfaces/webgamepad_struct_traits.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3833c138ad8462e2ec7103cbfbcc57855f812e1b
|
| --- /dev/null
|
| +++ b/device/gamepad/public/interfaces/webgamepad_struct_traits.cc
|
| @@ -0,0 +1,155 @@
|
| +// Copyright 2016 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 "device/gamepad/public/interfaces/webgamepad_struct_traits.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +// static
|
| +bool StructTraits<device::mojom::WebGamepadQuaternionDataView,
|
| + blink::WebGamepadQuaternion>::
|
| + Read(device::mojom::WebGamepadQuaternionDataView data,
|
| + blink::WebGamepadQuaternion* out) {
|
| + out->notNull = data.notNull();
|
| + out->x = data.x();
|
| + out->y = data.y();
|
| + out->z = data.z();
|
| + out->w = data.w();
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +bool StructTraits<
|
| + device::mojom::WebGamepadVectorDataView,
|
| + blink::WebGamepadVector>::Read(device::mojom::WebGamepadVectorDataView data,
|
| + blink::WebGamepadVector* out) {
|
| + out->notNull = data.notNull();
|
| + out->x = data.x();
|
| + out->y = data.y();
|
| + out->z = data.z();
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +bool StructTraits<
|
| + device::mojom::WebGamepadButtonDataView,
|
| + blink::WebGamepadButton>::Read(device::mojom::WebGamepadButtonDataView data,
|
| + blink::WebGamepadButton* out) {
|
| + out->pressed = data.pressed();
|
| + out->touched = data.touched();
|
| + out->value = data.value();
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +bool StructTraits<
|
| + device::mojom::WebGamepadPoseDataView,
|
| + blink::WebGamepadPose>::Read(device::mojom::WebGamepadPoseDataView data,
|
| + blink::WebGamepadPose* out) {
|
| + out->notNull = data.notNull();
|
| + out->hasOrientation = data.hasOrientation();
|
| + out->hasPosition = data.hasPosition();
|
| +
|
| + if (!data.ReadOrientation(&out->orientation))
|
| + return false;
|
| + if (!data.ReadPosition(&out->position))
|
| + return false;
|
| + if (!data.ReadAngularvelocity(&out->angularVelocity))
|
| + return false;
|
| + if (!data.ReadLinearvelocity(&out->linearVelocity))
|
| + return false;
|
| + if (!data.ReadAngularacceleration(&out->angularAcceleration))
|
| + return false;
|
| + if (!data.ReadLinearacceleration(&out->linearAcceleration))
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +// static
|
| +device::mojom::WebGamepadHand
|
| +EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand>::ToMojom(
|
| + blink::WebGamepadHand input) {
|
| + switch (input) {
|
| + case blink::WebGamepadHand::GamepadHandNone:
|
| + return device::mojom::WebGamepadHand::GamepadHandNone;
|
| + case blink::WebGamepadHand::GamepadHandLeft:
|
| + return device::mojom::WebGamepadHand::GamepadHandLeft;
|
| + case blink::WebGamepadHand::GamepadHandRight:
|
| + return device::mojom::WebGamepadHand::GamepadHandRight;
|
| + }
|
| +
|
| + NOTREACHED();
|
| + return device::mojom::WebGamepadHand::GamepadHandNone;
|
| +}
|
| +
|
| +// static
|
| +bool EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand>::
|
| + FromMojom(device::mojom::WebGamepadHand input,
|
| + blink::WebGamepadHand* output) {
|
| + switch (input) {
|
| + case device::mojom::WebGamepadHand::GamepadHandNone:
|
| + *output = blink::WebGamepadHand::GamepadHandNone;
|
| + return true;
|
| + case device::mojom::WebGamepadHand::GamepadHandLeft:
|
| + *output = blink::WebGamepadHand::GamepadHandLeft;
|
| + return true;
|
| + case device::mojom::WebGamepadHand::GamepadHandRight:
|
| + *output = blink::WebGamepadHand::GamepadHandRight;
|
| + return true;
|
| + }
|
| +
|
| + NOTREACHED();
|
| + return false;
|
| +}
|
| +
|
| +// static
|
| +bool StructTraits<device::mojom::WebGamepadDataView, blink::WebGamepad>::Read(
|
| + device::mojom::WebGamepadDataView data,
|
| + blink::WebGamepad* out) {
|
| + out->connected = data.connected();
|
| +
|
| + CArray<uint16_t> id = {0, blink::WebGamepad::idLengthCap,
|
| + reinterpret_cast<uint16_t*>(&out->id[0])};
|
| + if (!data.ReadId(&id))
|
| + return false;
|
| +
|
| + out->timestamp = data.timestamp();
|
| + out->axesLength = data.axesLength();
|
| + if (out->axesLength > blink::WebGamepad::axesLengthCap) {
|
| + return false;
|
| + }
|
| +
|
| + CArray<double> axes = {0, blink::WebGamepad::axesLengthCap, &out->axes[0]};
|
| + if (!data.ReadAxes(&axes))
|
| + return false;
|
| +
|
| + out->buttonsLength = data.buttonsLength();
|
| + if (out->buttonsLength > blink::WebGamepad::buttonsLengthCap) {
|
| + return false;
|
| + }
|
| +
|
| + CArray<blink::WebGamepadButton> buttons = {
|
| + 0, blink::WebGamepad::buttonsLengthCap, &out->buttons[0]};
|
| + if (!data.ReadButtons(&buttons))
|
| + return false;
|
| +
|
| + CArray<uint16_t> mapping = {0, blink::WebGamepad::mappingLengthCap,
|
| + reinterpret_cast<uint16_t*>(&out->mapping[0])};
|
| + if (!data.ReadMapping(&mapping))
|
| + return false;
|
| + if (!data.ReadPose(&out->pose))
|
| + return false;
|
| +
|
| + blink::WebGamepadHand hand;
|
| + if (!data.ReadHand(&hand))
|
| + return false;
|
| + out->hand = hand;
|
| +
|
| + out->displayId = data.displayId();
|
| +
|
| + return true;
|
| +}
|
| +
|
| +} // namespace mojo
|
|
|