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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/modules/gamepad/GamepadDispatcher.h ('k') | Source/modules/gamepad/GamepadEvent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/gamepad/GamepadDispatcher.h"
7
8 #include "modules/gamepad/NavigatorGamepad.h"
9 #include "public/platform/Platform.h"
10 #include "wtf/TemporaryChange.h"
11
12 namespace WebCore {
13
14 GamepadDispatcher& GamepadDispatcher::instance()
15 {
16 DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, ());
17 return gamepadDispatcher;
18 }
19
20 void GamepadDispatcher::addClient(NavigatorGamepad* client)
21 {
22 addController(client);
23 }
24
25 void GamepadDispatcher::removeClient(NavigatorGamepad* client)
26 {
27 removeController(client);
28 }
29
30 void GamepadDispatcher::sampleGamepads(blink::WebGamepads& gamepads)
31 {
32 ASSERT(!m_controllers.isEmpty());
33 blink::Platform::current()->sampleGamepads(gamepads);
34 }
35
36 GamepadDispatcher::GamepadDispatcher()
37 {
38 }
39
40 GamepadDispatcher::~GamepadDispatcher()
41 {
42 }
43
44 void GamepadDispatcher::didConnectGamepad(unsigned index, const blink::WebGamepa d& gamepad)
45 {
46 dispatchDidConnectOrDisconnectGamepad(index, gamepad, true);
47 }
48
49 void GamepadDispatcher::didDisconnectGamepad(unsigned index, const blink::WebGam epad& gamepad)
50 {
51 dispatchDidConnectOrDisconnectGamepad(index, gamepad, false);
52 }
53
54 void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, co nst blink::WebGamepad& gamepad, bool connected)
55 {
56 {
57 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
58 // Don't fire controllers removed or added during event dispatch.
59 size_t size = m_controllers.size();
60 for (size_t i = 0; i < size; ++i) {
61 if (m_controllers[i])
62 static_cast<NavigatorGamepad*>(m_controllers[i])->didConnectOrDi sconnectGamepad(index, gamepad, connected);
63 }
64 }
65
66 if (m_needsPurge)
67 purgeControllers();
68 }
69
70 void GamepadDispatcher::startListening()
71 {
72 blink::Platform::current()->setGamepadListener(this);
73 }
74
75 void GamepadDispatcher::stopListening()
76 {
77 blink::Platform::current()->setGamepadListener(0);
78 }
79
80 } // namespace WebCore
OLDNEW
« 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