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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 void NavigatorGamepad::didUpdateData() { | 122 void NavigatorGamepad::didUpdateData() { |
123 // We should stop listening once we detached. | 123 // We should stop listening once we detached. |
124 Document* document = static_cast<Document*>(getExecutionContext()); | 124 Document* document = static_cast<Document*>(getExecutionContext()); |
125 DCHECK(document->frame()); | 125 DCHECK(document->frame()); |
126 DCHECK(document->frame()->domWindow()); | 126 DCHECK(document->frame()->domWindow()); |
127 | 127 |
128 // We register to the dispatcher before sampling gamepads so we need to check
if we actually have an event listener. | 128 // We register to the dispatcher before sampling gamepads so we need to check |
| 129 // if we actually have an event listener. |
129 if (!m_hasEventListener) | 130 if (!m_hasEventListener) |
130 return; | 131 return; |
131 | 132 |
132 if (document->activeDOMObjectsAreStopped() || | 133 if (document->activeDOMObjectsAreStopped() || |
133 document->activeDOMObjectsAreSuspended()) | 134 document->activeDOMObjectsAreSuspended()) |
134 return; | 135 return; |
135 | 136 |
136 const GamepadDispatcher::ConnectionChange& change = | 137 const GamepadDispatcher::ConnectionChange& change = |
137 GamepadDispatcher::instance().latestConnectionChange(); | 138 GamepadDispatcher::instance().latestConnectionChange(); |
138 | 139 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // Inform the embedder whether it needs to provide gamepad data for us. | 239 // Inform the embedder whether it needs to provide gamepad data for us. |
239 bool visible = page()->isPageVisible(); | 240 bool visible = page()->isPageVisible(); |
240 if (visible && (m_hasEventListener || m_gamepads)) | 241 if (visible && (m_hasEventListener || m_gamepads)) |
241 startUpdatingIfAttached(); | 242 startUpdatingIfAttached(); |
242 else | 243 else |
243 stopUpdating(); | 244 stopUpdating(); |
244 | 245 |
245 if (!visible || !m_hasEventListener) | 246 if (!visible || !m_hasEventListener) |
246 return; | 247 return; |
247 | 248 |
248 // Tell the page what has changed. m_gamepads contains the state before we bec
ame hidden. | 249 // Tell the page what has changed. m_gamepads contains the state before we |
249 // We create a new snapshot and compare them. | 250 // became hidden. We create a new snapshot and compare them. |
250 GamepadList* oldGamepads = m_gamepads.release(); | 251 GamepadList* oldGamepads = m_gamepads.release(); |
251 gamepads(); | 252 gamepads(); |
252 GamepadList* newGamepads = m_gamepads.get(); | 253 GamepadList* newGamepads = m_gamepads.get(); |
253 DCHECK(newGamepads); | 254 DCHECK(newGamepads); |
254 | 255 |
255 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 256 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
256 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0; | 257 Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0; |
257 Gamepad* newGamepad = newGamepads->item(i); | 258 Gamepad* newGamepad = newGamepads->item(i); |
258 bool oldWasConnected = oldGamepad && oldGamepad->connected(); | 259 bool oldWasConnected = oldGamepad && oldGamepad->connected(); |
259 bool newIsConnected = newGamepad && newGamepad->connected(); | 260 bool newIsConnected = newGamepad && newGamepad->connected(); |
260 bool connectedGamepadChanged = oldWasConnected && newIsConnected && | 261 bool connectedGamepadChanged = oldWasConnected && newIsConnected && |
261 oldGamepad->id() != newGamepad->id(); | 262 oldGamepad->id() != newGamepad->id(); |
262 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { | 263 if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) { |
263 oldGamepad->setConnected(false); | 264 oldGamepad->setConnected(false); |
264 m_pendingEvents.append(oldGamepad); | 265 m_pendingEvents.append(oldGamepad); |
265 } | 266 } |
266 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 267 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
267 m_pendingEvents.append(newGamepad); | 268 m_pendingEvents.append(newGamepad); |
268 } | 269 } |
269 } | 270 } |
270 | 271 |
271 if (!m_pendingEvents.isEmpty()) | 272 if (!m_pendingEvents.isEmpty()) |
272 m_dispatchOneEventRunner->runAsync(); | 273 m_dispatchOneEventRunner->runAsync(); |
273 } | 274 } |
274 | 275 |
275 } // namespace blink | 276 } // namespace blink |
OLD | NEW |