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

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: use nullable feature 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 CArray<uint16_t> id(const blink::WebGamepad& r) {
97 return {
98 blink::WebGamepad::idLengthCap, blink::WebGamepad::idLengthCap,
99 reinterpret_cast<uint16_t*>(const_cast<blink::WebUChar*>(&r.id[0]))};
yzshen1 2016/11/15 19:17:33 You could return a ConstCArray, that way you don't
ke.he 2016/11/16 09:51:41 Done.
100 }
101 static uint64_t timestamp(const blink::WebGamepad& r) { return r.timestamp; }
102 static uint32_t axes_length(const blink::WebGamepad& r) {
103 return r.axesLength;
104 }
105 static CArray<double> axes(const blink::WebGamepad& r) {
106 return {blink::WebGamepad::axesLengthCap, blink::WebGamepad::axesLengthCap,
107 const_cast<double*>(&r.axes[0])};
108 }
109 static uint32_t buttons_length(const blink::WebGamepad& r) {
110 return r.buttonsLength;
111 }
112 static CArray<blink::WebGamepadButton> buttons(const blink::WebGamepad& r) {
113 return {blink::WebGamepad::buttonsLengthCap,
114 blink::WebGamepad::buttonsLengthCap,
115 const_cast<blink::WebGamepadButton*>(&r.buttons[0])};
116 }
117 static CArray<uint16_t> mapping(const blink::WebGamepad& r) {
118 return {blink::WebGamepad::mappingLengthCap,
119 blink::WebGamepad::mappingLengthCap,
120 reinterpret_cast<uint16_t*>(
121 const_cast<blink::WebUChar*>(&r.mapping[0]))};
122 }
123 static const blink::WebGamepadPose& pose(const blink::WebGamepad& r) {
124 return r.pose;
125 }
126 static const blink::WebGamepadHand& hand(const blink::WebGamepad& r) {
127 return r.hand;
128 }
129 static uint32_t display_id(const blink::WebGamepad& r) { return r.displayId; }
130 static bool Read(device::mojom::GamepadDataView data, blink::WebGamepad* out);
131 };
132
133 } // namespace mojo
134
135 #endif // DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698