Chromium Code Reviews| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 return m_gamepads.get(); | 122 return m_gamepads.get(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void NavigatorGamepad::trace(Visitor* visitor) | 125 void NavigatorGamepad::trace(Visitor* visitor) |
| 126 { | 126 { |
| 127 visitor->trace(m_gamepads); | 127 visitor->trace(m_gamepads); |
| 128 visitor->trace(m_webkitGamepads); | 128 visitor->trace(m_webkitGamepads); |
| 129 WillBeHeapSupplement<Navigator>::trace(visitor); | 129 WillBeHeapSupplement<Navigator>::trace(visitor); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink ::WebGamepad& webGamepad, bool connected) | 132 void NavigatorGamepad::didUpdateData() |
| 133 { | 133 { |
| 134 ASSERT(index < blink::WebGamepads::itemsLengthCap); | |
| 135 ASSERT(connected == webGamepad.connected); | |
| 136 | |
| 137 // We should stop listening once we detached. | 134 // We should stop listening once we detached. |
| 138 ASSERT(window()); | 135 ASSERT(window()); |
| 139 | 136 |
| 140 // We register to the dispatcher before sampling gamepads so we need to chec k if we actually have an event listener. | 137 // We register to the dispatcher before sampling gamepads so we need to chec k if we actually have an event listener. |
| 141 if (!m_hasEventListener) | 138 if (!m_hasEventListener) |
| 142 return; | 139 return; |
| 143 | 140 |
| 144 if (window()->document()->activeDOMObjectsAreStopped() || window()->document ()->activeDOMObjectsAreSuspended()) | 141 if (window()->document()->activeDOMObjectsAreStopped() || window()->document ()->activeDOMObjectsAreSuspended()) |
| 145 return; | 142 return; |
| 146 | 143 |
| 144 unsigned index; | |
| 145 const blink::WebGamepad& webGamepad = GamepadDispatcher::instance().latestGa mepadEventData(index); | |
|
timvolodine
2014/06/16 13:05:17
do you need to pass index here? maybe just return
kbalazs
2014/06/16 17:01:47
Yes, the index is used below, it was an argument o
timvolodine
2014/06/16 17:13:35
ah I see, so that looks confusing to me. maybe int
| |
| 146 | |
| 147 if (!m_gamepads) | 147 if (!m_gamepads) |
| 148 m_gamepads = GamepadList::create(); | 148 m_gamepads = GamepadList::create(); |
| 149 | 149 |
| 150 Gamepad* gamepad = m_gamepads->item(index); | 150 Gamepad* gamepad = m_gamepads->item(index); |
| 151 if (!gamepad) | 151 if (!gamepad) |
| 152 gamepad = Gamepad::create(); | 152 gamepad = Gamepad::create(); |
| 153 sampleGamepad(index, *gamepad, webGamepad); | 153 sampleGamepad(index, *gamepad, webGamepad); |
| 154 m_gamepads->set(index, gamepad); | 154 m_gamepads->set(index, gamepad); |
| 155 | 155 |
| 156 const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected : EventTypeNames::gamepaddisconnected; | 156 const AtomicString& eventName = webGamepad.connected ? EventTypeNames::gamep adconnected : EventTypeNames::gamepaddisconnected; |
| 157 RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, fal se, true, gamepad); | 157 window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad )); |
| 158 window()->dispatchEvent(event); | |
| 159 } | 158 } |
| 160 | 159 |
| 161 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) | 160 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) |
| 162 : DOMWindowProperty(frame) | 161 : DOMWindowProperty(frame) |
| 163 , DeviceSensorEventController(frame ? frame->page() : 0) | 162 , DeviceEventControllerBase(frame ? frame->page() : 0) |
| 164 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) | 163 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) |
| 165 { | 164 { |
| 166 } | 165 } |
| 167 | 166 |
| 168 NavigatorGamepad::~NavigatorGamepad() | 167 NavigatorGamepad::~NavigatorGamepad() |
| 169 { | 168 { |
| 170 } | 169 } |
| 171 | 170 |
| 172 const char* NavigatorGamepad::supplementName() | 171 const char* NavigatorGamepad::supplementName() |
| 173 { | 172 { |
| 174 return "NavigatorGamepad"; | 173 return "NavigatorGamepad"; |
| 175 } | 174 } |
| 176 | 175 |
| 177 void NavigatorGamepad::willDestroyGlobalObjectInFrame() | 176 void NavigatorGamepad::willDestroyGlobalObjectInFrame() |
| 178 { | 177 { |
| 179 stopUpdating(); | 178 stopUpdating(); |
| 180 DOMWindowProperty::willDestroyGlobalObjectInFrame(); | 179 DOMWindowProperty::willDestroyGlobalObjectInFrame(); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void NavigatorGamepad::willDetachGlobalObjectFromFrame() | 182 void NavigatorGamepad::willDetachGlobalObjectFromFrame() |
| 184 { | 183 { |
| 185 stopUpdating(); | 184 stopUpdating(); |
| 186 DOMWindowProperty::willDetachGlobalObjectFromFrame(); | 185 DOMWindowProperty::willDetachGlobalObjectFromFrame(); |
| 187 } | 186 } |
| 188 | 187 |
| 189 void NavigatorGamepad::registerWithDispatcher() | 188 void NavigatorGamepad::registerWithDispatcher() |
| 190 { | 189 { |
| 191 GamepadDispatcher::instance().addClient(this); | 190 GamepadDispatcher::instance().addController(this); |
| 192 } | 191 } |
| 193 | 192 |
| 194 void NavigatorGamepad::unregisterWithDispatcher() | 193 void NavigatorGamepad::unregisterWithDispatcher() |
| 195 { | 194 { |
| 196 GamepadDispatcher::instance().removeClient(this); | 195 GamepadDispatcher::instance().removeController(this); |
| 197 } | 196 } |
| 198 | 197 |
| 199 bool NavigatorGamepad::hasLastData() | 198 bool NavigatorGamepad::hasLastData() |
| 200 { | 199 { |
| 201 // Gamepad data is polled instead of pushed. | 200 // Gamepad data is polled instead of pushed. |
| 202 return false; | 201 return false; |
| 203 } | 202 } |
| 204 | 203 |
| 205 PassRefPtrWillBeRawPtr<Event> NavigatorGamepad::getLastEvent() | |
| 206 { | |
| 207 // This is called only when hasLastData() is true. | |
| 208 ASSERT_NOT_REACHED(); | |
| 209 return nullptr; | |
| 210 } | |
| 211 | |
| 212 bool NavigatorGamepad::isNullEvent(Event*) | |
| 213 { | |
| 214 // This is called only when hasLastData() is true. | |
| 215 ASSERT_NOT_REACHED(); | |
| 216 return false; | |
| 217 } | |
| 218 | |
| 219 Document* NavigatorGamepad::document() | |
| 220 { | |
| 221 return window() ? window()->document() : 0; | |
| 222 } | |
| 223 | |
| 224 static bool isGamepadEvent(const AtomicString& eventType) | 204 static bool isGamepadEvent(const AtomicString& eventType) |
| 225 { | 205 { |
| 226 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy peNames::gamepaddisconnected; | 206 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy peNames::gamepaddisconnected; |
| 227 } | 207 } |
| 228 | 208 |
| 229 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event Type) | 209 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event Type) |
| 230 { | 210 { |
| 231 if (RuntimeEnabledFeatures::gamepadEnabled() && isGamepadEvent(eventType)) { | 211 if (RuntimeEnabledFeatures::gamepadEnabled() && isGamepadEvent(eventType)) { |
| 232 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | 212 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
| 233 startUpdating(); | 213 startUpdating(); |
| 234 m_hasEventListener = true; | 214 m_hasEventListener = true; |
| 235 } | 215 } |
| 236 } | 216 } |
| 237 | 217 |
| 238 void NavigatorGamepad::didRemoveEventListener(DOMWindow*, const AtomicString& ev entType) | 218 void NavigatorGamepad::didRemoveEventListener(DOMWindow* window, const AtomicStr ing& eventType) |
| 239 { | 219 { |
| 240 if (isGamepadEvent(eventType)) | 220 if (isGamepadEvent(eventType) |
| 221 && !window->hasEventListeners(EventTypeNames::gamepadconnected) | |
| 222 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) { | |
| 241 m_hasEventListener = false; | 223 m_hasEventListener = false; |
| 224 } | |
| 242 } | 225 } |
| 243 | 226 |
| 244 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*) | 227 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*) |
| 245 { | 228 { |
| 246 m_hasEventListener = false; | 229 m_hasEventListener = false; |
| 247 } | 230 } |
| 248 | 231 |
| 249 } // namespace WebCore | 232 } // namespace WebCore |
| OLD | NEW |