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

Side by Side Diff: Source/modules/gamepad/GamepadDispatcher.cpp

Issue 336693004: Deduplicate DeviceEvent* classes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: oops - fix grammar in test expectation as well Created 6 years, 6 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/NavigatorGamepad.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/gamepad/GamepadDispatcher.h" 6 #include "modules/gamepad/GamepadDispatcher.h"
7 7
8 #include "modules/gamepad/NavigatorGamepad.h" 8 #include "modules/gamepad/NavigatorGamepad.h"
9 #include "public/platform/Platform.h" 9 #include "public/platform/Platform.h"
10 #include "wtf/TemporaryChange.h" 10 #include "wtf/TemporaryChange.h"
11 11
12 namespace WebCore { 12 namespace WebCore {
13 13
14 GamepadDispatcher& GamepadDispatcher::instance() 14 GamepadDispatcher& GamepadDispatcher::instance()
15 { 15 {
16 DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, ()); 16 DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, ());
17 return gamepadDispatcher; 17 return gamepadDispatcher;
18 } 18 }
19 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) 20 void GamepadDispatcher::sampleGamepads(blink::WebGamepads& gamepads)
31 { 21 {
32 ASSERT(!m_controllers.isEmpty());
33 blink::Platform::current()->sampleGamepads(gamepads); 22 blink::Platform::current()->sampleGamepads(gamepads);
34 } 23 }
35 24
36 GamepadDispatcher::GamepadDispatcher() 25 GamepadDispatcher::GamepadDispatcher()
37 { 26 {
38 } 27 }
39 28
40 GamepadDispatcher::~GamepadDispatcher() 29 GamepadDispatcher::~GamepadDispatcher()
41 { 30 {
42 } 31 }
43 32
44 void GamepadDispatcher::didConnectGamepad(unsigned index, const blink::WebGamepa d& gamepad) 33 void GamepadDispatcher::didConnectGamepad(unsigned index, const blink::WebGamepa d& gamepad)
45 { 34 {
46 dispatchDidConnectOrDisconnectGamepad(index, gamepad, true); 35 dispatchDidConnectOrDisconnectGamepad(index, gamepad, true);
47 } 36 }
48 37
49 void GamepadDispatcher::didDisconnectGamepad(unsigned index, const blink::WebGam epad& gamepad) 38 void GamepadDispatcher::didDisconnectGamepad(unsigned index, const blink::WebGam epad& gamepad)
50 { 39 {
51 dispatchDidConnectOrDisconnectGamepad(index, gamepad, false); 40 dispatchDidConnectOrDisconnectGamepad(index, gamepad, false);
52 } 41 }
53 42
54 void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, co nst blink::WebGamepad& gamepad, bool connected) 43 void GamepadDispatcher::dispatchDidConnectOrDisconnectGamepad(unsigned index, co nst blink::WebGamepad& gamepad, bool connected)
55 { 44 {
56 { 45 ASSERT(index < blink::WebGamepads::itemsLengthCap);
57 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true); 46 ASSERT(connected == gamepad.connected);
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 47
66 if (m_needsPurge) 48 m_latestChange.pad = gamepad;
67 purgeControllers(); 49 m_latestChange.index = index;
50 notifyControllers();
68 } 51 }
69 52
70 void GamepadDispatcher::startListening() 53 void GamepadDispatcher::startListening()
71 { 54 {
72 blink::Platform::current()->setGamepadListener(this); 55 blink::Platform::current()->setGamepadListener(this);
73 } 56 }
74 57
75 void GamepadDispatcher::stopListening() 58 void GamepadDispatcher::stopListening()
76 { 59 {
77 blink::Platform::current()->setGamepadListener(0); 60 blink::Platform::current()->setGamepadListener(0);
78 } 61 }
79 62
80 } // namespace WebCore 63 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/gamepad/GamepadDispatcher.h ('k') | Source/modules/gamepad/NavigatorGamepad.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698