| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) | 91 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) |
| 92 { | 92 { |
| 93 return NavigatorGamepad::from(navigator).gamepads(); | 93 return NavigatorGamepad::from(navigator).gamepads(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 GamepadList* NavigatorGamepad::gamepads() | 96 GamepadList* NavigatorGamepad::gamepads() |
| 97 { | 97 { |
| 98 if (!m_gamepads) | 98 if (!m_gamepads) |
| 99 m_gamepads = GamepadList::create(); | 99 m_gamepads = GamepadList::create(); |
| 100 if (window()) { | 100 if (frame() && frame()->domWindow()) { |
| 101 startUpdating(); | 101 startUpdating(); |
| 102 sampleGamepads<Gamepad>(m_gamepads.get()); | 102 sampleGamepads<Gamepad>(m_gamepads.get()); |
| 103 } | 103 } |
| 104 return m_gamepads.get(); | 104 return m_gamepads.get(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void NavigatorGamepad::trace(Visitor* visitor) | 107 void NavigatorGamepad::trace(Visitor* visitor) |
| 108 { | 108 { |
| 109 visitor->trace(m_gamepads); | 109 visitor->trace(m_gamepads); |
| 110 visitor->trace(m_pendingEvents); | 110 visitor->trace(m_pendingEvents); |
| 111 WillBeHeapSupplement<Navigator>::trace(visitor); | 111 WillBeHeapSupplement<Navigator>::trace(visitor); |
| 112 DOMWindowProperty::trace(visitor); | 112 DOMWindowProperty::trace(visitor); |
| 113 PlatformEventController::trace(visitor); | 113 PlatformEventController::trace(visitor); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void NavigatorGamepad::didUpdateData() | 116 void NavigatorGamepad::didUpdateData() |
| 117 { | 117 { |
| 118 // We should stop listening once we detached. | 118 // We should stop listening once we detached. |
| 119 ASSERT(window()); | 119 ASSERT(frame()); |
| 120 ASSERT(frame()->domWindow()); |
| 120 | 121 |
| 121 // We register to the dispatcher before sampling gamepads so we need to chec
k if we actually have an event listener. | 122 // We register to the dispatcher before sampling gamepads so we need to chec
k if we actually have an event listener. |
| 122 if (!m_hasEventListener) | 123 if (!m_hasEventListener) |
| 123 return; | 124 return; |
| 124 | 125 |
| 125 if (window()->document()->activeDOMObjectsAreStopped() || window()->document
()->activeDOMObjectsAreSuspended()) | 126 Document* document = frame()->domWindow()->document(); |
| 127 if (document->activeDOMObjectsAreStopped() || document->activeDOMObjectsAreS
uspended()) |
| 126 return; | 128 return; |
| 127 | 129 |
| 128 const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::insta
nce().latestConnectionChange(); | 130 const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::insta
nce().latestConnectionChange(); |
| 129 | 131 |
| 130 if (!m_gamepads) | 132 if (!m_gamepads) |
| 131 m_gamepads = GamepadList::create(); | 133 m_gamepads = GamepadList::create(); |
| 132 | 134 |
| 133 Gamepad* gamepad = m_gamepads->item(change.index); | 135 Gamepad* gamepad = m_gamepads->item(change.index); |
| 134 if (!gamepad) | 136 if (!gamepad) |
| 135 gamepad = Gamepad::create(); | 137 gamepad = Gamepad::create(); |
| 136 sampleGamepad(change.index, *gamepad, change.pad); | 138 sampleGamepad(change.index, *gamepad, change.pad); |
| 137 m_gamepads->set(change.index, gamepad); | 139 m_gamepads->set(change.index, gamepad); |
| 138 | 140 |
| 139 m_pendingEvents.append(gamepad); | 141 m_pendingEvents.append(gamepad); |
| 140 m_dispatchOneEventRunner.runAsync(); | 142 m_dispatchOneEventRunner.runAsync(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 void NavigatorGamepad::dispatchOneEvent() | 145 void NavigatorGamepad::dispatchOneEvent() |
| 144 { | 146 { |
| 145 ASSERT(window()); | 147 ASSERT(frame()); |
| 148 ASSERT(frame()->domWindow()); |
| 146 ASSERT(!m_pendingEvents.isEmpty()); | 149 ASSERT(!m_pendingEvents.isEmpty()); |
| 147 | 150 |
| 148 Gamepad* gamepad = m_pendingEvents.takeFirst(); | 151 Gamepad* gamepad = m_pendingEvents.takeFirst(); |
| 149 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; | 152 const AtomicString& eventName = gamepad->connected() ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; |
| 150 window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad
)); | 153 frame()->domWindow()->dispatchEvent(GamepadEvent::create(eventName, false, t
rue, gamepad)); |
| 151 | 154 |
| 152 if (!m_pendingEvents.isEmpty()) | 155 if (!m_pendingEvents.isEmpty()) |
| 153 m_dispatchOneEventRunner.runAsync(); | 156 m_dispatchOneEventRunner.runAsync(); |
| 154 } | 157 } |
| 155 | 158 |
| 156 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) | 159 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) |
| 157 : DOMWindowProperty(frame) | 160 : DOMWindowProperty(frame) |
| 158 , PlatformEventController(frame ? frame->page() : 0) | 161 , PlatformEventController(frame ? frame->page() : 0) |
| 159 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0) | 162 , DOMWindowLifecycleObserver(frame ? frame->localDOMWindow() : 0) |
| 160 , m_dispatchOneEventRunner(this, &NavigatorGamepad::dispatchOneEvent) | 163 , m_dispatchOneEventRunner(this, &NavigatorGamepad::dispatchOneEvent) |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 270 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
| 268 m_pendingEvents.append(newGamepad); | 271 m_pendingEvents.append(newGamepad); |
| 269 } | 272 } |
| 270 } | 273 } |
| 271 | 274 |
| 272 if (!m_pendingEvents.isEmpty()) | 275 if (!m_pendingEvents.isEmpty()) |
| 273 m_dispatchOneEventRunner.runAsync(); | 276 m_dispatchOneEventRunner.runAsync(); |
| 274 } | 277 } |
| 275 | 278 |
| 276 } // namespace blink | 279 } // namespace blink |
| OLD | NEW |