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

Unified Diff: device/gamepad/public/interfaces/webgamepad_struct_traits.h

Issue 2492183002: Add struct_traits and typemap for blink::WebGamepad (Closed)
Patch Set: fixed "un-aligned warning" in windows x64 build 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 side-by-side diff with in-line comments
Download patch
Index: device/gamepad/public/interfaces/webgamepad_struct_traits.h
diff --git a/device/gamepad/public/interfaces/webgamepad_struct_traits.h b/device/gamepad/public/interfaces/webgamepad_struct_traits.h
new file mode 100644
index 0000000000000000000000000000000000000000..5ab982287a18dffe91503227088422a28f9b935e
--- /dev/null
+++ b/device/gamepad/public/interfaces/webgamepad_struct_traits.h
@@ -0,0 +1,140 @@
+// 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.
+
+#ifndef DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_
+#define DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_
+
+#include <stddef.h>
+
+#include "device/gamepad/public/interfaces/gamepad.mojom.h"
+#include "mojo/public/cpp/bindings/array_traits_carray.h"
+#include "mojo/public/cpp/bindings/struct_traits.h"
+#include "third_party/WebKit/public/platform/WebGamepad.h"
+
+namespace mojo {
+
+template <>
+struct StructTraits<device::mojom::WebGamepadQuaternionDataView,
+ blink::WebGamepadQuaternion> {
+ static bool notNull(const blink::WebGamepadQuaternion& r) {
+ return r.notNull;
+ }
+ static float x(const blink::WebGamepadQuaternion& r) { return r.x; }
+ static float y(const blink::WebGamepadQuaternion& r) { return r.y; }
+ static float z(const blink::WebGamepadQuaternion& r) { return r.z; }
+ static float w(const blink::WebGamepadQuaternion& r) { return r.w; }
+ static bool Read(device::mojom::WebGamepadQuaternionDataView data,
+ blink::WebGamepadQuaternion* out);
+};
+
+template <>
+struct StructTraits<device::mojom::WebGamepadVectorDataView,
+ blink::WebGamepadVector> {
+ static bool notNull(const blink::WebGamepadVector& r) { return r.notNull; }
+ static float x(const blink::WebGamepadVector& r) { return r.x; }
+ static float y(const blink::WebGamepadVector& r) { return r.y; }
+ static float z(const blink::WebGamepadVector& r) { return r.z; }
+ static bool Read(device::mojom::WebGamepadVectorDataView data,
+ blink::WebGamepadVector* out);
+};
+
+template <>
+struct StructTraits<device::mojom::WebGamepadButtonDataView,
+ blink::WebGamepadButton> {
+ static bool pressed(const blink::WebGamepadButton& r) { return r.pressed; }
+ static bool touched(const blink::WebGamepadButton& r) { return r.touched; }
+ static double value(const blink::WebGamepadButton& r) { return r.value; }
+ static bool Read(device::mojom::WebGamepadButtonDataView data,
+ blink::WebGamepadButton* out);
+};
+
+template <>
+struct StructTraits<device::mojom::WebGamepadPoseDataView,
+ blink::WebGamepadPose> {
+ static bool notNull(const blink::WebGamepadPose& r) { return r.notNull; }
+ static bool hasOrientation(const blink::WebGamepadPose& r) {
+ return r.hasOrientation;
+ }
+ static bool hasPosition(const blink::WebGamepadPose& r) {
+ return r.hasPosition;
+ }
+ static const blink::WebGamepadQuaternion& orientation(
+ const blink::WebGamepadPose& r) {
+ return r.orientation;
+ }
+ static const blink::WebGamepadVector& position(
+ const blink::WebGamepadPose& r) {
+ return r.position;
+ }
+ static const blink::WebGamepadVector& angularVelocity(
+ const blink::WebGamepadPose& r) {
+ return r.angularVelocity;
+ }
+ static const blink::WebGamepadVector& linearVelocity(
+ const blink::WebGamepadPose& r) {
+ return r.linearVelocity;
+ }
+ static const blink::WebGamepadVector& angularAcceleration(
+ const blink::WebGamepadPose& r) {
+ return r.angularAcceleration;
+ }
+ static const blink::WebGamepadVector& linearAcceleration(
+ const blink::WebGamepadPose& r) {
+ return r.linearAcceleration;
+ }
+ static bool Read(device::mojom::WebGamepadPoseDataView data,
+ blink::WebGamepadPose* out);
+};
+
+template <>
+struct EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand> {
+ static device::mojom::WebGamepadHand ToMojom(blink::WebGamepadHand input);
+ static bool FromMojom(device::mojom::WebGamepadHand input,
+ blink::WebGamepadHand* output);
+};
+
+template <>
+struct StructTraits<device::mojom::WebGamepadDataView, blink::WebGamepad> {
+ static bool connected(const blink::WebGamepad& r) { return r.connected; }
+ static CArray<uint16_t> id(const blink::WebGamepad& r) {
+ return {
+ blink::WebGamepad::idLengthCap, blink::WebGamepad::idLengthCap,
+ reinterpret_cast<uint16_t*>(const_cast<blink::WebUChar*>(&r.id[0]))};
+ }
+ static uint64_t timestamp(const blink::WebGamepad& r) { return r.timestamp; }
+ static uint32_t axesLength(const blink::WebGamepad& r) {
+ return r.axesLength;
+ }
+ static CArray<double> axes(const blink::WebGamepad& r) {
+ return {blink::WebGamepad::axesLengthCap, blink::WebGamepad::axesLengthCap,
+ const_cast<double*>(&r.axes[0])};
+ }
+ static uint32_t buttonsLength(const blink::WebGamepad& r) {
+ return r.buttonsLength;
+ }
+ static CArray<blink::WebGamepadButton> buttons(const blink::WebGamepad& r) {
+ return {blink::WebGamepad::buttonsLengthCap,
+ blink::WebGamepad::buttonsLengthCap,
+ const_cast<blink::WebGamepadButton*>(&r.buttons[0])};
+ }
+ static CArray<uint16_t> mapping(const blink::WebGamepad& r) {
+ return {blink::WebGamepad::mappingLengthCap,
+ blink::WebGamepad::mappingLengthCap,
+ reinterpret_cast<uint16_t*>(
+ const_cast<blink::WebUChar*>(&r.mapping[0]))};
+ }
+ static const blink::WebGamepadPose& pose(const blink::WebGamepad& r) {
+ return r.pose;
+ }
+ static const blink::WebGamepadHand& hand(const blink::WebGamepad& r) {
+ return r.hand;
+ }
+ static uint32_t displayId(const blink::WebGamepad& r) { return r.displayId; }
+ static bool Read(device::mojom::WebGamepadDataView data,
+ blink::WebGamepad* out);
+};
+
+} // namespace mojo
+
+#endif // DEVICE_GAMEPAD_PUBLIC_INTERFACES_WEBGAMEPAD_STRUCT_TRAITS_H_

Powered by Google App Engine
This is Rietveld 408576698