OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
6 * | 6 * |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 m_gamepads = GamepadList::create(); | 98 m_gamepads = GamepadList::create(); |
99 if (startUpdatingIfAttached()) | 99 if (startUpdatingIfAttached()) |
100 sampleGamepads<Gamepad>(m_gamepads.get()); | 100 sampleGamepads<Gamepad>(m_gamepads.get()); |
101 return m_gamepads.get(); | 101 return m_gamepads.get(); |
102 } | 102 } |
103 | 103 |
104 DEFINE_TRACE(NavigatorGamepad) | 104 DEFINE_TRACE(NavigatorGamepad) |
105 { | 105 { |
106 visitor->trace(m_gamepads); | 106 visitor->trace(m_gamepads); |
107 visitor->trace(m_pendingEvents); | 107 visitor->trace(m_pendingEvents); |
| 108 visitor->trace(m_dispatchOneEventRunner); |
108 HeapSupplement<Navigator>::trace(visitor); | 109 HeapSupplement<Navigator>::trace(visitor); |
109 DOMWindowProperty::trace(visitor); | 110 DOMWindowProperty::trace(visitor); |
110 PlatformEventController::trace(visitor); | 111 PlatformEventController::trace(visitor); |
111 DOMWindowLifecycleObserver::trace(visitor); | 112 DOMWindowLifecycleObserver::trace(visitor); |
112 } | 113 } |
113 | 114 |
114 bool NavigatorGamepad::startUpdatingIfAttached() | 115 bool NavigatorGamepad::startUpdatingIfAttached() |
115 { | 116 { |
116 // The frame must be attached to start updating. | 117 // The frame must be attached to start updating. |
117 if (frame() && frame()->host()) { | 118 if (frame() && frame()->host()) { |
(...skipping 22 matching lines...) Expand all Loading... |
140 if (!m_gamepads) | 141 if (!m_gamepads) |
141 m_gamepads = GamepadList::create(); | 142 m_gamepads = GamepadList::create(); |
142 | 143 |
143 Gamepad* gamepad = m_gamepads->item(change.index); | 144 Gamepad* gamepad = m_gamepads->item(change.index); |
144 if (!gamepad) | 145 if (!gamepad) |
145 gamepad = Gamepad::create(); | 146 gamepad = Gamepad::create(); |
146 sampleGamepad(change.index, *gamepad, change.pad); | 147 sampleGamepad(change.index, *gamepad, change.pad); |
147 m_gamepads->set(change.index, gamepad); | 148 m_gamepads->set(change.index, gamepad); |
148 | 149 |
149 m_pendingEvents.append(gamepad); | 150 m_pendingEvents.append(gamepad); |
150 m_dispatchOneEventRunner.runAsync(); | 151 m_dispatchOneEventRunner->runAsync(); |
151 } | 152 } |
152 | 153 |
153 void NavigatorGamepad::dispatchOneEvent() | 154 void NavigatorGamepad::dispatchOneEvent() |
154 { | 155 { |
155 ASSERT(frame()); | 156 ASSERT(frame()); |
156 ASSERT(frame()->domWindow()); | 157 ASSERT(frame()->domWindow()); |
157 ASSERT(!m_pendingEvents.isEmpty()); | 158 ASSERT(!m_pendingEvents.isEmpty()); |
158 | 159 |
159 Gamepad* gamepad = m_pendingEvents.takeFirst(); | 160 Gamepad* gamepad = m_pendingEvents.takeFirst(); |
160 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; | 161 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; |
161 frame()->domWindow()->dispatchEvent(GamepadEvent::create(eventName, false, t
rue, gamepad)); | 162 frame()->domWindow()->dispatchEvent(GamepadEvent::create(eventName, false, t
rue, gamepad)); |
162 | 163 |
163 if (!m_pendingEvents.isEmpty()) | 164 if (!m_pendingEvents.isEmpty()) |
164 m_dispatchOneEventRunner.runAsync(); | 165 m_dispatchOneEventRunner->runAsync(); |
165 } | 166 } |
166 | 167 |
167 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) | 168 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) |
168 : DOMWindowProperty(frame) | 169 : DOMWindowProperty(frame) |
169 , PlatformEventController(frame ? frame->page() : 0) | 170 , PlatformEventController(frame ? frame->page() : 0) |
170 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0) | 171 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0) |
171 , m_dispatchOneEventRunner(this, &NavigatorGamepad::dispatchOneEvent) | 172 , m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create(this,
&NavigatorGamepad::dispatchOneEvent)) |
172 { | 173 { |
173 } | 174 } |
174 | 175 |
175 NavigatorGamepad::~NavigatorGamepad() | 176 NavigatorGamepad::~NavigatorGamepad() |
176 { | 177 { |
177 } | 178 } |
178 | 179 |
179 const char* NavigatorGamepad::supplementName() | 180 const char* NavigatorGamepad::supplementName() |
180 { | 181 { |
181 return "NavigatorGamepad"; | 182 return "NavigatorGamepad"; |
182 } | 183 } |
183 | 184 |
184 void NavigatorGamepad::willDestroyGlobalObjectInFrame() | 185 void NavigatorGamepad::willDestroyGlobalObjectInFrame() |
185 { | 186 { |
186 stopUpdating(); | 187 stopUpdating(); |
187 DOMWindowProperty::willDestroyGlobalObjectInFrame(); | 188 DOMWindowProperty::willDestroyGlobalObjectInFrame(); |
188 } | 189 } |
189 | 190 |
190 void NavigatorGamepad::willDetachGlobalObjectFromFrame() | 191 void NavigatorGamepad::willDetachGlobalObjectFromFrame() |
191 { | 192 { |
192 stopUpdating(); | 193 stopUpdating(); |
193 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 194 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
194 } | 195 } |
195 | 196 |
196 void NavigatorGamepad::registerWithDispatcher() | 197 void NavigatorGamepad::registerWithDispatcher() |
197 { | 198 { |
198 GamepadDispatcher::instance().addController(this); | 199 GamepadDispatcher::instance().addController(this); |
199 m_dispatchOneEventRunner.resume(); | 200 m_dispatchOneEventRunner->resume(); |
200 } | 201 } |
201 | 202 |
202 void NavigatorGamepad::unregisterWithDispatcher() | 203 void NavigatorGamepad::unregisterWithDispatcher() |
203 { | 204 { |
204 m_dispatchOneEventRunner.suspend(); | 205 m_dispatchOneEventRunner->suspend(); |
205 GamepadDispatcher::instance().removeController(this); | 206 GamepadDispatcher::instance().removeController(this); |
206 } | 207 } |
207 | 208 |
208 bool NavigatorGamepad::hasLastData() | 209 bool NavigatorGamepad::hasLastData() |
209 { | 210 { |
210 // Gamepad data is polled instead of pushed. | 211 // Gamepad data is polled instead of pushed. |
211 return false; | 212 return false; |
212 } | 213 } |
213 | 214 |
214 static bool isGamepadEvent(const AtomicString& eventType) | 215 static bool isGamepadEvent(const AtomicString& eventType) |
(...skipping 20 matching lines...) Expand all Loading... |
235 } | 236 } |
236 | 237 |
237 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) | 238 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) |
238 { | 239 { |
239 didRemoveGamepadEventListeners(); | 240 didRemoveGamepadEventListeners(); |
240 } | 241 } |
241 | 242 |
242 void NavigatorGamepad::didRemoveGamepadEventListeners() | 243 void NavigatorGamepad::didRemoveGamepadEventListeners() |
243 { | 244 { |
244 m_hasEventListener = false; | 245 m_hasEventListener = false; |
245 m_dispatchOneEventRunner.stop(); | 246 m_dispatchOneEventRunner->stop(); |
246 m_pendingEvents.clear(); | 247 m_pendingEvents.clear(); |
247 } | 248 } |
248 | 249 |
249 void NavigatorGamepad::pageVisibilityChanged() | 250 void NavigatorGamepad::pageVisibilityChanged() |
250 { | 251 { |
251 // Inform the embedder whether it needs to provide gamepad data for us. | 252 // Inform the embedder whether it needs to provide gamepad data for us. |
252 bool visible = page()->visibilityState() == PageVisibilityStateVisible; | 253 bool visible = page()->visibilityState() == PageVisibilityStateVisible; |
253 if (visible && (m_hasEventListener || m_gamepads)) | 254 if (visible && (m_hasEventListener || m_gamepads)) |
254 startUpdatingIfAttached(); | 255 startUpdatingIfAttached(); |
255 else | 256 else |
(...skipping 18 matching lines...) Expand all Loading... |
274 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { | 275 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { |
275 oldGamepad->setConnected(false); | 276 oldGamepad->setConnected(false); |
276 m_pendingEvents.append(oldGamepad); | 277 m_pendingEvents.append(oldGamepad); |
277 } | 278 } |
278 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 279 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
279 m_pendingEvents.append(newGamepad); | 280 m_pendingEvents.append(newGamepad); |
280 } | 281 } |
281 } | 282 } |
282 | 283 |
283 if (!m_pendingEvents.isEmpty()) | 284 if (!m_pendingEvents.isEmpty()) |
284 m_dispatchOneEventRunner.runAsync(); | 285 m_dispatchOneEventRunner->runAsync(); |
285 } | 286 } |
286 | 287 |
287 } // namespace blink | 288 } // namespace blink |
OLD | NEW |