Index: Source/modules/gamepad/NavigatorGamepad.cpp |
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp |
index c68f061fff5d0497122022d45368e78d7ee3adae..2e7058bb6570efafccb34d44847450e692128578 100644 |
--- a/Source/modules/gamepad/NavigatorGamepad.cpp |
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp |
@@ -33,13 +33,12 @@ |
#include "core/page/Page.h" |
#include "modules/gamepad/GamepadDispatcher.h" |
#include "modules/gamepad/GamepadEvent.h" |
-#include "modules/gamepad/GamepadList.h" |
namespace blink { |
-template<typename T> |
-static void sampleGamepad(unsigned index, T& gamepad, const WebGamepad& webGamepad) |
+static Member<Gamepad> sampleGamepad(unsigned index, Gamepad& gamepad, const WebGamepad& webGamepad) |
{ |
+ Member<Gamepad> gamepad = Gamepad::create(); |
gamepad.setId(webGamepad.id); |
gamepad.setIndex(index); |
gamepad.setConnected(webGamepad.connected); |
@@ -49,27 +48,28 @@ static void sampleGamepad(unsigned index, T& gamepad, const WebGamepad& webGamep |
gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons); |
} |
-template<typename GamepadType, typename ListType> |
-static void sampleGamepads(ListType* into) |
+static HeapVector<Member<Gamepad>> sampleGamepads() |
{ |
- WebGamepads gamepads; |
- |
- GamepadDispatcher::instance().sampleGamepads(gamepads); |
+ WebGamepads webGamepads; |
+ GamepadDispatcher::instance().sampleGamepads(webGamepads); |
+ HeapVector<Member<Gamepad>> gamepads; |
+ gamepads.reserveCapacity(webGamepads.length); |
for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
- WebGamepad& webGamepad = gamepads.items[i]; |
- if (i < gamepads.length && webGamepad.connected) { |
- GamepadType* gamepad = into->item(i); |
+ WebGamepad& webGamepad = webGamepads.items[i]; |
+ if (i < webGamepads.length && webGamepad.connected) { |
+ Gamepad* gamepad = gamepads->item(i); |
if (!gamepad) |
- gamepad = GamepadType::create(); |
+ gamepad = Gamepad::create(); |
sampleGamepad(i, *gamepad, webGamepad); |
- into->set(i, gamepad); |
+ gamepads->set(i, gamepad); |
} else { |
- into->set(i, 0); |
+ gamepads->set(i, 0); |
} |
} |
-} |
+ return gamepads; |
+} |
NavigatorGamepad* NavigatorGamepad::from(Document& document) |
{ |
if (!document.frame() || !document.frame()->domWindow()) |
@@ -88,18 +88,15 @@ NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) |
return *supplement; |
} |
-GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) |
+HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(Navigator& navigator) |
{ |
- return NavigatorGamepad::from(navigator).gamepads(); |
+ return NavigatorGamepad::from(navigator).getGamepads(); |
} |
-GamepadList* NavigatorGamepad::gamepads() |
+HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads() |
{ |
- if (!m_gamepads) |
- m_gamepads = GamepadList::create(); |
- if (startUpdatingIfAttached()) |
- sampleGamepads<Gamepad>(m_gamepads.get()); |
- return m_gamepads.get(); |
+ startUpdatingIfAttached(); |
+ return sampleGamepads(); |
} |
void NavigatorGamepad::trace(Visitor* visitor) |