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

Side by Side Diff: components/mus/input_devices/input_device_struct_traits.h

Issue 1992443002: Add Mojo IPC based input-device service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_ddm
Patch Set: Rebase/update. Created 4 years, 6 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
(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 COMPONENTS_MUS_INPUT_DEVICES_INPUT_DEVICE_STRUCT_TRAITS_H_
6 #define COMPONENTS_MUS_INPUT_DEVICES_INPUT_DEVICE_STRUCT_TRAITS_H_
7
8 #include <string>
9
10 #include "base/strings/string_piece.h"
11 #include "components/mus/public/interfaces/input_devices/input_devices.mojom.h"
12 #include "ui/events/devices/input_device.h"
13
14 namespace mojo {
15
16 template <>
17 struct StructTraits<input_device::mojom::InputDevice, ui::InputDevice> {
18 static int32_t id(const ui::InputDevice& device) { return device.id; }
19
20 static input_device::mojom::InputDeviceType type(
21 const ui::InputDevice& device) {
22 switch (device.type) {
23 case ui::INPUT_DEVICE_INTERNAL:
24 return input_device::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL;
25 case ui::INPUT_DEVICE_EXTERNAL:
26 return input_device::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL;
27 case ui::INPUT_DEVICE_UNKNOWN:
28 return input_device::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
29 }
30 }
31
32 static std::string name(const ui::InputDevice& device) { return device.name; }
sadrul 2016/06/07 03:39:25 Can the return type be const-ref in struct-traits?
kylechar 2016/06/07 16:36:41 I don't see why not. Done.
33
34 static base::StringPiece sys_path(const ui::InputDevice& device) {
35 return device.sys_path.AsUTF8Unsafe();
36 }
37
38 static uint32_t vendor_id(const ui::InputDevice& device) {
39 return device.vendor_id;
40 }
41
42 static uint32_t product_id(const ui::InputDevice& device) {
43 return device.product_id;
44 }
45
46 static bool Read(input_device::mojom::InputDeviceDataView data,
47 ui::InputDevice* out) {
48 out->id = data.id();
49
50 switch (data.type()) {
51 case input_device::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL:
52 out->type = ui::INPUT_DEVICE_INTERNAL;
53 break;
54 case input_device::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL:
55 out->type = ui::INPUT_DEVICE_EXTERNAL;
56 break;
57 case input_device::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN:
58 out->type = ui::INPUT_DEVICE_UNKNOWN;
59 break;
60 default:
sadrul 2016/06/07 03:39:25 Remove default case?
kylechar 2016/06/07 16:36:41 Do we want that? We can't necessarily control what
sadrul 2016/06/08 16:31:09 Hm, good point. I was going for the 'omit default:
61 return false;
62 }
63
64 if (!data.ReadName(&out->name))
65 return false;
66
67 base::StringPiece sys_path_string;
68 if (!data.ReadSysPath(&sys_path_string))
69 return false;
70 out->sys_path = base::FilePath::FromUTF8Unsafe(sys_path_string);
71
72 out->vendor_id = data.vendor_id();
73 out->product_id = data.product_id();
74
75 return true;
76 }
77 };
78
79 } // namespace mojo
80
81 #endif // COMPONENTS_MUS_INPUT_DEVICES_INPUT_DEVICE_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698