| 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 #include "device/gamepad/public/interfaces/webgamepad_struct_traits.h" |
| 6 |
| 7 namespace mojo { |
| 8 |
| 9 // static |
| 10 bool StructTraits<device::mojom::WebGamepadQuaternionDataView, |
| 11 blink::WebGamepadQuaternion>:: |
| 12 Read(device::mojom::WebGamepadQuaternionDataView data, |
| 13 blink::WebGamepadQuaternion* out) { |
| 14 out->notNull = data.notNull(); |
| 15 out->x = data.x(); |
| 16 out->y = data.y(); |
| 17 out->z = data.z(); |
| 18 out->w = data.w(); |
| 19 return true; |
| 20 } |
| 21 |
| 22 // static |
| 23 bool StructTraits< |
| 24 device::mojom::WebGamepadVectorDataView, |
| 25 blink::WebGamepadVector>::Read(device::mojom::WebGamepadVectorDataView data, |
| 26 blink::WebGamepadVector* out) { |
| 27 out->notNull = data.notNull(); |
| 28 out->x = data.x(); |
| 29 out->y = data.y(); |
| 30 out->z = data.z(); |
| 31 return true; |
| 32 } |
| 33 |
| 34 // static |
| 35 bool StructTraits< |
| 36 device::mojom::WebGamepadButtonDataView, |
| 37 blink::WebGamepadButton>::Read(device::mojom::WebGamepadButtonDataView data, |
| 38 blink::WebGamepadButton* out) { |
| 39 out->pressed = data.pressed(); |
| 40 out->touched = data.touched(); |
| 41 out->value = data.value(); |
| 42 return true; |
| 43 } |
| 44 |
| 45 // static |
| 46 bool StructTraits< |
| 47 device::mojom::WebGamepadPoseDataView, |
| 48 blink::WebGamepadPose>::Read(device::mojom::WebGamepadPoseDataView data, |
| 49 blink::WebGamepadPose* out) { |
| 50 out->notNull = data.notNull(); |
| 51 out->hasOrientation = data.hasOrientation(); |
| 52 out->hasPosition = data.hasPosition(); |
| 53 |
| 54 if (!data.ReadOrientation(&out->orientation)) |
| 55 return false; |
| 56 if (!data.ReadPosition(&out->position)) |
| 57 return false; |
| 58 if (!data.ReadAngularvelocity(&out->angularVelocity)) |
| 59 return false; |
| 60 if (!data.ReadLinearvelocity(&out->linearVelocity)) |
| 61 return false; |
| 62 if (!data.ReadAngularacceleration(&out->angularAcceleration)) |
| 63 return false; |
| 64 if (!data.ReadLinearacceleration(&out->linearAcceleration)) |
| 65 return false; |
| 66 |
| 67 return true; |
| 68 } |
| 69 |
| 70 // static |
| 71 device::mojom::WebGamepadHand |
| 72 EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand>::ToMojom( |
| 73 blink::WebGamepadHand input) { |
| 74 switch (input) { |
| 75 case blink::WebGamepadHand::GamepadHandNone: |
| 76 return device::mojom::WebGamepadHand::GamepadHandNone; |
| 77 case blink::WebGamepadHand::GamepadHandLeft: |
| 78 return device::mojom::WebGamepadHand::GamepadHandLeft; |
| 79 case blink::WebGamepadHand::GamepadHandRight: |
| 80 return device::mojom::WebGamepadHand::GamepadHandRight; |
| 81 } |
| 82 |
| 83 NOTREACHED(); |
| 84 return device::mojom::WebGamepadHand::GamepadHandNone; |
| 85 } |
| 86 |
| 87 // static |
| 88 bool EnumTraits<device::mojom::WebGamepadHand, blink::WebGamepadHand>:: |
| 89 FromMojom(device::mojom::WebGamepadHand input, |
| 90 blink::WebGamepadHand* output) { |
| 91 switch (input) { |
| 92 case device::mojom::WebGamepadHand::GamepadHandNone: |
| 93 *output = blink::WebGamepadHand::GamepadHandNone; |
| 94 return true; |
| 95 case device::mojom::WebGamepadHand::GamepadHandLeft: |
| 96 *output = blink::WebGamepadHand::GamepadHandLeft; |
| 97 return true; |
| 98 case device::mojom::WebGamepadHand::GamepadHandRight: |
| 99 *output = blink::WebGamepadHand::GamepadHandRight; |
| 100 return true; |
| 101 } |
| 102 |
| 103 NOTREACHED(); |
| 104 return false; |
| 105 } |
| 106 |
| 107 // static |
| 108 bool StructTraits<device::mojom::WebGamepadDataView, blink::WebGamepad>::Read( |
| 109 device::mojom::WebGamepadDataView data, |
| 110 blink::WebGamepad* out) { |
| 111 out->connected = data.connected(); |
| 112 |
| 113 CArray<uint16_t> id = {0, blink::WebGamepad::idLengthCap, |
| 114 reinterpret_cast<uint16_t*>(&out->id[0])}; |
| 115 if (!data.ReadId(&id)) |
| 116 return false; |
| 117 |
| 118 out->timestamp = data.timestamp(); |
| 119 out->axesLength = data.axesLength(); |
| 120 if (out->axesLength > blink::WebGamepad::axesLengthCap) { |
| 121 return false; |
| 122 } |
| 123 |
| 124 CArray<double> axes = {0, blink::WebGamepad::axesLengthCap, &out->axes[0]}; |
| 125 if (!data.ReadAxes(&axes)) |
| 126 return false; |
| 127 |
| 128 out->buttonsLength = data.buttonsLength(); |
| 129 if (out->buttonsLength > blink::WebGamepad::buttonsLengthCap) { |
| 130 return false; |
| 131 } |
| 132 |
| 133 CArray<blink::WebGamepadButton> buttons = { |
| 134 0, blink::WebGamepad::buttonsLengthCap, &out->buttons[0]}; |
| 135 if (!data.ReadButtons(&buttons)) |
| 136 return false; |
| 137 |
| 138 CArray<uint16_t> mapping = {0, blink::WebGamepad::mappingLengthCap, |
| 139 reinterpret_cast<uint16_t*>(&out->mapping[0])}; |
| 140 if (!data.ReadMapping(&mapping)) |
| 141 return false; |
| 142 if (!data.ReadPose(&out->pose)) |
| 143 return false; |
| 144 |
| 145 blink::WebGamepadHand hand; |
| 146 if (!data.ReadHand(&hand)) |
| 147 return false; |
| 148 out->hand = hand; |
| 149 |
| 150 out->displayId = data.displayId(); |
| 151 |
| 152 return true; |
| 153 } |
| 154 |
| 155 } // namespace mojo |
| OLD | NEW |