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