| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 | 214 |
| 215 static bool isGamepadEvent(const AtomicString& eventType) | 215 static bool isGamepadEvent(const AtomicString& eventType) |
| 216 { | 216 { |
| 217 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy
peNames::gamepaddisconnected; | 217 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy
peNames::gamepaddisconnected; |
| 218 } | 218 } |
| 219 | 219 |
| 220 void NavigatorGamepad::didAddEventListener(LocalDOMWindow*, const AtomicString&
eventType) | 220 void NavigatorGamepad::didAddEventListener(LocalDOMWindow*, const AtomicString&
eventType) |
| 221 { | 221 { |
| 222 if (isGamepadEvent(eventType)) { | 222 if (isGamepadEvent(eventType)) { |
| 223 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | 223 if (page() && page()->isPageVisible()) |
| 224 startUpdatingIfAttached(); | 224 startUpdatingIfAttached(); |
| 225 m_hasEventListener = true; | 225 m_hasEventListener = true; |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void NavigatorGamepad::didRemoveEventListener(LocalDOMWindow* window, const Atom
icString& eventType) | 229 void NavigatorGamepad::didRemoveEventListener(LocalDOMWindow* window, const Atom
icString& eventType) |
| 230 { | 230 { |
| 231 if (isGamepadEvent(eventType) | 231 if (isGamepadEvent(eventType) |
| 232 && !window->hasEventListeners(EventTypeNames::gamepadconnected) | 232 && !window->hasEventListeners(EventTypeNames::gamepadconnected) |
| 233 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) { | 233 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) { |
| 234 didRemoveGamepadEventListeners(); | 234 didRemoveGamepadEventListeners(); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) | 238 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) |
| 239 { | 239 { |
| 240 didRemoveGamepadEventListeners(); | 240 didRemoveGamepadEventListeners(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void NavigatorGamepad::didRemoveGamepadEventListeners() | 243 void NavigatorGamepad::didRemoveGamepadEventListeners() |
| 244 { | 244 { |
| 245 m_hasEventListener = false; | 245 m_hasEventListener = false; |
| 246 m_dispatchOneEventRunner->stop(); | 246 m_dispatchOneEventRunner->stop(); |
| 247 m_pendingEvents.clear(); | 247 m_pendingEvents.clear(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void NavigatorGamepad::pageVisibilityChanged() | 250 void NavigatorGamepad::pageVisibilityChanged() |
| 251 { | 251 { |
| 252 // Inform the embedder whether it needs to provide gamepad data for us. | 252 // Inform the embedder whether it needs to provide gamepad data for us. |
| 253 bool visible = page()->visibilityState() == PageVisibilityStateVisible; | 253 bool visible = page()->isPageVisible(); |
| 254 if (visible && (m_hasEventListener || m_gamepads)) | 254 if (visible && (m_hasEventListener || m_gamepads)) |
| 255 startUpdatingIfAttached(); | 255 startUpdatingIfAttached(); |
| 256 else | 256 else |
| 257 stopUpdating(); | 257 stopUpdating(); |
| 258 | 258 |
| 259 if (!visible || !m_hasEventListener) | 259 if (!visible || !m_hasEventListener) |
| 260 return; | 260 return; |
| 261 | 261 |
| 262 // Tell the page what has changed. m_gamepads contains the state before we b
ecame hidden. | 262 // Tell the page what has changed. m_gamepads contains the state before we b
ecame hidden. |
| 263 // We create a new snapshot and compare them. | 263 // We create a new snapshot and compare them. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 279 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { | 279 if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) { |
| 280 m_pendingEvents.append(newGamepad); | 280 m_pendingEvents.append(newGamepad); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 if (!m_pendingEvents.isEmpty()) | 284 if (!m_pendingEvents.isEmpty()) |
| 285 m_dispatchOneEventRunner->runAsync(); | 285 m_dispatchOneEventRunner->runAsync(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |