Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / gamepad / gamepad_standard_mappings_win.cc
blobbfd1dfaba0a2d146df167b40beb6b2aac61a678d
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 MapperLogitechDualAction(const blink::WebGamepad& input,
12 blink::WebGamepad* mapped) {
13 *mapped = input;
14 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
15 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
16 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
17 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
18 DpadFromAxis(mapped, input.axes[9]);
20 mapped->buttonsLength = BUTTON_INDEX_COUNT;
21 mapped->axesLength = AXIS_INDEX_COUNT;
24 void Mapper2Axes8Keys(const blink::WebGamepad& input,
25 blink::WebGamepad* mapped) {
26 *mapped = input;
27 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[2];
28 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
29 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
30 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[0];
31 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
32 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
33 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
34 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
35 AxisPositiveAsButton(input.axes[0]);
37 // Missing buttons
38 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = blink::WebGamepadButton();
39 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = blink::WebGamepadButton();
40 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = blink::WebGamepadButton();
41 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = blink::WebGamepadButton();
42 mapped->buttons[BUTTON_INDEX_META] = blink::WebGamepadButton();
44 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1;
45 mapped->axesLength = 0;
48 void MapperDualshock4(const blink::WebGamepad& input,
49 blink::WebGamepad* mapped) {
50 enum Dualshock4Buttons {
51 DUALSHOCK_BUTTON_TOUCHPAD = BUTTON_INDEX_COUNT,
52 DUALSHOCK_BUTTON_COUNT
55 *mapped = input;
56 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
57 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[2];
58 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[0];
59 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[3];
60 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[4];
61 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[5];
62 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[3]);
63 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[4]);
64 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[8];
65 mapped->buttons[BUTTON_INDEX_START] = input.buttons[9];
66 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[10];
67 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[11];
68 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
69 mapped->buttons[DUALSHOCK_BUTTON_TOUCHPAD] = input.buttons[13];
70 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
71 DpadFromAxis(mapped, input.axes[9]);
73 mapped->buttonsLength = DUALSHOCK_BUTTON_COUNT;
74 mapped->axesLength = AXIS_INDEX_COUNT;
77 void MapperIBuffalo(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
78 *mapped = input;
79 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[1];
80 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[0];
81 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
82 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[2];
83 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[6];
84 mapped->buttons[BUTTON_INDEX_START] = input.buttons[7];
85 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = input.buttons[4];
86 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = input.buttons[5];
87 mapped->buttons[BUTTON_INDEX_DPAD_UP] = AxisNegativeAsButton(input.axes[1]);
88 mapped->buttons[BUTTON_INDEX_DPAD_DOWN] = AxisPositiveAsButton(input.axes[1]);
89 mapped->buttons[BUTTON_INDEX_DPAD_LEFT] = AxisNegativeAsButton(input.axes[0]);
90 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT] =
91 AxisPositiveAsButton(input.axes[0]);
92 mapped->buttonsLength = BUTTON_INDEX_COUNT - 1; /* no meta */
93 mapped->axesLength = 2;
96 void MapperOnLiveWireless(const blink::WebGamepad& input,
97 blink::WebGamepad* mapped) {
98 *mapped = input;
99 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
100 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
101 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
102 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
103 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
104 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
105 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[2]);
106 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[5]);
107 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = input.buttons[10];
108 mapped->buttons[BUTTON_INDEX_START] = input.buttons[11];
109 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
110 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
111 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
112 mapped->axes[AXIS_INDEX_RIGHT_STICK_X] = input.axes[3];
113 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[4];
114 DpadFromAxis(mapped, input.axes[9]);
116 mapped->buttonsLength = BUTTON_INDEX_COUNT;
117 mapped->axesLength = AXIS_INDEX_COUNT;
120 void MapperADT1(const blink::WebGamepad& input, blink::WebGamepad* mapped) {
121 *mapped = input;
122 mapped->buttons[BUTTON_INDEX_PRIMARY] = input.buttons[0];
123 mapped->buttons[BUTTON_INDEX_SECONDARY] = input.buttons[1];
124 mapped->buttons[BUTTON_INDEX_TERTIARY] = input.buttons[3];
125 mapped->buttons[BUTTON_INDEX_QUATERNARY] = input.buttons[4];
126 mapped->buttons[BUTTON_INDEX_LEFT_SHOULDER] = input.buttons[6];
127 mapped->buttons[BUTTON_INDEX_RIGHT_SHOULDER] = input.buttons[7];
128 mapped->buttons[BUTTON_INDEX_LEFT_TRIGGER] = AxisToButton(input.axes[4]);
129 mapped->buttons[BUTTON_INDEX_RIGHT_TRIGGER] = AxisToButton(input.axes[3]);
130 mapped->buttons[BUTTON_INDEX_BACK_SELECT] = NullButton();
131 mapped->buttons[BUTTON_INDEX_START] = NullButton();
132 mapped->buttons[BUTTON_INDEX_LEFT_THUMBSTICK] = input.buttons[13];
133 mapped->buttons[BUTTON_INDEX_RIGHT_THUMBSTICK] = input.buttons[14];
134 mapped->buttons[BUTTON_INDEX_META] = input.buttons[12];
135 mapped->axes[AXIS_INDEX_RIGHT_STICK_Y] = input.axes[5];
136 DpadFromAxis(mapped, input.axes[9]);
138 mapped->buttonsLength = BUTTON_INDEX_COUNT;
139 mapped->axesLength = AXIS_INDEX_COUNT;
142 struct MappingData {
143 const char* const vendor_id;
144 const char* const product_id;
145 GamepadStandardMappingFunction function;
146 } AvailableMappings[] = {
147 // http://www.linux-usb.org/usb.ids
148 {"0079", "0011", Mapper2Axes8Keys}, // 2Axes 8Keys Game Pad
149 {"046d", "c216", MapperLogitechDualAction}, // Logitech DualAction
150 {"054c", "05c4", MapperDualshock4}, // Playstation Dualshock 4
151 {"0583", "2060", MapperIBuffalo}, // iBuffalo Classic
152 {"18d1", "2c40", MapperADT1}, // ADT-1 Controller
153 {"2378", "1008", MapperOnLiveWireless}, // OnLive Controller (Bluetooth)
154 {"2378", "100a", MapperOnLiveWireless}, // OnLive Controller (Wired)
157 } // namespace
159 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
160 const base::StringPiece& vendor_id,
161 const base::StringPiece& product_id) {
162 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) {
163 MappingData& item = AvailableMappings[i];
164 if (vendor_id == item.vendor_id && product_id == item.product_id)
165 return item.function;
167 return NULL;
170 } // namespace content