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

Side by Side Diff: device/gamepad/public/interfaces/gamepad_struct_traits.h

Issue 2492183002: Add struct_traits and typemap for blink::WebGamepad (Closed)
Patch Set: code rebase Created 4 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 unified diff | Download patch
OLDNEW
(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_GAMEPAD_STRUCT_TRAITS_H_
6 #define DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_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::GamepadQuaternionDataView,
19 blink::WebGamepadQuaternion> {
20 static bool IsNull(const blink::WebGamepadQuaternion& r) {
21 return !r.notNull;
22 }
23 static void SetToNull(blink::WebGamepadQuaternion* out);
24 static float x(const blink::WebGamepadQuaternion& r) { return r.x; }
25 static float y(const blink::WebGamepadQuaternion& r) { return r.y; }
26 static float z(const blink::WebGamepadQuaternion& r) { return r.z; }
27 static float w(const blink::WebGamepadQuaternion& r) { return r.w; }
28 static bool Read(device::mojom::GamepadQuaternionDataView data,
29 blink::WebGamepadQuaternion* out);
30 };
31
32 template <>
33 struct StructTraits<device::mojom::GamepadVectorDataView,
34 blink::WebGamepadVector> {
35 static bool IsNull(const blink::WebGamepadVector& r) { return !r.notNull; }
36 static void SetToNull(blink::WebGamepadVector* out);
37 static float x(const blink::WebGamepadVector& r) { return r.x; }
38 static float y(const blink::WebGamepadVector& r) { return r.y; }
39 static float z(const blink::WebGamepadVector& r) { return r.z; }
40 static bool Read(device::mojom::GamepadVectorDataView data,
41 blink::WebGamepadVector* out);
42 };
43
44 template <>
45 struct StructTraits<device::mojom::GamepadButtonDataView,
46 blink::WebGamepadButton> {
47 static bool pressed(const blink::WebGamepadButton& r) { return r.pressed; }
48 static bool touched(const blink::WebGamepadButton& r) { return r.touched; }
49 static double value(const blink::WebGamepadButton& r) { return r.value; }
50 static bool Read(device::mojom::GamepadButtonDataView data,
51 blink::WebGamepadButton* out);
52 };
53
54 template <>
55 struct StructTraits<device::mojom::GamepadPoseDataView, blink::WebGamepadPose> {
56 static bool IsNull(const blink::WebGamepadPose& r) { return !r.notNull; }
57 static void SetToNull(blink::WebGamepadPose* out);
58 static const blink::WebGamepadQuaternion& orientation(
59 const blink::WebGamepadPose& r) {
60 return r.orientation;
61 }
62 static const blink::WebGamepadVector& position(
63 const blink::WebGamepadPose& r) {
64 return r.position;
65 }
66 static const blink::WebGamepadVector& angular_velocity(
67 const blink::WebGamepadPose& r) {
68 return r.angularVelocity;
69 }
70 static const blink::WebGamepadVector& linear_velocity(
71 const blink::WebGamepadPose& r) {
72 return r.linearVelocity;
73 }
74 static const blink::WebGamepadVector& angular_acceleration(
75 const blink::WebGamepadPose& r) {
76 return r.angularAcceleration;
77 }
78 static const blink::WebGamepadVector& linear_acceleration(
79 const blink::WebGamepadPose& r) {
80 return r.linearAcceleration;
81 }
82 static bool Read(device::mojom::GamepadPoseDataView data,
83 blink::WebGamepadPose* out);
84 };
85
86 template <>
87 struct EnumTraits<device::mojom::GamepadHand, blink::WebGamepadHand> {
88 static device::mojom::GamepadHand ToMojom(blink::WebGamepadHand input);
89 static bool FromMojom(device::mojom::GamepadHand input,
90 blink::WebGamepadHand* output);
91 };
92
93 template <>
94 struct StructTraits<device::mojom::GamepadDataView, blink::WebGamepad> {
95 static bool connected(const blink::WebGamepad& r) { return r.connected; }
96 static uint64_t timestamp(const blink::WebGamepad& r) { return r.timestamp; }
97 static ConstCArray<double> axes(const blink::WebGamepad& r) {
98 return {r.axesLength, &r.axes[0]};
99 }
100 static ConstCArray<blink::WebGamepadButton> buttons(
101 const blink::WebGamepad& r) {
102 return {r.buttonsLength, &r.buttons[0]};
103 }
104 static const blink::WebGamepadPose& pose(const blink::WebGamepad& r) {
105 return r.pose;
106 }
107 static const blink::WebGamepadHand& hand(const blink::WebGamepad& r) {
108 return r.hand;
109 }
110 static uint32_t display_id(const blink::WebGamepad& r) { return r.displayId; }
111
112 static ConstCArray<uint16_t> id(const blink::WebGamepad& r);
113 static ConstCArray<uint16_t> mapping(const blink::WebGamepad& r);
114 static bool Read(device::mojom::GamepadDataView data, blink::WebGamepad* out);
115 };
116
117 } // namespace mojo
118
119 #endif // DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_
OLDNEW
« no previous file with comments | « device/gamepad/public/interfaces/gamepad.typemap ('k') | device/gamepad/public/interfaces/gamepad_struct_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698