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

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

Issue 200783002: Gamepad API: add support for gamepadconnected and gamepaddisconnected events (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: layout fix: webexposed/global-constructors-listing 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/GamepadDispatcher.h ('k') | Source/modules/gamepad/GamepadEvent.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/GamepadDispatcher.cpp
diff --git a/Source/modules/gamepad/GamepadDispatcher.cpp b/Source/modules/gamepad/GamepadDispatcher.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0749ad1a1bf2b053cf061c28c307b502c92b3f29
--- /dev/null
+++ b/Source/modules/gamepad/GamepadDispatcher.cpp
@@ -0,0 +1,80 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/gamepad/GamepadDispatcher.h"
+
+#include "modules/gamepad/NavigatorGamepad.h"
+#include "public/platform/Platform.h"
+#include "wtf/TemporaryChange.h"
+
+namespace WebCore {
+
+GamepadDispatcher& GamepadDispatcher::instance()
+{
+ DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, ());
+ return gamepadDispatcher;
+}
+
+void GamepadDispatcher::addClient(NavigatorGamepad* client)
+{
+ addController(client);
+}
+
+void GamepadDispatcher::removeClient(NavigatorGamepad* client)
+{
+ removeController(client);
+}
+
+void GamepadDispatcher::sampleGamepads(blink::WebGamepads& gamepads)
+{
+ ASSERT(!m_controllers.isEmpty());
+ blink::Platform::current()->sampleGamepads(gamepads);
+}
+
+GamepadDispatcher::GamepadDispatcher()
+{
+}
+
+GamepadDispatcher::~GamepadDispatcher()
+{
+}
+
+void GamepadDispatcher::didConnectGamepad(unsigned index, const blink::WebGamepad& gamepad)
+{
+ dispatchDidConnectOrDisconnectGamepad(index, gamepad, true);
+}
+
+void GamepadDispatcher::didDisconnectGamepad(unsigned index, const blink::WebGamepad& gamepad)
+{
+ dispatchDidConnectOrDisconnectGamepad(index, gamepad, false);
+}
+
+void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, const blink::WebGamepad& gamepad, bool connected)
+{
+ {
+ TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
+ // Don't fire controllers removed or added during event dispatch.
+ size_t size = m_controllers.size();
+ for (size_t i = 0; i < size; ++i) {
+ if (m_controllers[i])
+ static_cast<NavigatorGamepad*>(m_controllers[i])->didConnectOrDisconnectGamepad(index, gamepad, connected);
+ }
+ }
+
+ if (m_needsPurge)
+ purgeControllers();
+}
+
+void GamepadDispatcher::startListening()
+{
+ blink::Platform::current()->setGamepadListener(this);
+}
+
+void GamepadDispatcher::stopListening()
+{
+ blink::Platform::current()->setGamepadListener(0);
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/modules/gamepad/GamepadDispatcher.h ('k') | Source/modules/gamepad/GamepadEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698