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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 if (!document.frame() || !document.frame()->domWindow()) | 75 if (!document.frame() || !document.frame()->domWindow()) |
| 76 return 0; | 76 return 0; |
| 77 Navigator& navigator = *document.frame()->domWindow()->navigator(); | 77 Navigator& navigator = *document.frame()->domWindow()->navigator(); |
| 78 return &from(navigator); | 78 return &from(navigator); |
| 79 } | 79 } |
| 80 | 80 |
| 81 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) { | 81 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) { |
| 82 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>( | 82 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>( |
| 83 Supplement<Navigator>::from(navigator, supplementName())); | 83 Supplement<Navigator>::from(navigator, supplementName())); |
| 84 if (!supplement) { | 84 if (!supplement) { |
| 85 supplement = new NavigatorGamepad(navigator.frame()); | 85 supplement = new NavigatorGamepad(navigator); |
| 86 provideTo(navigator, supplementName(), supplement); | 86 provideTo(navigator, supplementName(), supplement); |
| 87 } | 87 } |
| 88 return *supplement; | 88 return *supplement; |
| 89 } | 89 } |
| 90 | 90 |
| 91 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) { | 91 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) { |
| 92 return NavigatorGamepad::from(navigator).gamepads(); | 92 return NavigatorGamepad::from(navigator).gamepads(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 GamepadList* NavigatorGamepad::gamepads() { | 95 GamepadList* NavigatorGamepad::gamepads() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 const AtomicString& eventName = gamepad->connected() | 159 const AtomicString& eventName = gamepad->connected() |
| 160 ? EventTypeNames::gamepadconnected | 160 ? EventTypeNames::gamepadconnected |
| 161 : EventTypeNames::gamepaddisconnected; | 161 : EventTypeNames::gamepaddisconnected; |
| 162 document->frame()->domWindow()->dispatchEvent( | 162 document->frame()->domWindow()->dispatchEvent( |
| 163 GamepadEvent::create(eventName, false, true, gamepad)); | 163 GamepadEvent::create(eventName, false, true, gamepad)); |
| 164 | 164 |
| 165 if (!m_pendingEvents.isEmpty()) | 165 if (!m_pendingEvents.isEmpty()) |
| 166 m_dispatchOneEventRunner->runAsync(); | 166 m_dispatchOneEventRunner->runAsync(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) | 169 NavigatorGamepad::NavigatorGamepad(Navigator& navigator) |
| 170 : ContextLifecycleObserver(frame->document()), | 170 : Supplement<Navigator>(navigator), |
| 171 PlatformEventController(frame ? frame->page() : 0), | 171 ContextLifecycleObserver(navigator.frame()->document()), |
|
sof
2017/01/23 08:05:31
ftr, crbug.com/683520 suggests that there's a miss
| |
| 172 PlatformEventController(navigator.frame() ? navigator.frame()->page() | |
| 173 : 0), | |
| 172 m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create( | 174 m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create( |
| 173 this, | 175 this, |
| 174 &NavigatorGamepad::dispatchOneEvent)) { | 176 &NavigatorGamepad::dispatchOneEvent)) { |
| 175 if (frame) | 177 if (navigator.frame()) |
| 176 frame->domWindow()->registerEventListenerObserver(this); | 178 navigator.frame()->domWindow()->registerEventListenerObserver(this); |
| 177 } | 179 } |
| 178 | 180 |
| 179 NavigatorGamepad::~NavigatorGamepad() {} | 181 NavigatorGamepad::~NavigatorGamepad() {} |
| 180 | 182 |
| 181 const char* NavigatorGamepad::supplementName() { | 183 const char* NavigatorGamepad::supplementName() { |
| 182 return "NavigatorGamepad"; | 184 return "NavigatorGamepad"; |
| 183 } | 185 } |
| 184 | 186 |
| 185 void NavigatorGamepad::contextDestroyed(ExecutionContext*) { | 187 void NavigatorGamepad::contextDestroyed(ExecutionContext*) { |
| 186 stopUpdating(); | 188 stopUpdating(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 268 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
| 267 m_pendingEvents.append(newGamepad); | 269 m_pendingEvents.append(newGamepad); |
| 268 } | 270 } |
| 269 } | 271 } |
| 270 | 272 |
| 271 if (!m_pendingEvents.isEmpty()) | 273 if (!m_pendingEvents.isEmpty()) |
| 272 m_dispatchOneEventRunner->runAsync(); | 274 m_dispatchOneEventRunner->runAsync(); |
| 273 } | 275 } |
| 274 | 276 |
| 275 } // namespace blink | 277 } // namespace blink |
| OLD | NEW |