| Index: Source/modules/gamepad/NavigatorGamepad.cpp
|
| diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
|
| index 8aa04555f93f958a5b2d8aefda2827064902f3e8..cafa2c0e466f220a3807f9080fcb185ae158e28e 100644
|
| --- a/Source/modules/gamepad/NavigatorGamepad.cpp
|
| +++ b/Source/modules/gamepad/NavigatorGamepad.cpp
|
| @@ -26,14 +26,49 @@
|
| #include "config.h"
|
| #include "modules/gamepad/NavigatorGamepad.h"
|
|
|
| +#include "core/frame/DOMWindow.h"
|
| +#include "core/frame/LocalFrame.h"
|
| #include "core/frame/Navigator.h"
|
| +#include "modules/gamepad/GamepadEvent.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)
|
| +static void sampleGamepad(unsigned index, GamepadBase* gamepad, const blink::WebGamepad& webGamepad)
|
| +{
|
| + 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);
|
| + into->set(i, gamepad);
|
| + } else {
|
| + into->set(i, nullptr);
|
| + }
|
| + }
|
| +}
|
| +
|
| +static void sampleGamepads(GamepadList* into, LocalFrame* frame)
|
| {
|
| blink::WebGamepads gamepads;
|
|
|
| @@ -45,15 +80,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);
|
| @@ -61,7 +88,8 @@ static void sampleGamepads(GamepadList* into)
|
| }
|
| }
|
|
|
| -NavigatorGamepad::NavigatorGamepad()
|
| +NavigatorGamepad::NavigatorGamepad(LocalFrame* frame)
|
| + : DOMWindowProperty(frame)
|
| {
|
| }
|
|
|
| @@ -78,22 +106,35 @@ NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator)
|
| {
|
| NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(Supplement<Navigator>::from(navigator, supplementName()));
|
| if (!supplement) {
|
| - supplement = new NavigatorGamepad();
|
| + supplement = new NavigatorGamepad(navigator.frame());
|
| provideTo(navigator, supplementName(), adoptPtr(supplement));
|
| }
|
| 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)
|
| m_gamepads = GamepadList::create();
|
| - sampleGamepads(m_gamepads.get());
|
| + sampleGamepads(m_gamepads.get(), frame());
|
| return m_gamepads.get();
|
| }
|
|
|
|
|