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

Side by Side Diff: ui/events/devices/mojo/input_device_struct_traits.cc

Issue 2069823004: Fix InputDevice StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_device
Patch Set: Run gn format. 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 #include "ui/events/devices/mojo/input_device_struct_traits.h"
6
7 #include "base/logging.h"
8 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
9
10 namespace mojo {
11
12 ui::mojom::InputDeviceType
13 EnumTraits<ui::mojom::InputDeviceType, ui::InputDeviceType>::ToMojom(
14 ui::InputDeviceType type) {
15 switch (type) {
16 case ui::INPUT_DEVICE_INTERNAL:
17 return ui::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL;
18 case ui::INPUT_DEVICE_EXTERNAL:
19 return ui::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL;
20 case ui::INPUT_DEVICE_UNKNOWN:
21 return ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
22 }
23 NOTREACHED();
24 return ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
25 }
26
27 bool EnumTraits<ui::mojom::InputDeviceType, ui::InputDeviceType>::FromMojom(
28 ui::mojom::InputDeviceType type,
29 ui::InputDeviceType* output) {
30 switch (type) {
31 case ui::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL:
32 *output = ui::INPUT_DEVICE_INTERNAL;
33 break;
34 case ui::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL:
35 *output = ui::INPUT_DEVICE_EXTERNAL;
36 break;
37 case ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN:
38 *output = ui::INPUT_DEVICE_UNKNOWN;
39 break;
40 default:
41 // Who knows what values might come over the wire, fail if invalid.
42 return false;
43 }
44 return true;
45 }
46
47 bool StructTraits<ui::mojom::InputDevice, ui::InputDevice>::Read(
48 ui::mojom::InputDeviceDataView data,
49 ui::InputDevice* out) {
50 out->id = data.id();
51
52 if (!data.ReadType(&out->type))
53 return false;
54
55 if (!data.ReadName(&out->name))
56 return false;
57
58 base::StringPiece sys_path_string;
59 if (!data.ReadSysPath(&sys_path_string))
60 return false;
61 out->sys_path = base::FilePath::FromUTF8Unsafe(sys_path_string);
62
63 out->vendor_id = data.vendor_id();
64 out->product_id = data.product_id();
65
66 return true;
67 }
68
69 bool StructTraits<ui::mojom::TouchscreenDevice, ui::TouchscreenDevice>::Read(
70 ui::mojom::TouchscreenDeviceDataView data,
71 ui::TouchscreenDevice* out) {
72 if (!data.ReadInputDevice(static_cast<ui::InputDevice*>(out)))
73 return false;
74
75 if (!data.ReadSize(&out->size))
76 return false;
77
78 out->touch_points = data.touch_points();
79
80 return true;
81 }
82
83 } // namespace mojo
OLDNEW
« no previous file with comments | « ui/events/devices/mojo/input_device_struct_traits.h ('k') | ui/events/devices/mojo/touchscreen_device.typemap » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698