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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return NavigatorGamepad::from(navigator).webkitGamepads(); | 95 return NavigatorGamepad::from(navigator).webkitGamepads(); |
96 } | 96 } |
97 | 97 |
98 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) | 98 GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) |
99 { | 99 { |
100 return NavigatorGamepad::from(navigator).gamepads(); | 100 return NavigatorGamepad::from(navigator).gamepads(); |
101 } | 101 } |
102 | 102 |
103 WebKitGamepadList* NavigatorGamepad::webkitGamepads() | 103 WebKitGamepadList* NavigatorGamepad::webkitGamepads() |
104 { | 104 { |
| 105 m_wasPolled = true; |
105 if (!m_webkitGamepads) | 106 if (!m_webkitGamepads) |
106 m_webkitGamepads = WebKitGamepadList::create(); | 107 m_webkitGamepads = WebKitGamepadList::create(); |
107 if (window()) { | 108 if (window()) { |
108 startUpdating(); | 109 startUpdating(); |
109 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get()); | 110 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get()); |
110 } | 111 } |
111 return m_webkitGamepads.get(); | 112 return m_webkitGamepads.get(); |
112 } | 113 } |
113 | 114 |
114 GamepadList* NavigatorGamepad::gamepads() | 115 GamepadList* NavigatorGamepad::gamepads() |
115 { | 116 { |
| 117 m_wasPolled = true; |
116 if (!m_gamepads) | 118 if (!m_gamepads) |
117 m_gamepads = GamepadList::create(); | 119 m_gamepads = GamepadList::create(); |
118 if (window()) { | 120 if (window()) { |
119 startUpdating(); | 121 startUpdating(); |
120 sampleGamepads<Gamepad>(m_gamepads.get()); | 122 sampleGamepads<Gamepad>(m_gamepads.get()); |
121 } | 123 } |
122 return m_gamepads.get(); | 124 return m_gamepads.get(); |
123 } | 125 } |
124 | 126 |
125 void NavigatorGamepad::trace(Visitor* visitor) | 127 void NavigatorGamepad::trace(Visitor* visitor) |
(...skipping 27 matching lines...) Expand all Loading... |
153 m_gamepads->set(change.index, gamepad); | 155 m_gamepads->set(change.index, gamepad); |
154 | 156 |
155 const AtomicString& eventName = change.pad.connected ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; | 157 const AtomicString& eventName = change.pad.connected ? EventTypeNames::gamep
adconnected : EventTypeNames::gamepaddisconnected; |
156 window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad
)); | 158 window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad
)); |
157 } | 159 } |
158 | 160 |
159 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) | 161 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) |
160 : DOMWindowProperty(frame) | 162 : DOMWindowProperty(frame) |
161 , DeviceEventControllerBase(frame ? frame->page() : 0) | 163 , DeviceEventControllerBase(frame ? frame->page() : 0) |
162 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) | 164 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) |
| 165 , m_wasPolled(false) |
163 { | 166 { |
164 } | 167 } |
165 | 168 |
166 NavigatorGamepad::~NavigatorGamepad() | 169 NavigatorGamepad::~NavigatorGamepad() |
167 { | 170 { |
168 } | 171 } |
169 | 172 |
170 const char* NavigatorGamepad::supplementName() | 173 const char* NavigatorGamepad::supplementName() |
171 { | 174 { |
172 return "NavigatorGamepad"; | 175 return "NavigatorGamepad"; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) { | 224 && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) { |
222 m_hasEventListener = false; | 225 m_hasEventListener = false; |
223 } | 226 } |
224 } | 227 } |
225 | 228 |
226 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) | 229 void NavigatorGamepad::didRemoveAllEventListeners(LocalDOMWindow*) |
227 { | 230 { |
228 m_hasEventListener = false; | 231 m_hasEventListener = false; |
229 } | 232 } |
230 | 233 |
| 234 void NavigatorGamepad::pageVisibilityChanged() |
| 235 { |
| 236 // Inform the embedder whether it needs to provide gamepad data for us. |
| 237 if (page()->visibilityState() == PageVisibilityStateVisible && (m_hasEventLi
stener || m_wasPolled)) |
| 238 startUpdating(); |
| 239 else |
| 240 stopUpdating(); |
| 241 } |
| 242 |
231 } // namespace WebCore | 243 } // namespace WebCore |
OLD | NEW |