Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "modules/gamepad/GamepadDispatcher.h" | 5 #include "modules/gamepad/GamepadDispatcher.h" |
| 6 | 6 |
| 7 #include "modules/gamepad/GamepadSharedMemoryReader.h" | |
|
ke.he
2016/12/15 14:11:01
Actually the GamepadSharedMemory can be merged int
| |
| 7 #include "modules/gamepad/NavigatorGamepad.h" | 8 #include "modules/gamepad/NavigatorGamepad.h" |
| 8 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 9 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 12 GamepadDispatcher& GamepadDispatcher::instance() { | 13 GamepadDispatcher& GamepadDispatcher::instance() { |
| 13 DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, | 14 DEFINE_STATIC_LOCAL(GamepadDispatcher, gamepadDispatcher, |
| 14 (new GamepadDispatcher)); | 15 (new GamepadDispatcher)); |
| 15 return gamepadDispatcher; | 16 return gamepadDispatcher; |
| 16 } | 17 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 43 bool connected) { | 44 bool connected) { |
| 44 ASSERT(index < WebGamepads::itemsLengthCap); | 45 ASSERT(index < WebGamepads::itemsLengthCap); |
| 45 ASSERT(connected == gamepad.connected); | 46 ASSERT(connected == gamepad.connected); |
| 46 | 47 |
| 47 m_latestChange.pad = gamepad; | 48 m_latestChange.pad = gamepad; |
| 48 m_latestChange.index = index; | 49 m_latestChange.index = index; |
| 49 notifyControllers(); | 50 notifyControllers(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void GamepadDispatcher::startListening() { | 53 void GamepadDispatcher::startListening() { |
| 53 Platform::current()->startListening(WebPlatformEventTypeGamepad, this); | 54 if (!m_reader.get()) { |
| 55 m_reader.reset(new GamepadSharedMemoryReader( | |
| 56 Platform::current()->interfaceProvider())); | |
| 57 } | |
| 58 m_reader->start(this); | |
| 54 } | 59 } |
| 55 | 60 |
| 56 void GamepadDispatcher::stopListening() { | 61 void GamepadDispatcher::stopListening() { |
| 57 Platform::current()->stopListening(WebPlatformEventTypeGamepad); | 62 if (m_reader) { |
| 63 m_reader->stop(); | |
| 64 } | |
| 58 } | 65 } |
| 59 | 66 |
| 60 } // namespace blink | 67 } // namespace blink |
| OLD | NEW |