Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: third_party/WebKit/Source/modules/gamepad/NavigatorGamepad.cpp

Issue 2646383002: Use a new Supplement constructor for (Worker)Navigator supplements (Closed)
Patch Set: temp Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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() ? navigator.frame()->document()
172 : nullptr),
173 PlatformEventController(navigator.frame() ? navigator.frame()->page()
174 : nullptr),
172 m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create( 175 m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorGamepad>::create(
173 this, 176 this,
174 &NavigatorGamepad::dispatchOneEvent)) { 177 &NavigatorGamepad::dispatchOneEvent)) {
175 if (frame) 178 if (navigator.frame())
176 frame->domWindow()->registerEventListenerObserver(this); 179 navigator.frame()->domWindow()->registerEventListenerObserver(this);
177 } 180 }
178 181
179 NavigatorGamepad::~NavigatorGamepad() {} 182 NavigatorGamepad::~NavigatorGamepad() {}
180 183
181 const char* NavigatorGamepad::supplementName() { 184 const char* NavigatorGamepad::supplementName() {
182 return "NavigatorGamepad"; 185 return "NavigatorGamepad";
183 } 186 }
184 187
185 void NavigatorGamepad::contextDestroyed(ExecutionContext*) { 188 void NavigatorGamepad::contextDestroyed(ExecutionContext*) {
186 stopUpdating(); 189 stopUpdating();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { 269 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
267 m_pendingEvents.append(newGamepad); 270 m_pendingEvents.append(newGamepad);
268 } 271 }
269 } 272 }
270 273
271 if (!m_pendingEvents.isEmpty()) 274 if (!m_pendingEvents.isEmpty())
272 m_dispatchOneEventRunner->runAsync(); 275 m_dispatchOneEventRunner->runAsync();
273 } 276 }
274 277
275 } // namespace blink 278 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698