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

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

Issue 808643005: Sync Navigator.getGamepads() with the spec Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 10 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 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)
« 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