| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
| 6 | 6 |
| 7 import android.view.KeyEvent; | 7 import android.view.KeyEvent; |
| 8 import android.view.MotionEvent; | 8 import android.view.MotionEvent; |
| 9 | 9 |
| 10 import org.chromium.base.JNINamespace; | 10 import org.chromium.base.JNINamespace; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 mapUnknownGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); | 39 mapUnknownGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); |
| 40 return false; | 40 return false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 private static void mapCommonXYABButtons(float[] mappedButtons, float[] rawB
uttons) { | 43 private static void mapCommonXYABButtons(float[] mappedButtons, float[] rawB
uttons) { |
| 44 float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A]; | 44 float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A]; |
| 45 float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B]; | 45 float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B]; |
| 46 float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X]; | 46 float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X]; |
| 47 float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; | 47 float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; |
| 48 mappedButtons[CanonicalButtonIndex.PRIMARY] = a; | 48 mappedButtons[CanonicalButtonIndex.BUTTON_PRIMARY] = a; |
| 49 mappedButtons[CanonicalButtonIndex.SECONDARY] = b; | 49 mappedButtons[CanonicalButtonIndex.BUTTON_SECONDARY] = b; |
| 50 mappedButtons[CanonicalButtonIndex.TERTIARY] = x; | 50 mappedButtons[CanonicalButtonIndex.BUTTON_TERTIARY] = x; |
| 51 mappedButtons[CanonicalButtonIndex.QUATERNARY] = y; | 51 mappedButtons[CanonicalButtonIndex.BUTTON_QUATERNARY] = y; |
| 52 } | 52 } |
| 53 | 53 |
| 54 private static void mapCommonStartSelectMetaButtons( | 54 private static void mapCommonStartSelectMetaButtons( |
| 55 float[] mappedButtons, float[] rawButtons) { | 55 float[] mappedButtons, float[] rawButtons) { |
| 56 float start = rawButtons[KeyEvent.KEYCODE_BUTTON_START]; | 56 float start = rawButtons[KeyEvent.KEYCODE_BUTTON_START]; |
| 57 float select = rawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]; | 57 float select = rawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]; |
| 58 float mode = rawButtons[KeyEvent.KEYCODE_BUTTON_MODE]; | 58 float mode = rawButtons[KeyEvent.KEYCODE_BUTTON_MODE]; |
| 59 mappedButtons[CanonicalButtonIndex.START] = start; | 59 mappedButtons[CanonicalButtonIndex.BUTTON_START] = start; |
| 60 mappedButtons[CanonicalButtonIndex.BACK_SELECT] = select; | 60 mappedButtons[CanonicalButtonIndex.BUTTON_BACK_SELECT] = select; |
| 61 mappedButtons[CanonicalButtonIndex.META] = mode; | 61 mappedButtons[CanonicalButtonIndex.BUTTON_META] = mode; |
| 62 } | 62 } |
| 63 | 63 |
| 64 private static void mapCommonThumbstickButtons(float[] mappedButtons, float[
] rawButtons) { | 64 private static void mapCommonThumbstickButtons(float[] mappedButtons, float[
] rawButtons) { |
| 65 float thumbL = rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]; | 65 float thumbL = rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]; |
| 66 float thumbR = rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]; | 66 float thumbR = rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]; |
| 67 mappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK] = thumbL; | 67 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_THUMBSTICK] = thumbL; |
| 68 mappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK] = thumbR; | 68 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_THUMBSTICK] = thumbR; |
| 69 } | 69 } |
| 70 | 70 |
| 71 private static void mapCommonTriggerButtons(float[] mappedButtons, float[] r
awButtons) { | 71 private static void mapCommonTriggerButtons(float[] mappedButtons, float[] r
awButtons) { |
| 72 float l1 = rawButtons[KeyEvent.KEYCODE_BUTTON_L1]; | 72 float l1 = rawButtons[KeyEvent.KEYCODE_BUTTON_L1]; |
| 73 float r1 = rawButtons[KeyEvent.KEYCODE_BUTTON_R1]; | 73 float r1 = rawButtons[KeyEvent.KEYCODE_BUTTON_R1]; |
| 74 mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = l1; | 74 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = l1; |
| 75 mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = r1; | 75 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = r1; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private static void mapCommonDpadButtons(float[] mappedButtons, float[] rawB
uttons) { | 78 private static void mapCommonDpadButtons(float[] mappedButtons, float[] rawB
uttons) { |
| 79 float dpadDown = rawButtons[KeyEvent.KEYCODE_DPAD_DOWN]; | 79 float dpadDown = rawButtons[KeyEvent.KEYCODE_DPAD_DOWN]; |
| 80 float dpadUp = rawButtons[KeyEvent.KEYCODE_DPAD_UP]; | 80 float dpadUp = rawButtons[KeyEvent.KEYCODE_DPAD_UP]; |
| 81 float dpadLeft = rawButtons[KeyEvent.KEYCODE_DPAD_LEFT]; | 81 float dpadLeft = rawButtons[KeyEvent.KEYCODE_DPAD_LEFT]; |
| 82 float dpadRight = rawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]; | 82 float dpadRight = rawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]; |
| 83 mappedButtons[CanonicalButtonIndex.DPAD_DOWN] = dpadDown; | 83 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = dpadDown; |
| 84 mappedButtons[CanonicalButtonIndex.DPAD_UP] = dpadUp; | 84 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = dpadUp; |
| 85 mappedButtons[CanonicalButtonIndex.DPAD_LEFT] = dpadLeft; | 85 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = dpadLeft; |
| 86 mappedButtons[CanonicalButtonIndex.DPAD_RIGHT] = dpadRight; | 86 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = dpadRight; |
| 87 } | 87 } |
| 88 | 88 |
| 89 private static void mapXYAxes(float[] mappedAxes, float[] rawAxes) { | 89 private static void mapXYAxes(float[] mappedAxes, float[] rawAxes) { |
| 90 mappedAxes[CanonicalAxisIndex.LEFT_STICK_X] = rawAxes[MotionEvent.AXIS_X
]; | 90 mappedAxes[CanonicalAxisIndex.AXIS_LEFT_STICK_X] = rawAxes[MotionEvent.A
XIS_X]; |
| 91 mappedAxes[CanonicalAxisIndex.LEFT_STICK_Y] = rawAxes[MotionEvent.AXIS_Y
]; | 91 mappedAxes[CanonicalAxisIndex.AXIS_LEFT_STICK_Y] = rawAxes[MotionEvent.A
XIS_Y]; |
| 92 } | 92 } |
| 93 | 93 |
| 94 private static void mapRXAndRYAxesToRightStick(float[] mappedAxes, float[] r
awAxes) { | 94 private static void mapRXAndRYAxesToRightStick(float[] mappedAxes, float[] r
awAxes) { |
| 95 mappedAxes[CanonicalAxisIndex.RIGHT_STICK_X] = rawAxes[MotionEvent.AXIS_
RX]; | 95 mappedAxes[CanonicalAxisIndex.AXIS_RIGHT_STICK_X] = rawAxes[MotionEvent.
AXIS_RX]; |
| 96 mappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y] = rawAxes[MotionEvent.AXIS_
RY]; | 96 mappedAxes[CanonicalAxisIndex.AXIS_RIGHT_STICK_Y] = rawAxes[MotionEvent.
AXIS_RY]; |
| 97 } | 97 } |
| 98 | 98 |
| 99 private static void mapZAndRZAxesToRightStick(float[] mappedAxes, float[] ra
wAxes) { | 99 private static void mapZAndRZAxesToRightStick(float[] mappedAxes, float[] ra
wAxes) { |
| 100 mappedAxes[CanonicalAxisIndex.RIGHT_STICK_X] = rawAxes[MotionEvent.AXIS_
Z]; | 100 mappedAxes[CanonicalAxisIndex.AXIS_RIGHT_STICK_X] = rawAxes[MotionEvent.
AXIS_Z]; |
| 101 mappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y] = rawAxes[MotionEvent.AXIS_
RZ]; | 101 mappedAxes[CanonicalAxisIndex.AXIS_RIGHT_STICK_Y] = rawAxes[MotionEvent.
AXIS_RZ]; |
| 102 } | 102 } |
| 103 | 103 |
| 104 private static void mapTriggerAxexToShoulderButtons(float[] mappedButtons, f
loat[] rawAxes) { | 104 private static void mapTriggerAxexToShoulderButtons(float[] mappedButtons, f
loat[] rawAxes) { |
| 105 float lTrigger = rawAxes[MotionEvent.AXIS_LTRIGGER]; | 105 float lTrigger = rawAxes[MotionEvent.AXIS_LTRIGGER]; |
| 106 float rTrigger = rawAxes[MotionEvent.AXIS_RTRIGGER]; | 106 float rTrigger = rawAxes[MotionEvent.AXIS_RTRIGGER]; |
| 107 mappedButtons[CanonicalButtonIndex.LEFT_SHOULDER] = lTrigger; | 107 mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_SHOULDER] = lTrigger; |
| 108 mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = rTrigger; | 108 mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_SHOULDER] = rTrigger; |
| 109 } | 109 } |
| 110 | 110 |
| 111 private static float negativeAxisValueAsButton(float input) { | 111 private static float negativeAxisValueAsButton(float input) { |
| 112 return (input < -0.5f) ? 1.f : 0.f; | 112 return (input < -0.5f) ? 1.f : 0.f; |
| 113 } | 113 } |
| 114 | 114 |
| 115 private static float positiveAxisValueAsButton(float input) { | 115 private static float positiveAxisValueAsButton(float input) { |
| 116 return (input > 0.5f) ? 1.f : 0.f; | 116 return (input > 0.5f) ? 1.f : 0.f; |
| 117 } | 117 } |
| 118 | 118 |
| 119 private static void mapHatAxisToDpadButtons(float[] mappedButtons, float[] r
awAxes) { | 119 private static void mapHatAxisToDpadButtons(float[] mappedButtons, float[] r
awAxes) { |
| 120 float hatX = rawAxes[MotionEvent.AXIS_HAT_X]; | 120 float hatX = rawAxes[MotionEvent.AXIS_HAT_X]; |
| 121 float hatY = rawAxes[MotionEvent.AXIS_HAT_Y]; | 121 float hatY = rawAxes[MotionEvent.AXIS_HAT_Y]; |
| 122 mappedButtons[CanonicalButtonIndex.DPAD_LEFT] = negativeAxisValueAsButto
n(hatX); | 122 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = negativeAxisValue
AsButton(hatX); |
| 123 mappedButtons[CanonicalButtonIndex.DPAD_RIGHT] = positiveAxisValueAsButt
on(hatX); | 123 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = positiveAxisValu
eAsButton(hatX); |
| 124 mappedButtons[CanonicalButtonIndex.DPAD_UP] = negativeAxisValueAsButton(
hatY); | 124 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = negativeAxisValueAs
Button(hatY); |
| 125 mappedButtons[CanonicalButtonIndex.DPAD_DOWN] = positiveAxisValueAsButto
n(hatY); | 125 mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = positiveAxisValue
AsButton(hatY); |
| 126 } | 126 } |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * Method for mapping Nvidia gamepad axis and button values | 129 * Method for mapping Nvidia gamepad axis and button values |
| 130 * to standard gamepad button and axes values. | 130 * to standard gamepad button and axes values. |
| 131 */ | 131 */ |
| 132 private static void mapShieldGamepad(float[] mappedButtons, float[] rawButto
ns, | 132 private static void mapShieldGamepad(float[] mappedButtons, float[] rawButto
ns, |
| 133 float[] mappedAxes, float[] rawAxes) { | 133 float[] mappedAxes, float[] rawAxes) { |
| 134 mapCommonXYABButtons(mappedButtons, rawButtons); | 134 mapCommonXYABButtons(mappedButtons, rawButtons); |
| 135 mapCommonTriggerButtons(mappedButtons, rawButtons); | 135 mapCommonTriggerButtons(mappedButtons, rawButtons); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 152 mapShieldGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); | 152 mapShieldGamepad(mappedButtons, rawButtons, mappedAxes, rawAxes); |
| 153 } | 153 } |
| 154 | 154 |
| 155 private static void mapPS3SixAxisGamepad(float[] mappedButtons, float[] rawB
uttons, | 155 private static void mapPS3SixAxisGamepad(float[] mappedButtons, float[] rawB
uttons, |
| 156 float[] mappedAxes, float[] rawAxes) { | 156 float[] mappedAxes, float[] rawAxes) { |
| 157 // On PS3 X/Y has higher priority. | 157 // On PS3 X/Y has higher priority. |
| 158 float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A]; | 158 float a = rawButtons[KeyEvent.KEYCODE_BUTTON_A]; |
| 159 float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B]; | 159 float b = rawButtons[KeyEvent.KEYCODE_BUTTON_B]; |
| 160 float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X]; | 160 float x = rawButtons[KeyEvent.KEYCODE_BUTTON_X]; |
| 161 float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; | 161 float y = rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; |
| 162 mappedButtons[CanonicalButtonIndex.PRIMARY] = x; | 162 mappedButtons[CanonicalButtonIndex.BUTTON_PRIMARY] = x; |
| 163 mappedButtons[CanonicalButtonIndex.SECONDARY] = y; | 163 mappedButtons[CanonicalButtonIndex.BUTTON_SECONDARY] = y; |
| 164 mappedButtons[CanonicalButtonIndex.TERTIARY] = a; | 164 mappedButtons[CanonicalButtonIndex.BUTTON_TERTIARY] = a; |
| 165 mappedButtons[CanonicalButtonIndex.QUATERNARY] = b; | 165 mappedButtons[CanonicalButtonIndex.BUTTON_QUATERNARY] = b; |
| 166 | 166 |
| 167 mapCommonTriggerButtons(mappedButtons, rawButtons); | 167 mapCommonTriggerButtons(mappedButtons, rawButtons); |
| 168 mapCommonThumbstickButtons(mappedButtons, rawButtons); | 168 mapCommonThumbstickButtons(mappedButtons, rawButtons); |
| 169 mapCommonDpadButtons(mappedButtons, rawButtons); | 169 mapCommonDpadButtons(mappedButtons, rawButtons); |
| 170 mapCommonStartSelectMetaButtons(mappedButtons, rawButtons); | 170 mapCommonStartSelectMetaButtons(mappedButtons, rawButtons); |
| 171 mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes); | 171 mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes); |
| 172 | 172 |
| 173 mapXYAxes(mappedAxes, rawAxes); | 173 mapXYAxes(mappedAxes, rawAxes); |
| 174 mapZAndRZAxesToRightStick(mappedAxes, rawAxes); | 174 mapZAndRZAxesToRightStick(mappedAxes, rawAxes); |
| 175 } | 175 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 mapCommonTriggerButtons(mappedButtons, rawButtons); | 196 mapCommonTriggerButtons(mappedButtons, rawButtons); |
| 197 mapCommonThumbstickButtons(mappedButtons, rawButtons); | 197 mapCommonThumbstickButtons(mappedButtons, rawButtons); |
| 198 mapCommonStartSelectMetaButtons(mappedButtons, rawButtons); | 198 mapCommonStartSelectMetaButtons(mappedButtons, rawButtons); |
| 199 mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes); | 199 mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes); |
| 200 mapCommonDpadButtons(mappedButtons, rawButtons); | 200 mapCommonDpadButtons(mappedButtons, rawButtons); |
| 201 | 201 |
| 202 mapXYAxes(mappedAxes, rawAxes); | 202 mapXYAxes(mappedAxes, rawAxes); |
| 203 mapRXAndRYAxesToRightStick(mappedAxes, rawAxes); | 203 mapRXAndRYAxesToRightStick(mappedAxes, rawAxes); |
| 204 } | 204 } |
| 205 } | 205 } |
| OLD | NEW |