Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / gamepad / gamepad_standard_mappings_linux.cc
blob86c3afde8a15399e136b0f8c5f8ea1a59d8ec515
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/gamepad/gamepad_standard_mappings.h"
7 namespace content {
9 namespace {
11 void MapperXInputStyleGamepad(
12 const blink::WebGamepad& input,
13 blink::WebGamepad* mapped) {
14 *mapped = input;
15 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]);
16 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]);
17 mapped->buttons[kButtonBackSelect] = input.buttons[6];
18 mapped->buttons[kButtonStart] = input.buttons[7];
19 mapped->buttons[kButtonLeftThumbstick] = input.buttons[9];
20 mapped->buttons[kButtonRightThumbstick] = input.buttons[10];
21 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[7]);
22 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[7]);
23 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[6]);
24 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[6]);
25 mapped->buttons[kButtonMeta] = input.buttons[8];
26 mapped->axes[kAxisRightStickX] = input.axes[3];
27 mapped->axes[kAxisRightStickY] = input.axes[4];
28 mapped->buttonsLength = kNumButtons;
29 mapped->axesLength = kNumAxes;
32 void MapperLakeviewResearch(
33 const blink::WebGamepad& input,
34 blink::WebGamepad* mapped) {
35 *mapped = input;
36 mapped->buttons[kButtonPrimary] = input.buttons[2];
37 mapped->buttons[kButtonTertiary] = input.buttons[3];
38 mapped->buttons[kButtonQuaternary] = input.buttons[0];
39 mapped->buttons[kButtonLeftShoulder] = input.buttons[6];
40 mapped->buttons[kButtonRightShoulder] = input.buttons[7];
41 mapped->buttons[kButtonLeftTrigger] = input.buttons[4];
42 mapped->buttons[kButtonRightTrigger] = input.buttons[5];
43 mapped->buttons[kButtonBackSelect] = input.buttons[9];
44 mapped->buttons[kButtonStart] = input.buttons[8];
45 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]);
46 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]);
47 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]);
48 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]);
49 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device
50 mapped->axesLength = kNumAxes;
53 void MapperPlaystationSixAxis(
54 const blink::WebGamepad& input,
55 blink::WebGamepad* mapped) {
56 *mapped = input;
57 mapped->buttons[kButtonPrimary] = input.buttons[14];
58 mapped->buttons[kButtonSecondary] = input.buttons[13];
59 mapped->buttons[kButtonTertiary] = input.buttons[15];
60 mapped->buttons[kButtonQuaternary] = input.buttons[12];
61 mapped->buttons[kButtonLeftShoulder] = input.buttons[10];
62 mapped->buttons[kButtonRightShoulder] = input.buttons[11];
63 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[12]);
64 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[13]);
65 mapped->buttons[kButtonBackSelect] = input.buttons[0];
66 mapped->buttons[kButtonStart] = input.buttons[3];
67 mapped->buttons[kButtonLeftThumbstick] = input.buttons[1];
68 mapped->buttons[kButtonRightThumbstick] = input.buttons[2];
69 mapped->buttons[kButtonDpadUp] = AxisToButton(input.axes[8]);
70 mapped->buttons[kButtonDpadDown] = AxisToButton(input.axes[10]);
71 mapped->buttons[kButtonDpadLeft] = input.buttons[7];
72 mapped->buttons[kButtonDpadRight] = AxisToButton(input.axes[9]);
73 mapped->buttons[kButtonMeta] = input.buttons[16];
75 mapped->buttonsLength = kNumButtons;
76 mapped->axesLength = kNumAxes;
79 void MapperDualshock4(
80 const blink::WebGamepad& input,
81 blink::WebGamepad* mapped) {
82 enum Dualshock4Buttons {
83 kTouchpadButton = kNumButtons,
84 kNumDualshock4Buttons
87 *mapped = input;
88 mapped->buttons[kButtonPrimary] = input.buttons[1];
89 mapped->buttons[kButtonSecondary] = input.buttons[2];
90 mapped->buttons[kButtonTertiary] = input.buttons[0];
91 mapped->buttons[kButtonQuaternary] = input.buttons[3];
92 mapped->buttons[kButtonLeftShoulder] = input.buttons[4];
93 mapped->buttons[kButtonRightShoulder] = input.buttons[5];
94 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[3]);
95 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[4]);
96 mapped->buttons[kButtonBackSelect] = input.buttons[8];
97 mapped->buttons[kButtonStart] = input.buttons[9];
98 mapped->buttons[kButtonLeftThumbstick] = input.buttons[10];
99 mapped->buttons[kButtonRightThumbstick] = input.buttons[11];
100 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[7]);
101 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[7]);
102 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[6]);
103 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[6]);
104 mapped->buttons[kButtonMeta] = input.buttons[12];
105 mapped->buttons[kTouchpadButton] = input.buttons[13];
106 mapped->axes[kAxisRightStickY] = input.axes[5];
108 mapped->buttonsLength = kNumDualshock4Buttons;
109 mapped->axesLength = kNumAxes;
112 void MapperXGEAR(
113 const blink::WebGamepad& input,
114 blink::WebGamepad* mapped) {
115 *mapped = input;
116 mapped->buttons[kButtonPrimary] = input.buttons[2];
117 mapped->buttons[kButtonSecondary] = input.buttons[1];
118 mapped->buttons[kButtonTertiary] = input.buttons[3];
119 mapped->buttons[kButtonQuaternary] = input.buttons[0];
120 mapped->buttons[kButtonLeftShoulder] = input.buttons[6];
121 mapped->buttons[kButtonRightShoulder] = input.buttons[7];
122 mapped->buttons[kButtonLeftTrigger] = input.buttons[4];
123 mapped->buttons[kButtonRightTrigger] = input.buttons[5];
124 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[5]);
125 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[5]);
126 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[4]);
127 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[4]);
128 mapped->axes[kAxisRightStickX] = input.axes[3];
129 mapped->axes[kAxisRightStickY] = input.axes[2];
130 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device
131 mapped->axesLength = kNumAxes;
135 void MapperDragonRiseGeneric(
136 const blink::WebGamepad& input,
137 blink::WebGamepad* mapped) {
138 *mapped = input;
139 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[6]);
140 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[6]);
141 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[5]);
142 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[5]);
143 mapped->axes[kAxisLeftStickX] = input.axes[0];
144 mapped->axes[kAxisLeftStickY] = input.axes[1];
145 mapped->axes[kAxisRightStickX] = input.axes[3];
146 mapped->axes[kAxisRightStickY] = input.axes[4];
147 mapped->buttonsLength = kNumButtons - 1; // no Meta on this device
148 mapped->axesLength = kNumAxes;
151 void MapperOnLiveWireless(
152 const blink::WebGamepad& input,
153 blink::WebGamepad* mapped) {
154 *mapped = input;
155 mapped->buttons[kButtonLeftTrigger] = AxisToButton(input.axes[2]);
156 mapped->buttons[kButtonRightTrigger] = AxisToButton(input.axes[5]);
157 mapped->buttons[kButtonBackSelect] = input.buttons[6];
158 mapped->buttons[kButtonStart] = input.buttons[7];
159 mapped->buttons[kButtonLeftThumbstick] = input.buttons[9];
160 mapped->buttons[kButtonRightThumbstick] = input.buttons[10];
161 mapped->buttons[kButtonDpadUp] = AxisNegativeAsButton(input.axes[7]);
162 mapped->buttons[kButtonDpadDown] = AxisPositiveAsButton(input.axes[7]);
163 mapped->buttons[kButtonDpadLeft] = AxisNegativeAsButton(input.axes[6]);
164 mapped->buttons[kButtonDpadRight] = AxisPositiveAsButton(input.axes[6]);
165 mapped->buttons[kButtonMeta] = input.buttons[8];
166 mapped->axes[kAxisRightStickX] = input.axes[3];
167 mapped->axes[kAxisRightStickY] = input.axes[4];
169 mapped->buttonsLength = kNumButtons;
170 mapped->axesLength = kNumAxes;
174 struct MappingData {
175 const char* const vendor_id;
176 const char* const product_id;
177 GamepadStandardMappingFunction function;
178 } AvailableMappings[] = {
179 // http://www.linux-usb.org/usb.ids
180 { "0079", "0006", MapperDragonRiseGeneric }, // DragonRise Generic USB
181 { "045e", "028e", MapperXInputStyleGamepad }, // Xbox 360 Controller
182 { "045e", "028f", MapperXInputStyleGamepad }, // Xbox 360 Wireless Controller
183 { "046d", "c21d", MapperXInputStyleGamepad }, // Logitech F310
184 { "046d", "c21e", MapperXInputStyleGamepad }, // Logitech F510
185 { "046d", "c21f", MapperXInputStyleGamepad }, // Logitech F710
186 { "054c", "0268", MapperPlaystationSixAxis }, // Playstation SIXAXIS
187 { "054c", "05c4", MapperDualshock4 }, // Playstation Dualshock 4
188 { "0925", "0005", MapperLakeviewResearch }, // SmartJoy PLUS Adapter
189 { "0925", "8866", MapperLakeviewResearch }, // WiseGroup MP-8866
190 { "0e8f", "0003", MapperXGEAR }, // XFXforce XGEAR PS2 Controller
191 { "2378", "1008", MapperOnLiveWireless }, // OnLive Controller (Bluetooth)
192 { "2378", "100a", MapperOnLiveWireless }, // OnLive Controller (Wired)
195 } // namespace
197 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
198 const base::StringPiece& vendor_id,
199 const base::StringPiece& product_id) {
200 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
201 MappingData& item = AvailableMappings[i];
202 if (vendor_id == item.vendor_id && product_id == item.product_id)
203 return item.function;
205 return NULL;
208 } // namespace content