OLD | NEW |
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 <memory> |
| 9 |
8 #include "ui/events/ozone/gamepad/webgamepad_constants.h" | 10 #include "ui/events/ozone/gamepad/webgamepad_constants.h" |
9 | 11 |
10 namespace ui { | 12 namespace ui { |
11 | 13 |
| 14 class EventDeviceInfo; |
| 15 |
12 // The following HATX and HATY is not part of web gamepad definition, but we | 16 // 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 | 17 // 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. | 18 // DPAD_DOWN, and HAT_X can be mapped to DAPD_LEFT or DPAD_RIGHT. |
15 constexpr int kHAT_X = 4; | 19 constexpr int kHAT_X = 4; |
16 constexpr int kHAT_Y = 5; | 20 constexpr int kHAT_Y = 5; |
17 | 21 |
18 typedef bool (*GamepadMapper)(uint16_t key, | 22 // KeyMap maps evdev key code to web gamepad code. |
19 uint16_t code, | 23 struct KeyMapEntry { |
20 GamepadEventType* mapped_type, | 24 uint16_t evdev_code; |
21 uint16_t* mapped_code); | 25 uint16_t mapped_code; |
| 26 }; |
| 27 |
| 28 // AbsMap maps evdev abs code to web gamepad (type, code). |
| 29 struct AbsMapEntry { |
| 30 uint16_t evdev_code; |
| 31 GamepadEventType mapped_type; |
| 32 uint16_t mapped_code; |
| 33 }; |
| 34 |
| 35 using KeyMapType = const KeyMapEntry[]; |
| 36 using AbsMapType = const AbsMapEntry[]; |
| 37 |
| 38 #define TO_BTN(code, mapped_code) \ |
| 39 { code, GamepadEventType::BUTTON, mapped_code } |
| 40 |
| 41 #define TO_ABS(code, mapped_code) \ |
| 42 { code, GamepadEventType::AXIS, mapped_code } |
| 43 |
| 44 class GamepadMapper { |
| 45 public: |
| 46 virtual bool Map(uint16_t key, |
| 47 uint16_t code, |
| 48 GamepadEventType* mapped_type, |
| 49 uint16_t* mapped_code) const = 0; |
| 50 |
| 51 virtual ~GamepadMapper() {} |
| 52 }; |
22 | 53 |
23 // This function gets the best mapper for the gamepad vendor_id and product_id. | 54 // 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); | 55 std::unique_ptr<GamepadMapper> GetGamepadMapper(const EventDeviceInfo& devinfo); |
25 | 56 |
26 } // namespace ui | 57 } // namespace ui |
27 | 58 |
28 #endif // UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_ | 59 #endif // UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_MAPPING_H_ |
OLD | NEW |