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

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: Rebase 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
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/NavigatorGamepad.cpp
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
index 8aa04555f93f958a5b2d8aefda2827064902f3e8..27c1e53322ceece8349fc24a3b5d8f530ab8e7e2 100644
--- a/Source/modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp
@@ -28,12 +28,26 @@
#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 sampleGamepads(GamepadList* into)
+template<typename T>
+static void sampleGamepad(unsigned index, T& gamepad, const blink::WebGamepad& webGamepad)
+{
+ gamepad.setId(webGamepad.id);
+ gamepad.setIndex(index);
+ gamepad.setConnected(webGamepad.connected);
+ gamepad.setTimestamp(webGamepad.timestamp);
+ gamepad.setMapping(webGamepad.mapping);
+ gamepad.setAxes(webGamepad.axesLength, webGamepad.axes);
+ gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons);
+}
+
+template<typename GamepadType, typename ListType>
+static void sampleGamepads(ListType* into)
{
blink::WebGamepads gamepads;
@@ -42,18 +56,10 @@ static void sampleGamepads(GamepadList* into)
for (unsigned i = 0; i < blink::WebGamepads::itemsLengthCap; ++i) {
blink::WebGamepad& webGamepad = gamepads.items[i];
if (i < gamepads.length && webGamepad.connected) {
- RefPtrWillBeRawPtr<Gamepad> gamepad = into->item(i);
+ RefPtrWillBeRawPtr<GamepadType> 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);
+ gamepad = GamepadType::create();
+ sampleGamepad(i, *gamepad, webGamepad);
into->set(i, gamepad);
} else {
into->set(i, nullptr);
@@ -84,16 +90,29 @@ 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();
+ sampleGamepads<WebKitGamepad>(m_webkitGamepads.get());
+ return m_webkitGamepads.get();
+}
+
GamepadList* NavigatorGamepad::gamepads()
{
if (!m_gamepads)
m_gamepads = GamepadList::create();
- sampleGamepads(m_gamepads.get());
+ sampleGamepads<Gamepad>(m_gamepads.get());
return m_gamepads.get();
}
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | Source/modules/gamepad/NavigatorGamepad.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698