OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/common/gamepad_user_gesture.h" | 5 #include "device/gamepad/gamepad_user_gesture.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "third_party/WebKit/public/platform/WebGamepads.h" | 11 #include "third_party/WebKit/public/platform/WebGamepads.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 // A big enough deadzone to detect accidental presses. | 14 // A big enough deadzone to detect accidental presses. |
15 const float kAxisMoveAmountThreshold = 0.5; | 15 const float kAxisMoveAmountThreshold = 0.5; |
16 } | 16 } |
17 | 17 |
18 namespace content { | 18 namespace device { |
19 | 19 |
20 bool GamepadsHaveUserGesture(const blink::WebGamepads& gamepads) { | 20 bool GamepadsHaveUserGesture(const blink::WebGamepads& gamepads) { |
21 for (unsigned int i = 0; i < blink::WebGamepads::itemsLengthCap; i++) { | 21 for (unsigned int i = 0; i < blink::WebGamepads::itemsLengthCap; i++) { |
22 const blink::WebGamepad& pad = gamepads.items[i]; | 22 const blink::WebGamepad& pad = gamepads.items[i]; |
23 | 23 |
24 // If the device is physically connected, then check the buttons and axes | 24 // If the device is physically connected, then check the buttons and axes |
25 // to see if there is currently an intentional user action. | 25 // to see if there is currently an intentional user action. |
26 if (pad.connected) { | 26 if (pad.connected) { |
27 for (unsigned int button_index = 0; button_index < pad.buttonsLength; | 27 for (unsigned int button_index = 0; button_index < pad.buttonsLength; |
28 button_index++) { | 28 button_index++) { |
29 if (pad.buttons[button_index].pressed) | 29 if (pad.buttons[button_index].pressed) |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 for (unsigned int axes_index = 0; axes_index < pad.axesLength; | 33 for (unsigned int axes_index = 0; axes_index < pad.axesLength; |
34 axes_index++) { | 34 axes_index++) { |
35 if (fabs(pad.axes[axes_index]) > kAxisMoveAmountThreshold) | 35 if (fabs(pad.axes[axes_index]) > kAxisMoveAmountThreshold) |
36 return true; | 36 return true; |
37 } | 37 } |
38 } | 38 } |
39 } | 39 } |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 } // namespace content | 43 } // namespace device |
OLD | NEW |