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

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

Issue 336693004: Deduplicate DeviceEvent* classes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: latestConnectionChange Created 6 years, 6 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GamepadDispatcher::ConnectionChange change = GamepadDispatcher::instance().l atestConnectionChange();
timvolodine 2014/06/17 14:23:51 const ..& ?
145
147 if (!m_gamepads) 146 if (!m_gamepads)
148 m_gamepads = GamepadList::create(); 147 m_gamepads = GamepadList::create();
149 148
150 Gamepad* gamepad = m_gamepads->item(index); 149 Gamepad* gamepad = m_gamepads->item(change.index);
151 if (!gamepad) 150 if (!gamepad)
152 gamepad = Gamepad::create(); 151 gamepad = Gamepad::create();
153 sampleGamepad(index, *gamepad, webGamepad); 152 sampleGamepad(change.index, *gamepad, change.pad);
154 m_gamepads->set(index, gamepad); 153 m_gamepads->set(change.index, gamepad);
155 154
156 const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected : EventTypeNames::gamepaddisconnected; 155 const AtomicString& eventName = change.pad.connected ? EventTypeNames::gamep adconnected : EventTypeNames::gamepaddisconnected;
157 RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, fal se, true, gamepad); 156 window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad ));
158 window()->dispatchEvent(event);
159 } 157 }
160 158
161 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) 159 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame)
162 : DOMWindowProperty(frame) 160 : DOMWindowProperty(frame)
163 , DeviceSensorEventController(frame ? frame->page() : 0) 161 , DeviceEventControllerBase(frame ? frame->page() : 0)
164 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) 162 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0)
165 { 163 {
166 } 164 }
167 165
168 NavigatorGamepad::~NavigatorGamepad() 166 NavigatorGamepad::~NavigatorGamepad()
169 { 167 {
170 } 168 }
171 169
172 const char* NavigatorGamepad::supplementName() 170 const char* NavigatorGamepad::supplementName()
173 { 171 {
174 return "NavigatorGamepad"; 172 return "NavigatorGamepad";
175 } 173 }
176 174
177 void NavigatorGamepad::willDestroyGlobalObjectInFrame() 175 void NavigatorGamepad::willDestroyGlobalObjectInFrame()
178 { 176 {
179 stopUpdating(); 177 stopUpdating();
180 DOMWindowProperty::willDestroyGlobalObjectInFrame(); 178 DOMWindowProperty::willDestroyGlobalObjectInFrame();
181 } 179 }
182 180
183 void NavigatorGamepad::willDetachGlobalObjectFromFrame() 181 void NavigatorGamepad::willDetachGlobalObjectFromFrame()
184 { 182 {
185 stopUpdating(); 183 stopUpdating();
186 DOMWindowProperty::willDetachGlobalObjectFromFrame(); 184 DOMWindowProperty::willDetachGlobalObjectFromFrame();
187 } 185 }
188 186
189 void NavigatorGamepad::registerWithDispatcher() 187 void NavigatorGamepad::registerWithDispatcher()
190 { 188 {
191 GamepadDispatcher::instance().addClient(this); 189 GamepadDispatcher::instance().addController(this);
192 } 190 }
193 191
194 void NavigatorGamepad::unregisterWithDispatcher() 192 void NavigatorGamepad::unregisterWithDispatcher()
195 { 193 {
196 GamepadDispatcher::instance().removeClient(this); 194 GamepadDispatcher::instance().removeController(this);
197 } 195 }
198 196
199 bool NavigatorGamepad::hasLastData() 197 bool NavigatorGamepad::hasLastData()
200 { 198 {
201 // Gamepad data is polled instead of pushed. 199 // Gamepad data is polled instead of pushed.
202 return false; 200 return false;
203 } 201 }
204 202
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) 203 static bool isGamepadEvent(const AtomicString& eventType)
225 { 204 {
226 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy peNames::gamepaddisconnected; 205 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy peNames::gamepaddisconnected;
227 } 206 }
228 207
229 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event Type) 208 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event Type)
230 { 209 {
231 if (RuntimeEnabledFeatures::gamepadEnabled() && isGamepadEvent(eventType)) { 210 if (RuntimeEnabledFeatures::gamepadEnabled() && isGamepadEvent(eventType)) {
232 if (page() && page()->visibilityState() == PageVisibilityStateVisible) 211 if (page() && page()->visibilityState() == PageVisibilityStateVisible)
233 startUpdating(); 212 startUpdating();
234 m_hasEventListener = true; 213 m_hasEventListener = true;
235 } 214 }
236 } 215 }
237 216
238 void NavigatorGamepad::didRemoveEventListener(DOMWindow*, const AtomicString& ev entType) 217 void NavigatorGamepad::didRemoveEventListener(DOMWindow* window, const AtomicStr ing& eventType)
239 { 218 {
240 if (isGamepadEvent(eventType)) 219 if (isGamepadEvent(eventType)
220 && !window->hasEventListeners(EventTypeNames::gamepadconnected)
221 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) {
241 m_hasEventListener = false; 222 m_hasEventListener = false;
223 }
242 } 224 }
243 225
244 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*) 226 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*)
245 { 227 {
246 m_hasEventListener = false; 228 m_hasEventListener = false;
247 } 229 }
248 230
249 } // namespace WebCore 231 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698