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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/devices/mojo/input_device_struct_traits.cc
diff --git a/ui/events/devices/mojo/input_device_struct_traits.cc b/ui/events/devices/mojo/input_device_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..afab8208d5c42f1df702a70bbac4678a8d1c00b3
--- /dev/null
+++ b/ui/events/devices/mojo/input_device_struct_traits.cc
@@ -0,0 +1,83 @@
+// 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.
+
+#include "ui/events/devices/mojo/input_device_struct_traits.h"
+
+#include "base/logging.h"
+#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
+
+namespace mojo {
+
+ui::mojom::InputDeviceType
+EnumTraits<ui::mojom::InputDeviceType, ui::InputDeviceType>::ToMojom(
+ ui::InputDeviceType type) {
+ switch (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;
+ }
+ NOTREACHED();
+ return ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN;
+}
+
+bool EnumTraits<ui::mojom::InputDeviceType, ui::InputDeviceType>::FromMojom(
+ ui::mojom::InputDeviceType type,
+ ui::InputDeviceType* output) {
+ switch (type) {
+ case ui::mojom::InputDeviceType::INPUT_DEVICE_INTERNAL:
+ *output = ui::INPUT_DEVICE_INTERNAL;
+ break;
+ case ui::mojom::InputDeviceType::INPUT_DEVICE_EXTERNAL:
+ *output = ui::INPUT_DEVICE_EXTERNAL;
+ break;
+ case ui::mojom::InputDeviceType::INPUT_DEVICE_UNKNOWN:
+ *output = ui::INPUT_DEVICE_UNKNOWN;
+ break;
+ default:
+ // Who knows what values might come over the wire, fail if invalid.
+ return false;
+ }
+ return true;
+}
+
+bool StructTraits<ui::mojom::InputDevice, ui::InputDevice>::Read(
+ ui::mojom::InputDeviceDataView data,
+ ui::InputDevice* out) {
+ out->id = data.id();
+
+ if (!data.ReadType(&out->type))
+ 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;
+}
+
+bool StructTraits<ui::mojom::TouchscreenDevice, ui::TouchscreenDevice>::Read(
+ ui::mojom::TouchscreenDeviceDataView data,
+ ui::TouchscreenDevice* out) {
+ if (!data.ReadInputDevice(static_cast<ui::InputDevice*>(out)))
+ return false;
+
+ if (!data.ReadSize(&out->size))
+ return false;
+
+ out->touch_points = data.touch_points();
+
+ return true;
+}
+
+} // namespace mojo
« 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