Index: content/common/gamepad_user_gesture.cc |
diff --git a/content/common/gamepad_user_gesture.cc b/content/common/gamepad_user_gesture.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e08b52912d9672c687e9e4029012ad3f6ed89f9 |
--- /dev/null |
+++ b/content/common/gamepad_user_gesture.cc |
@@ -0,0 +1,30 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/common/gamepad_user_gesture.h" |
+ |
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h" |
+ |
+namespace content { |
+ |
+bool GamepadsHaveUserGesture(const WebKit::WebGamepads& gamepads) { |
+ bool has_user_gesture = false; |
+ for (unsigned i = 0; i < WebKit::WebGamepads::itemsLengthCap; i++) { |
+ const WebKit::WebGamepad& pad = gamepads.items[i]; |
+ |
+ // If the device is physically connected, then check the primary 4 buttons |
+ // to see if there is currently an intentional user action. |
+ if (pad.connected) { |
+ const int kPrimaryInteractionButtons = 4; |
+ for (int button_index = 0; button_index < kPrimaryInteractionButtons; |
+ button_index++) { |
+ if (pad.buttons[button_index] > 0.5f) |
+ return true; |
+ } |
+ } |
+ } |
+ return false; |
+} |
+ |
+} // namespace content |