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

Unified Diff: ui/events/ozone/gamepad/gamepad_mapping.h

Issue 2899893003: Add generic mapping for gamepad (Closed)
Patch Set: Created 3 years, 7 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/ozone/gamepad/gamepad_mapping.h
diff --git a/ui/events/ozone/gamepad/gamepad_mapping.h b/ui/events/ozone/gamepad/gamepad_mapping.h
index e864e977e7ae4ff3ece2242e9d9a7749b21a6de3..14d508b48709f6cdcd6f4e78c3883065c175a9a4 100644
--- a/ui/events/ozone/gamepad/gamepad_mapping.h
+++ b/ui/events/ozone/gamepad/gamepad_mapping.h
@@ -9,19 +9,47 @@
namespace ui {
+class EventDeviceInfo;
+
// The following HATX and HATY is not part of web gamepad definition, but we
// need to specially treat them cause HAT_Y can be mapped to DPAD_UP or
// DPAD_DOWN, and HAT_X can be mapped to DAPD_LEFT or DPAD_RIGHT.
constexpr int kHAT_X = 4;
constexpr int kHAT_Y = 5;
-typedef bool (*GamepadMapper)(uint16_t key,
- uint16_t code,
- GamepadEventType* mapped_type,
- uint16_t* mapped_code);
+// KeyMap maps evdev key code to web gamepad code.
+struct KeyMapEntry {
+ uint16_t evdev_code;
+ uint16_t mapped_code;
+};
+
+// AbsMap maps evdev abs code to web gamepad (type, code).
+struct AbsMapEntry {
+ uint16_t evdev_code;
+ GamepadEventType mapped_type;
+ uint16_t mapped_code;
+};
+
+using KeyMapType = const KeyMapEntry[];
+using AbsMapType = const AbsMapEntry[];
+
+#define TO_BTN(code, mapped_code) \
+ { code, GamepadEventType::BUTTON, mapped_code }
+
+#define TO_ABS(code, mapped_code) \
+ { code, GamepadEventType::AXIS, mapped_code }
+
+class GamepadMapper {
+ public:
+ virtual bool operator()(uint16_t key,
+ uint16_t code,
spang 2017/06/01 05:08:12 overloading operator() is going to cause syntactic
jkwang 2017/06/02 22:03:51 Done.
+ GamepadEventType* mapped_type,
+ uint16_t* mapped_code) = 0;
+ virtual ~GamepadMapper() {}
+};
// This function gets the best mapper for the gamepad vendor_id and product_id.
-GamepadMapper GetGamepadMapper(uint16_t vendor_id, uint16_t product_id);
+GamepadMapper* GetGamepadMapper(const EventDeviceInfo& devinfo);
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698