1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_GamepadRemapping_h_
8 #define mozilla_dom_GamepadRemapping_h_
10 #include "mozilla/dom/GamepadBinding.h"
11 #include "mozilla/dom/GamepadLightIndicator.h"
12 #include "mozilla/dom/GamepadPoseState.h"
13 #include "mozilla/dom/GamepadTouchState.h"
15 namespace mozilla::dom
{
17 // GamepadId is (vendorId << 16) | productId)
18 enum class GamepadId
: uint32_t {
19 // Nexus Player Controller
20 kAsusTekProduct4500
= 0x0b054500,
21 // 2Axes 8Keys Game Pad
22 kDragonRiseProduct0011
= 0x00790011,
24 kGoogleProduct2c40
= 0x18d12c40,
26 kGoogleProduct9400
= 0x18d19400,
27 // Logitech F310, D-mode
28 kLogitechProductc216
= 0x046dc216,
29 // Logitech F510, D-mode
30 kLogitechProductc218
= 0x046dc218,
31 // Logitech F710, D-mode
32 kLogitechProductc219
= 0x046dc219,
34 kMicrosoftProductXbox360
= 0x045e028e,
35 // Microsoft Xbox 360 Wireless
36 kMicrosoftProductXbox360Wireless
= 0x045e028f,
37 // Microsoft Xbox 360 Wireless
38 kMicrosoftProductXbox360Wireless2
= 0x045e0719,
39 // Microsoft Xbox One 2013
40 kMicrosoftProductXbox2013
= 0x045e02d1,
41 // Microsoft Xbox One (2015 FW)
42 kMicrosoftProductXbox2015
= 0x045e02dd,
43 // Microsoft Xbox One S
44 kMicrosoftProductXboxOneS
= 0x045e02ea,
45 // Microsoft Xbox One S Wireless
46 kMicrosoftProductXboxOneSWireless
= 0x045e02e0,
47 // Microsoft Xbox One Elite
48 kMicrosoftProductXboxOneElite
= 0x045e02e3,
49 // Microsoft Xbox One Elite 2
50 kMicrosoftProductXboxOneElite2
= 0x045e0b00,
51 // Microsoft Xbox One Elite 2 Wireless
52 kMicrosoftProductXboxOneElite2Wireless
= 0x045e0b05,
53 // Xbox One S Wireless (2016 FW)
54 kMicrosoftProductXboxOneSWireless2016
= 0x045e02fd,
55 // Microsoft Xbox Adaptive
56 kMicrosoftProductXboxAdaptive
= 0x045e0b0a,
57 // Microsoft Xbox Adaptive Wireless
58 kMicrosoftProductXboxAdaptiveWireless
= 0x045e0b0c,
60 kNintendoProduct2006
= 0x057e2006,
62 kNintendoProduct2007
= 0x057e2007,
63 // Switch Pro Controller
64 kNintendoProduct2009
= 0x057e2009,
65 // Switch Charging Grip
66 kNintendoProduct200e
= 0x057e200e,
67 // Nvidia Shield gamepad (2015)
68 kNvidiaProduct7210
= 0x09557210,
69 // Nvidia Shield gamepad (2017)
70 kNvidiaProduct7214
= 0x09557214,
72 kPadixProduct2060
= 0x05832060,
73 // XSkills Gamecube USB adapter
74 kPlayComProduct0005
= 0x0b430005,
75 // boom PSX+N64 USB Converter
76 kPrototypeVendorProduct0667
= 0x66660667,
77 // Analog game controller
78 kPrototypeVendorProduct9401
= 0x66669401,
79 // Razer Serval Controller
80 kRazer1532Product0900
= 0x15320900,
81 // Playstation 3 Controller
82 kSonyProduct0268
= 0x054c0268,
83 // Playstation Dualshock 4
84 kSonyProduct05c4
= 0x054c05c4,
85 // Dualshock 4 (PS4 Slim)
86 kSonyProduct09cc
= 0x054c09cc,
87 // Dualshock 4 USB receiver
88 kSonyProduct0ba0
= 0x054c0ba0,
89 // Moga Pro Controller (HID mode)
90 kVendor20d6Product6271
= 0x20d66271,
91 // OnLive Controller (Bluetooth)
92 kVendor2378Product1008
= 0x23781008,
93 // OnLive Controller (Wired)
94 kVendor2378Product100a
= 0x2378100a,
96 kVendor2836Product0001
= 0x28360001,
99 class GamepadRemapper
{
100 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GamepadRemapper
)
103 virtual uint32_t GetAxisCount() const = 0;
104 virtual uint32_t GetButtonCount() const = 0;
105 virtual uint32_t GetLightIndicatorCount() const { return 0; }
106 virtual void GetLightIndicators(
107 nsTArray
<GamepadLightIndicatorType
>& aTypes
) const {}
108 virtual uint32_t GetTouchEventCount() const { return 0; }
109 virtual void GetLightColorReport(uint8_t aRed
, uint8_t aGreen
, uint8_t aBlue
,
110 std::vector
<uint8_t>& aReport
) const {}
111 virtual uint32_t GetMaxInputReportLength() const { return 0; }
113 virtual void SetAxisCount(uint32_t aButtonCount
) {}
114 virtual void SetButtonCount(uint32_t aButtonCount
) {}
115 virtual GamepadMappingType
GetMappingType() const {
116 return GamepadMappingType::Standard
;
118 virtual void ProcessTouchData(GamepadHandle aHandle
, void* aInput
) {}
119 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
120 double aValue
) const = 0;
121 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
122 bool aPressed
) const = 0;
125 GamepadRemapper() = default;
126 virtual ~GamepadRemapper() = default;
129 struct GamepadRemappingData
{
131 RefPtr
<GamepadRemapper
> remapping
;
134 already_AddRefed
<GamepadRemapper
> GetGamepadRemapper(const uint16_t aVendorId
,
135 const uint16_t aProductId
,
136 bool& aUsingDefault
);
138 } // namespace mozilla::dom
140 #endif // mozilla_dom_GamepadRemapping_h_