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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_ 5 #ifndef UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_
6 #define UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_ 6 #define UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_
7 7
8 #include "ui/events/ozone/gamepad/webgamepad_constants.h" 8 #include "ui/events/ozone/gamepad/webgamepad_constants.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 class EventDeviceInfo;
13
12 // The following HATX and HATY is not part of web gamepad definition, but we 14 // The following HATX and HATY is not part of web gamepad definition, but we
13 // need to specially treat them cause HAT_Y can be mapped to DPAD_UP or 15 // need to specially treat them cause HAT_Y can be mapped to DPAD_UP or
14 // DPAD_DOWN, and HAT_X can be mapped to DAPD_LEFT or DPAD_RIGHT. 16 // DPAD_DOWN, and HAT_X can be mapped to DAPD_LEFT or DPAD_RIGHT.
15 constexpr int kHAT_X = 4; 17 constexpr int kHAT_X = 4;
16 constexpr int kHAT_Y = 5; 18 constexpr int kHAT_Y = 5;
17 19
18 typedef bool (*GamepadMapper)(uint16_t key, 20 // KeyMap maps evdev key code to web gamepad code.
19 uint16_t code, 21 struct KeyMapEntry {
20 GamepadEventType* mapped_type, 22 uint16_t evdev_code;
21 uint16_t* mapped_code); 23 uint16_t mapped_code;
24 };
25
26 // AbsMap maps evdev abs code to web gamepad (type, code).
27 struct AbsMapEntry {
28 uint16_t evdev_code;
29 GamepadEventType mapped_type;
30 uint16_t mapped_code;
31 };
32
33 using KeyMapType = const KeyMapEntry[];
34 using AbsMapType = const AbsMapEntry[];
35
36 #define TO_BTN(code, mapped_code) \
37 { code, GamepadEventType::BUTTON, mapped_code }
38
39 #define TO_ABS(code, mapped_code) \
40 { code, GamepadEventType::AXIS, mapped_code }
41
42 class GamepadMapper {
43 public:
44 virtual bool operator()(uint16_t key,
45 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.
46 GamepadEventType* mapped_type,
47 uint16_t* mapped_code) = 0;
48 virtual ~GamepadMapper() {}
49 };
22 50
23 // This function gets the best mapper for the gamepad vendor_id and product_id. 51 // This function gets the best mapper for the gamepad vendor_id and product_id.
24 GamepadMapper GetGamepadMapper(uint16_t vendor_id, uint16_t product_id); 52 GamepadMapper* GetGamepadMapper(const EventDeviceInfo& devinfo);
25 53
26 } // namespace ui 54 } // namespace ui
27 55
28 #endif // UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_ 56 #endif // UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698