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

Side by Side Diff: components/mus/input_devices/touchscreen_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/move. 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_TOUCHSCREEN_DEVICE_STRUCT_TRAITS_H_
6 #define COMPONENTS_MUS_INPUT_DEVICES_TOUCHSCREEN_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/touchscreen_device.h"
13 #include "ui/gfx/geometry/size.h"
14
15 namespace mojo {
16
17 template <>
18 struct StructTraits<input_device::mojom::TouchscreenDevice,
19 ui::TouchscreenDevice> {
20 static int32_t id(const ui::TouchscreenDevice& device) { return device.id; }
21
22 static input_device::mojom::InputDeviceType type(
23 const ui::TouchscreenDevice& device) {
24 switch (device.type) {
25 case ui::INPUT_DEVICE_INTERNAL:
26 return input_device::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL;
27 case ui::INPUT_DEVICE_EXTERNAL:
28 return input_device::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL;
29 case ui::INPUT_DEVICE_UNKNOWN:
30 return input_device::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
31 }
32 }
33
34 static std::string name(const ui::TouchscreenDevice& device) {
35 return device.name;
36 }
37
38 static base::StringPiece sys_path(const ui::TouchscreenDevice& device) {
39 return device.sys_path.AsUTF8Unsafe();
40 }
41
42 static uint32_t vendor_id(const ui::TouchscreenDevice& device) {
43 return device.vendor_id;
44 }
45
46 static uint32_t product_id(const ui::TouchscreenDevice& device) {
47 return device.product_id;
48 }
49
50 static gfx::Size size(const ui::TouchscreenDevice& device) {
51 return device.size;
52 }
53
54 static int32_t touch_points(const ui::TouchscreenDevice& device) {
55 return device.touch_points;
56 }
57
58 static bool Read(input_device::mojom::TouchscreenDeviceDataView data,
59 ui::TouchscreenDevice* out) {
60 out->id = data.id();
61
62 switch (data.type()) {
63 case input_device::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL:
64 out->type = ui::INPUT_DEVICE_INTERNAL;
65 break;
66 case input_device::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL:
67 out->type = ui::INPUT_DEVICE_EXTERNAL;
68 break;
69 case input_device::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN:
70 out->type = ui::INPUT_DEVICE_UNKNOWN;
71 break;
72 default:
73 return false;
74 }
75
76 if (!data.ReadName(&out->name))
77 return false;
78
79 base::StringPiece sys_path_string;
80 if (!data.ReadSysPath(&sys_path_string))
81 return false;
82 out->sys_path = base::FilePath::FromUTF8Unsafe(sys_path_string);
83
84 out->vendor_id = data.vendor_id();
85 out->product_id = data.product_id();
86
87 if (!data.ReadSize(&out->size))
88 return false;
89
90 out->touch_points = data.touch_points();
91
92 return true;
93 }
94 };
95
96 } // namespace mojo
97
98 #endif // COMPONENTS_MUS_INPUT_DEVICES_TOUCHSCREEN_DEVICE_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698