| Index: ui/events/devices/mojo/input_device_struct_traits.h
|
| diff --git a/ui/events/devices/mojo/input_device_struct_traits.h b/ui/events/devices/mojo/input_device_struct_traits.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..354189024a6cb76ea233aa8744f5d116a82c5d03
|
| --- /dev/null
|
| +++ b/ui/events/devices/mojo/input_device_struct_traits.h
|
| @@ -0,0 +1,81 @@
|
| +// 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 UI_EVENTS_DEVICES_MOJO_INPUT_DEVICE_STRUCT_TRAITS_H_
|
| +#define UI_EVENTS_DEVICES_MOJO_INPUT_DEVICE_STRUCT_TRAITS_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/strings/string_piece.h"
|
| +#include "ui/events/devices/input_device.h"
|
| +#include "ui/events/devices/mojo/input_devices.mojom.h"
|
| +
|
| +namespace mojo {
|
| +
|
| +template <>
|
| +struct StructTraits<ui::mojom::InputDevice, ui::InputDevice> {
|
| + static int32_t id(const ui::InputDevice& device) { return device.id; }
|
| +
|
| + static ui::mojom::InputDeviceType type(const ui::InputDevice& device) {
|
| + switch (device.type) {
|
| + case ui::INPUT_DEVICE_INTERNAL:
|
| + return ui::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL;
|
| + case ui::INPUT_DEVICE_EXTERNAL:
|
| + return ui::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL;
|
| + case ui::INPUT_DEVICE_UNKNOWN:
|
| + return ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
|
| + }
|
| + }
|
| +
|
| + static const std::string& name(const ui::InputDevice& device) {
|
| + return device.name;
|
| + }
|
| +
|
| + static base::StringPiece sys_path(const ui::InputDevice& device) {
|
| + return device.sys_path.AsUTF8Unsafe();
|
| + }
|
| +
|
| + static uint32_t vendor_id(const ui::InputDevice& device) {
|
| + return device.vendor_id;
|
| + }
|
| +
|
| + static uint32_t product_id(const ui::InputDevice& device) {
|
| + return device.product_id;
|
| + }
|
| +
|
| + static bool Read(ui::mojom::InputDeviceDataView data, ui::InputDevice* out) {
|
| + out->id = data.id();
|
| +
|
| + switch (data.type()) {
|
| + case ui::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL:
|
| + out->type = ui::INPUT_DEVICE_INTERNAL;
|
| + break;
|
| + case ui::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL:
|
| + out->type = ui::INPUT_DEVICE_EXTERNAL;
|
| + break;
|
| + case ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN:
|
| + out->type = ui::INPUT_DEVICE_UNKNOWN;
|
| + break;
|
| + default:
|
| + return false;
|
| + }
|
| +
|
| + if (!data.ReadName(&out->name))
|
| + return false;
|
| +
|
| + base::StringPiece sys_path_string;
|
| + if (!data.ReadSysPath(&sys_path_string))
|
| + return false;
|
| + out->sys_path = base::FilePath::FromUTF8Unsafe(sys_path_string);
|
| +
|
| + out->vendor_id = data.vendor_id();
|
| + out->product_id = data.product_id();
|
| +
|
| + return true;
|
| + }
|
| +};
|
| +
|
| +} // namespace mojo
|
| +
|
| +#endif // UI_EVENTS_DEVICES_MOJO_INPUT_DEVICE_STRUCT_TRAITS_H_
|
|
|