Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / gamepad / GamepadDispatcher.cpp
index 0749ad1..8a62678 100644 (file)
@@ -9,7 +9,7 @@
 #include "public/platform/Platform.h"
 #include "wtf/TemporaryChange.h"
 
-namespace WebCore {
+namespace blink {
 
 GamepadDispatcher& GamepadDispatcher::instance()
 {
@@ -17,20 +17,9 @@ GamepadDispatcher& GamepadDispatcher::instance()
     return gamepadDispatcher;
 }
 
-void GamepadDispatcher::addClient(NavigatorGamepad* client)
+void GamepadDispatcher::sampleGamepads(WebGamepads& gamepads)
 {
-    addController(client);
-}
-
-void GamepadDispatcher::removeClient(NavigatorGamepad* client)
-{
-    removeController(client);
-}
-
-void GamepadDispatcher::sampleGamepads(blink::WebGamepads& gamepads)
-{
-    ASSERT(!m_controllers.isEmpty());
-    blink::Platform::current()->sampleGamepads(gamepads);
+    Platform::current()->sampleGamepads(gamepads);
 }
 
 GamepadDispatcher::GamepadDispatcher()
@@ -41,40 +30,34 @@ GamepadDispatcher::~GamepadDispatcher()
 {
 }
 
-void GamepadDispatcher::didConnectGamepad(unsigned index, const blink::WebGamepad& gamepad)
+void GamepadDispatcher::didConnectGamepad(unsigned index, const WebGamepad& gamepad)
 {
     dispatchDidConnectOrDisconnectGamepad(index, gamepad, true);
 }
 
-void GamepadDispatcher::didDisconnectGamepad(unsigned index, const blink::WebGamepad& gamepad)
+void GamepadDispatcher::didDisconnectGamepad(unsigned index, const WebGamepad& gamepad)
 {
     dispatchDidConnectOrDisconnectGamepad(index, gamepad, false);
 }
 
-void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, const blink::WebGamepad& gamepad, bool connected)
+void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, const 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);
-        }
-    }
+    ASSERT(index < WebGamepads::itemsLengthCap);
+    ASSERT(connected == gamepad.connected);
 
-    if (m_needsPurge)
-        purgeControllers();
+    m_latestChange.pad = gamepad;
+    m_latestChange.index = index;
+    notifyControllers();
 }
 
 void GamepadDispatcher::startListening()
 {
-    blink::Platform::current()->setGamepadListener(this);
+    Platform::current()->startListening(WebPlatformEventGamepad, this);
 }
 
 void GamepadDispatcher::stopListening()
 {
-    blink::Platform::current()->setGamepadListener(0);
+    Platform::current()->stopListening(WebPlatformEventGamepad);
 }
 
-} // namespace WebCore
+} // namespace blink