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

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

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_ 5 #ifndef DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_
6 #define DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_ 6 #define DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "device/gamepad/public/cpp/gamepad.h"
10 #include "device/gamepad/public/interfaces/gamepad.mojom.h" 11 #include "device/gamepad/public/interfaces/gamepad.mojom.h"
11 #include "mojo/public/cpp/bindings/array_traits_carray.h" 12 #include "mojo/public/cpp/bindings/array_traits_carray.h"
12 #include "mojo/public/cpp/bindings/struct_traits.h" 13 #include "mojo/public/cpp/bindings/struct_traits.h"
13 #include "third_party/WebKit/public/platform/WebGamepad.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 16
17 template <> 17 template <>
18 struct StructTraits<device::mojom::GamepadQuaternionDataView, 18 struct StructTraits<device::mojom::GamepadQuaternionDataView,
19 blink::WebGamepadQuaternion> { 19 device::GamepadQuaternion> {
20 static bool IsNull(const blink::WebGamepadQuaternion& r) { 20 static bool IsNull(const device::GamepadQuaternion& r) { return !r.not_null; }
21 return !r.not_null; 21 static void SetToNull(device::GamepadQuaternion* out);
22 } 22 static float x(const device::GamepadQuaternion& r) { return r.x; }
23 static void SetToNull(blink::WebGamepadQuaternion* out); 23 static float y(const device::GamepadQuaternion& r) { return r.y; }
24 static float x(const blink::WebGamepadQuaternion& r) { return r.x; } 24 static float z(const device::GamepadQuaternion& r) { return r.z; }
25 static float y(const blink::WebGamepadQuaternion& r) { return r.y; } 25 static float w(const device::GamepadQuaternion& r) { return r.w; }
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, 26 static bool Read(device::mojom::GamepadQuaternionDataView data,
29 blink::WebGamepadQuaternion* out); 27 device::GamepadQuaternion* out);
30 }; 28 };
31 29
32 template <> 30 template <>
33 struct StructTraits<device::mojom::GamepadVectorDataView, 31 struct StructTraits<device::mojom::GamepadVectorDataView,
34 blink::WebGamepadVector> { 32 device::GamepadVector> {
35 static bool IsNull(const blink::WebGamepadVector& r) { return !r.not_null; } 33 static bool IsNull(const device::GamepadVector& r) { return !r.not_null; }
36 static void SetToNull(blink::WebGamepadVector* out); 34 static void SetToNull(device::GamepadVector* out);
37 static float x(const blink::WebGamepadVector& r) { return r.x; } 35 static float x(const device::GamepadVector& r) { return r.x; }
38 static float y(const blink::WebGamepadVector& r) { return r.y; } 36 static float y(const device::GamepadVector& r) { return r.y; }
39 static float z(const blink::WebGamepadVector& r) { return r.z; } 37 static float z(const device::GamepadVector& r) { return r.z; }
40 static bool Read(device::mojom::GamepadVectorDataView data, 38 static bool Read(device::mojom::GamepadVectorDataView data,
41 blink::WebGamepadVector* out); 39 device::GamepadVector* out);
42 }; 40 };
43 41
44 template <> 42 template <>
45 struct StructTraits<device::mojom::GamepadButtonDataView, 43 struct StructTraits<device::mojom::GamepadButtonDataView,
46 blink::WebGamepadButton> { 44 device::GamepadButton> {
47 static bool pressed(const blink::WebGamepadButton& r) { return r.pressed; } 45 static bool pressed(const device::GamepadButton& r) { return r.pressed; }
48 static bool touched(const blink::WebGamepadButton& r) { return r.touched; } 46 static bool touched(const device::GamepadButton& r) { return r.touched; }
49 static double value(const blink::WebGamepadButton& r) { return r.value; } 47 static double value(const device::GamepadButton& r) { return r.value; }
50 static bool Read(device::mojom::GamepadButtonDataView data, 48 static bool Read(device::mojom::GamepadButtonDataView data,
51 blink::WebGamepadButton* out); 49 device::GamepadButton* out);
52 }; 50 };
53 51
54 template <> 52 template <>
55 struct StructTraits<device::mojom::GamepadPoseDataView, blink::WebGamepadPose> { 53 struct StructTraits<device::mojom::GamepadPoseDataView, device::GamepadPose> {
56 static bool IsNull(const blink::WebGamepadPose& r) { return !r.not_null; } 54 static bool IsNull(const device::GamepadPose& r) { return !r.not_null; }
57 static void SetToNull(blink::WebGamepadPose* out); 55 static void SetToNull(device::GamepadPose* out);
58 static const blink::WebGamepadQuaternion& orientation( 56 static const device::GamepadQuaternion& orientation(
59 const blink::WebGamepadPose& r) { 57 const device::GamepadPose& r) {
60 return r.orientation; 58 return r.orientation;
61 } 59 }
62 static const blink::WebGamepadVector& position( 60 static const device::GamepadVector& position(const device::GamepadPose& r) {
63 const blink::WebGamepadPose& r) {
64 return r.position; 61 return r.position;
65 } 62 }
66 static const blink::WebGamepadVector& angular_velocity( 63 static const device::GamepadVector& angular_velocity(
67 const blink::WebGamepadPose& r) { 64 const device::GamepadPose& r) {
68 return r.angular_velocity; 65 return r.angular_velocity;
69 } 66 }
70 static const blink::WebGamepadVector& linear_velocity( 67 static const device::GamepadVector& linear_velocity(
71 const blink::WebGamepadPose& r) { 68 const device::GamepadPose& r) {
72 return r.linear_velocity; 69 return r.linear_velocity;
73 } 70 }
74 static const blink::WebGamepadVector& angular_acceleration( 71 static const device::GamepadVector& angular_acceleration(
75 const blink::WebGamepadPose& r) { 72 const device::GamepadPose& r) {
76 return r.angular_acceleration; 73 return r.angular_acceleration;
77 } 74 }
78 static const blink::WebGamepadVector& linear_acceleration( 75 static const device::GamepadVector& linear_acceleration(
79 const blink::WebGamepadPose& r) { 76 const device::GamepadPose& r) {
80 return r.linear_acceleration; 77 return r.linear_acceleration;
81 } 78 }
82 static bool Read(device::mojom::GamepadPoseDataView data, 79 static bool Read(device::mojom::GamepadPoseDataView data,
83 blink::WebGamepadPose* out); 80 device::GamepadPose* out);
84 }; 81 };
85 82
86 template <> 83 template <>
87 struct EnumTraits<device::mojom::GamepadHand, blink::WebGamepadHand> { 84 struct EnumTraits<device::mojom::GamepadHand, device::GamepadHand> {
88 static device::mojom::GamepadHand ToMojom(blink::WebGamepadHand input); 85 static device::mojom::GamepadHand ToMojom(device::GamepadHand input);
89 static bool FromMojom(device::mojom::GamepadHand input, 86 static bool FromMojom(device::mojom::GamepadHand input,
90 blink::WebGamepadHand* output); 87 device::GamepadHand* output);
91 }; 88 };
92 89
93 template <> 90 template <>
94 struct StructTraits<device::mojom::GamepadDataView, blink::WebGamepad> { 91 struct StructTraits<device::mojom::GamepadDataView, device::Gamepad> {
95 static bool connected(const blink::WebGamepad& r) { return r.connected; } 92 static bool connected(const device::Gamepad& r) { return r.connected; }
96 static uint64_t timestamp(const blink::WebGamepad& r) { return r.timestamp; } 93 static uint64_t timestamp(const device::Gamepad& r) { return r.timestamp; }
97 static ConstCArray<double> axes(const blink::WebGamepad& r) { 94 static ConstCArray<double> axes(const device::Gamepad& r) {
98 return {r.axes_length, &r.axes[0]}; 95 return {r.axes_length, &r.axes[0]};
99 } 96 }
100 static ConstCArray<blink::WebGamepadButton> buttons( 97 static ConstCArray<device::GamepadButton> buttons(const device::Gamepad& r) {
101 const blink::WebGamepad& r) {
102 return {r.buttons_length, &r.buttons[0]}; 98 return {r.buttons_length, &r.buttons[0]};
103 } 99 }
104 static const blink::WebGamepadPose& pose(const blink::WebGamepad& r) { 100 static const device::GamepadPose& pose(const device::Gamepad& r) {
105 return r.pose; 101 return r.pose;
106 } 102 }
107 static const blink::WebGamepadHand& hand(const blink::WebGamepad& r) { 103 static const device::GamepadHand& hand(const device::Gamepad& r) {
108 return r.hand; 104 return r.hand;
109 } 105 }
110 static uint32_t display_id(const blink::WebGamepad& r) { 106 static uint32_t display_id(const device::Gamepad& r) { return r.display_id; }
111 return r.display_id;
112 }
113 107
114 static ConstCArray<uint16_t> id(const blink::WebGamepad& r); 108 static ConstCArray<uint16_t> id(const device::Gamepad& r);
115 static ConstCArray<uint16_t> mapping(const blink::WebGamepad& r); 109 static ConstCArray<uint16_t> mapping(const device::Gamepad& r);
116 static bool Read(device::mojom::GamepadDataView data, blink::WebGamepad* out); 110 static bool Read(device::mojom::GamepadDataView data, device::Gamepad* out);
117 }; 111 };
118 112
119 } // namespace mojo 113 } // namespace mojo
120 114
121 #endif // DEVICE_GAMEPAD_PUBLIC_INTERFACES_GAMEPAD_STRUCT_TRAITS_H_ 115 #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