| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_ |
| 6 #define DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include "device/gamepad/public/interfaces/gamepad.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/array_traits_carray.h" |
| 12 #include "mojo/public/cpp/bindings/struct_traits.h" |
| 13 #include "third_party/WebKit/public/platform/WebGamepad.h" |
| 14 |
| 15 namespace mojo { |
| 16 |
| 17 template <> |
| 18 struct StructTraits<device::mojom::WebGamepadQuaternionDataView, |
| 19 blink::WebGamepadQuaternion> { |
| 20 static bool notNull(const blink::WebGamepadQuaternion& r) { |
| 21 return r.notNull; |
| 22 } |
| 23 static float x(const blink::WebGamepadQuaternion& r) { return r.x; } |
| 24 static float y(const blink::WebGamepadQuaternion& r) { return r.y; } |
| 25 static float z(const blink::WebGamepadQuaternion& r) { return r.z; } |
| 26 static float w(const blink::WebGamepadQuaternion& r) { return r.w; } |
| 27 static bool Read(device::mojom::WebGamepadQuaternionDataView data, |
| 28 blink::WebGamepadQuaternion* out); |
| 29 }; |
| 30 |
| 31 template <> |
| 32 struct StructTraits<device::mojom::WebGamepadVectorDataView, |
| 33 blink::WebGamepadVector> { |
| 34 static bool notNull(const blink::WebGamepadVector& r) { return r.notNull; } |
| 35 static float x(const blink::WebGamepadVector& r) { return r.x; } |
| 36 static float y(const blink::WebGamepadVector& r) { return r.y; } |
| 37 static float z(const blink::WebGamepadVector& r) { return r.z; } |
| 38 static bool Read(device::mojom::WebGamepadVectorDataView data, |
| 39 blink::WebGamepadVector* out); |
| 40 }; |
| 41 |
| 42 template <> |
| 43 struct StructTraits<device::mojom::WebGamepadButtonDataView, |
| 44 blink::WebGamepadButton> { |
| 45 static bool pressed(const blink::WebGamepadButton& r) { return r.pressed; } |
| 46 static bool touched(const blink::WebGamepadButton& r) { return r.touched; } |
| 47 static double value(const blink::WebGamepadButton& r) { return r.value; } |
| 48 static bool Read(device::mojom::WebGamepadButtonDataView data, |
| 49 blink::WebGamepadButton* out); |
| 50 }; |
| 51 |
| 52 template <> |
| 53 struct StructTraits<device::mojom::WebGamepadPoseDataView, |
| 54 blink::WebGamepadPose> { |
| 55 static bool notNull(const blink::WebGamepadPose& r) { return r.notNull; } |
| 56 static bool hasOrientation(const blink::WebGamepadPose& r) { |
| 57 return r.hasOrientation; |
| 58 } |
| 59 static bool hasPosition(const blink::WebGamepadPose& r) { |
| 60 return r.hasPosition; |
| 61 } |
| 62 static const blink::WebGamepadQuaternion& orientation( |
| 63 const blink::WebGamepadPose& r) { |
| 64 return r.orientation; |
| 65 } |
| 66 static const blink::WebGamepadVector& position( |
| 67 const blink::WebGamepadPose& r) { |
| 68 return r.position; |
| 69 } |
| 70 static const blink::WebGamepadVector& angularVelocity( |
| 71 const blink::WebGamepadPose& r) { |
| 72 return r.angularVelocity; |
| 73 } |
| 74 static const blink::WebGamepadVector& linearVelocity( |
| 75 const blink::WebGamepadPose& r) { |
| 76 return r.linearVelocity; |
| 77 } |
| 78 static const blink::WebGamepadVector& angularAcceleration( |
| 79 const blink::WebGamepadPose& r) { |
| 80 return r.angularAcceleration; |
| 81 } |
| 82 static const blink::WebGamepadVector& linearAcceleration( |
| 83 const blink::WebGamepadPose& r) { |
| 84 return r.linearAcceleration; |
| 85 } |
| 86 static bool Read(device::mojom::WebGamepadPoseDataView data, |
| 87 blink::WebGamepadPose* out); |
| 88 }; |
| 89 |
| 90 template <> |
| 91 struct EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand> { |
| 92 static device::mojom::WebGamepadHand ToMojom(blink::WebGamepadHand input); |
| 93 static bool FromMojom(device::mojom::WebGamepadHand input, |
| 94 blink::WebGamepadHand* output); |
| 95 }; |
| 96 |
| 97 template <> |
| 98 struct StructTraits<device::mojom::WebGamepadDataView, blink::WebGamepad> { |
| 99 static bool connected(const blink::WebGamepad& r) { return r.connected; } |
| 100 static CArray<uint16_t> id(const blink::WebGamepad& r) { |
| 101 return { |
| 102 blink::WebGamepad::idLengthCap, blink::WebGamepad::idLengthCap, |
| 103 reinterpret_cast<uint16_t*>(const_cast<blink::WebUChar*>(&r.id[0]))}; |
| 104 } |
| 105 static uint64_t timestamp(const blink::WebGamepad& r) { return r.timestamp; } |
| 106 static uint32_t axesLength(const blink::WebGamepad& r) { |
| 107 return r.axesLength; |
| 108 } |
| 109 static CArray<double> axes(const blink::WebGamepad& r) { |
| 110 return {blink::WebGamepad::axesLengthCap, blink::WebGamepad::axesLengthCap, |
| 111 const_cast<double*>(&r.axes[0])}; |
| 112 } |
| 113 static uint32_t buttonsLength(const blink::WebGamepad& r) { |
| 114 return r.buttonsLength; |
| 115 } |
| 116 static CArray<blink::WebGamepadButton> buttons(const blink::WebGamepad& r) { |
| 117 return {blink::WebGamepad::buttonsLengthCap, |
| 118 blink::WebGamepad::buttonsLengthCap, |
| 119 const_cast<blink::WebGamepadButton*>(&r.buttons[0])}; |
| 120 } |
| 121 static CArray<uint16_t> mapping(const blink::WebGamepad& r) { |
| 122 return {blink::WebGamepad::mappingLengthCap, |
| 123 blink::WebGamepad::mappingLengthCap, |
| 124 reinterpret_cast<uint16_t*>( |
| 125 const_cast<blink::WebUChar*>(&r.mapping[0]))}; |
| 126 } |
| 127 static const blink::WebGamepadPose& pose(const blink::WebGamepad& r) { |
| 128 return r.pose; |
| 129 } |
| 130 static const blink::WebGamepadHand& hand(const blink::WebGamepad& r) { |
| 131 return r.hand; |
| 132 } |
| 133 static uint32_t displayId(const blink::WebGamepad& r) { return r.displayId; } |
| 134 static bool Read(device::mojom::WebGamepadDataView data, |
| 135 blink::WebGamepad* out); |
| 136 }; |
| 137 |
| 138 } // namespace mojo |
| 139 |
| 140 #endif // DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_ |
| OLD | NEW |