• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_
7 
8 #include "base/strings/string_piece.h"
9 #include "content/common/gamepad_hardware_buffer.h"
10 
11 namespace content {
12 
13 typedef void (*GamepadStandardMappingFunction)(
14     const blink::WebGamepad& original,
15     blink::WebGamepad* mapped);
16 
17 GamepadStandardMappingFunction GetGamepadStandardMappingFunction(
18     const base::StringPiece& vendor_id,
19     const base::StringPiece& product_id);
20 
21 // This defines our canonical mapping order for gamepad-like devices. If these
22 // items cannot all be satisfied, it is a case-by-case judgement as to whether
23 // it is better to leave the device unmapped, or to partially map it. In
24 // general, err towards leaving it *unmapped* so that content can handle
25 // appropriately.
26 
27 enum CanonicalButtonIndex {
28   kButtonPrimary,
29   kButtonSecondary,
30   kButtonTertiary,
31   kButtonQuaternary,
32   kButtonLeftShoulder,
33   kButtonRightShoulder,
34   kButtonLeftTrigger,
35   kButtonRightTrigger,
36   kButtonBackSelect,
37   kButtonStart,
38   kButtonLeftThumbstick,
39   kButtonRightThumbstick,
40   kButtonDpadUp,
41   kButtonDpadDown,
42   kButtonDpadLeft,
43   kButtonDpadRight,
44   kButtonMeta,
45   kNumButtons
46 };
47 
48 enum CanonicalAxisIndex {
49   kAxisLeftStickX,
50   kAxisLeftStickY,
51   kAxisRightStickX,
52   kAxisRightStickY,
53   kNumAxes
54 };
55 
56 // Matches XInput's trigger deadzone
57 const float kDefaultButtonPressedThreshold = 30.f/255.f;
58 
59 // Common mapping functions
60 blink::WebGamepadButton AxisToButton(float input);
61 blink::WebGamepadButton AxisNegativeAsButton(float input);
62 blink::WebGamepadButton AxisPositiveAsButton(float input);
63 blink::WebGamepadButton ButtonFromButtonAndAxis(
64     blink::WebGamepadButton button, float axis);
65 void DpadFromAxis(blink::WebGamepad* mapped, float dir);
66 
67 }  // namespace content
68 
69 #endif  // CONTENT_BROWSER_GAMEPAD_GAMEPAD_STANDARD_MAPPINGS_H_
70