void NavigatorGamepad::didUpdateData() { // We should stop listening once we detached. ASSERT(frame()); ASSERT(frame()->domWindow()); // We register to the dispatcher before sampling gamepads so we need to check if we actually have an event listener. if (!m_hasEventListener) return; Document* document = frame()->domWindow()->document(); if (document->activeDOMObjectsAreStopped() || document->activeDOMObjectsAreSuspended()) return; const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::instance().latestConnectionChange(); if (!m_gamepads) m_gamepads = GamepadList::create(); Gamepad* gamepad = m_gamepads->item(change.index); if (!gamepad) gamepad = Gamepad::create(); sampleGamepad(change.index, *gamepad, change.pad); m_gamepads->set(change.index, gamepad); m_pendingEvents.append(gamepad); m_dispatchOneEventRunner.runAsync(); }
void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink::WebGamepad& webGamepad, bool connected) { ASSERT(index < blink::WebGamepads::itemsLengthCap); ASSERT(connected == webGamepad.connected); // We should stop listening once we detached. ASSERT(window()); // We register to the dispatcher before sampling gamepads so we need to check if we actually have an event listener. if (!m_hasEventListener) return; if (window()->document()->activeDOMObjectsAreStopped() || window()->document()->activeDOMObjectsAreSuspended()) return; if (!m_gamepads) m_gamepads = GamepadList::create(); Gamepad* gamepad = m_gamepads->item(index); if (!gamepad) gamepad = Gamepad::create(); sampleGamepad(index, *gamepad, webGamepad); m_gamepads->set(index, gamepad); const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected : EventTypeNames::gamepaddisconnected; RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, false, true, gamepad); window()->dispatchEvent(event); }
static void sampleGamepads(ListType* into) { WebGamepads gamepads; GamepadDispatcher::instance().sampleGamepads(gamepads); for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { WebGamepad& webGamepad = gamepads.items[i]; if (i < gamepads.length && webGamepad.connected) { GamepadType* gamepad = into->item(i); if (!gamepad) gamepad = GamepadType::create(); sampleGamepad(i, *gamepad, webGamepad); into->set(i, gamepad); } else { into->set(i, 0); } } }