Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3682)

Unified Diff: Source/modules/gamepad/NavigatorGamepad.cpp

Issue 183313003: Added non-prefixed navigator.getGamepads() with updated API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added LayoutTests Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/gamepad/NavigatorGamepad.cpp
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
index 8aa04555f93f958a5b2d8aefda2827064902f3e8..12cf8160a9dcd7fb9d8954f00625bdd774ace8ec 100644
--- a/Source/modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp
@@ -28,11 +28,43 @@
#include "core/frame/Navigator.h"
#include "modules/gamepad/GamepadList.h"
+#include "modules/gamepad/WebKitGamepadList.h"
#include "public/platform/Platform.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
+static void sampleGamepad(unsigned index, GamepadBase* gamepad, const blink::WebGamepad& webGamepad)
Inactive 2014/03/06 02:54:00 nit: gamedpad would be passed by reference here to
+{
+ gamepad->id(webGamepad.id);
+ gamepad->index(index);
+ gamepad->connected(webGamepad.connected);
+ gamepad->timestamp(webGamepad.timestamp);
+ gamepad->mapping(webGamepad.mapping);
+ gamepad->axes(webGamepad.axesLength, webGamepad.axes);
+ gamepad->buttons(webGamepad.buttonsLength, webGamepad.buttons);
+}
+
+static void sampleWebKitGamepads(WebKitGamepadList* into)
+{
+ blink::WebGamepads gamepads;
+
+ blink::Platform::current()->sampleGamepads(gamepads);
+
+ for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) {
+ blink::WebGamepad& webGamepad = gamepads.items[i];
+ if (i < gamepads.length && webGamepad.connected) {
+ RefPtrWillBeRawPtr<WebKitGamepad> gamepad = into->item(i);
+ if (!gamepad)
+ gamepad = WebKitGamepad::create();
+ sampleGamepad(i, gamepad.get(), webGamepad);
Inactive 2014/03/06 02:54:00 nit: *gamepad (see comment above)
+ into->set(i, gamepad);
+ } else {
+ into->set(i, nullptr);
+ }
+ }
+}
+
static void sampleGamepads(GamepadList* into)
{
blink::WebGamepads gamepads;
@@ -45,15 +77,7 @@ static void sampleGamepads(GamepadList* into)
RefPtrWillBeRawPtr<Gamepad> gamepad = into->item(i);
if (!gamepad)
gamepad = Gamepad::create();
- gamepad->id(webGamepad.id);
- gamepad->index(i);
- gamepad->connected(webGamepad.connected);
- gamepad->timestamp(webGamepad.timestamp);
-#if defined(ENABLE_NEW_GAMEPAD_API)
- gamepad->mapping(webGamepad.mapping);
-#endif
- gamepad->axes(webGamepad.axesLength, webGamepad.axes);
- gamepad->buttons(webGamepad.buttonsLength, webGamepad.buttons);
+ sampleGamepad(i, gamepad.get(), webGamepad);
into->set(i, gamepad);
} else {
into->set(i, nullptr);
@@ -63,10 +87,12 @@ static void sampleGamepads(GamepadList* into)
NavigatorGamepad::NavigatorGamepad()
{
+
}
NavigatorGamepad::~NavigatorGamepad()
{
+
}
const char* NavigatorGamepad::supplementName()
@@ -84,11 +110,24 @@ NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator)
return *supplement;
}
-GamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
+WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator)
+{
+ return NavigatorGamepad::from(navigator).webkitGamepads();
+}
+
+GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator)
{
return NavigatorGamepad::from(navigator).gamepads();
}
+WebKitGamepadList* NavigatorGamepad::webkitGamepads()
+{
+ if (!m_webkitGamepads)
+ m_webkitGamepads = WebKitGamepadList::create();
+ sampleWebKitGamepads(m_webkitGamepads.get());
+ return m_webkitGamepads.get();
+}
+
GamepadList* NavigatorGamepad::gamepads()
{
if (!m_gamepads)

Powered by Google App Engine
This is Rietveld 408576698