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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (!document.frame() || !document.frame()->domWindow()) | 77 if (!document.frame() || !document.frame()->domWindow()) |
78 return 0; | 78 return 0; |
79 Navigator& navigator = document.frame()->domWindow()->navigator(); | 79 Navigator& navigator = document.frame()->domWindow()->navigator(); |
80 return &from(navigator); | 80 return &from(navigator); |
81 } | 81 } |
82 | 82 |
83 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) | 83 NavigatorGamepad& NavigatorGamepad::from(Navigator& navigator) |
84 { | 84 { |
85 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(WillBeHeapSupp
lement<Navigator>::from(navigator, supplementName())); | 85 NavigatorGamepad* supplement = static_cast<NavigatorGamepad*>(WillBeHeapSupp
lement<Navigator>::from(navigator, supplementName())); |
86 if (!supplement) { | 86 if (!supplement) { |
87 supplement = new NavigatorGamepad(*navigator.frame()->document()); | 87 supplement = new NavigatorGamepad(navigator.frame()); |
88 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); | 88 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); |
89 } | 89 } |
90 return *supplement; | 90 return *supplement; |
91 } | 91 } |
92 | 92 |
93 WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator) | 93 WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator) |
94 { | 94 { |
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 startUpdating(); | |
106 if (!m_webkitGamepads) | 105 if (!m_webkitGamepads) |
107 m_webkitGamepads = WebKitGamepadList::create(); | 106 m_webkitGamepads = WebKitGamepadList::create(); |
108 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get()); | 107 if (window()) { |
| 108 startUpdating(); |
| 109 sampleGamepads<WebKitGamepad>(m_webkitGamepads.get()); |
| 110 } |
109 return m_webkitGamepads.get(); | 111 return m_webkitGamepads.get(); |
110 } | 112 } |
111 | 113 |
112 GamepadList* NavigatorGamepad::gamepads() | 114 GamepadList* NavigatorGamepad::gamepads() |
113 { | 115 { |
114 startUpdating(); | |
115 if (!m_gamepads) | 116 if (!m_gamepads) |
116 m_gamepads = GamepadList::create(); | 117 m_gamepads = GamepadList::create(); |
117 sampleGamepads<Gamepad>(m_gamepads.get()); | 118 if (window()) { |
| 119 startUpdating(); |
| 120 sampleGamepads<Gamepad>(m_gamepads.get()); |
| 121 } |
118 return m_gamepads.get(); | 122 return m_gamepads.get(); |
119 } | 123 } |
120 | 124 |
121 void NavigatorGamepad::trace(Visitor* visitor) | 125 void NavigatorGamepad::trace(Visitor* visitor) |
122 { | 126 { |
123 visitor->trace(m_gamepads); | 127 visitor->trace(m_gamepads); |
124 visitor->trace(m_webkitGamepads); | 128 visitor->trace(m_webkitGamepads); |
125 } | 129 } |
126 | 130 |
127 void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink
::WebGamepad& webGamepad, bool connected) | 131 void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink
::WebGamepad& webGamepad, bool connected) |
(...skipping 18 matching lines...) Expand all Loading... |
146 if (!gamepad) | 150 if (!gamepad) |
147 gamepad = Gamepad::create(); | 151 gamepad = Gamepad::create(); |
148 sampleGamepad(index, *gamepad, webGamepad); | 152 sampleGamepad(index, *gamepad, webGamepad); |
149 m_gamepads->set(index, gamepad); | 153 m_gamepads->set(index, gamepad); |
150 | 154 |
151 const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected
: EventTypeNames::gamepaddisconnected; | 155 const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected
: EventTypeNames::gamepaddisconnected; |
152 RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, fal
se, true, gamepad); | 156 RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, fal
se, true, gamepad); |
153 window()->dispatchEvent(event); | 157 window()->dispatchEvent(event); |
154 } | 158 } |
155 | 159 |
156 NavigatorGamepad::NavigatorGamepad(Document& document) | 160 NavigatorGamepad::NavigatorGamepad(LocalFrame* frame) |
157 : DOMWindowProperty(document.frame()) | 161 : DOMWindowProperty(frame) |
158 , DeviceSensorEventController(document) | 162 , DeviceSensorEventController(frame ? frame->document() : 0) |
159 , DOMWindowLifecycleObserver(document.frame()->domWindow()) | 163 , DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0) |
160 { | 164 { |
161 } | 165 } |
162 | 166 |
163 NavigatorGamepad::~NavigatorGamepad() | 167 NavigatorGamepad::~NavigatorGamepad() |
164 { | 168 { |
165 } | 169 } |
166 | 170 |
167 const char* NavigatorGamepad::supplementName() | 171 const char* NavigatorGamepad::supplementName() |
168 { | 172 { |
169 return "NavigatorGamepad"; | 173 return "NavigatorGamepad"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return nullptr; | 208 return nullptr; |
205 } | 209 } |
206 | 210 |
207 bool NavigatorGamepad::isNullEvent(Event*) | 211 bool NavigatorGamepad::isNullEvent(Event*) |
208 { | 212 { |
209 // This is called only when hasLastData() is true. | 213 // This is called only when hasLastData() is true. |
210 ASSERT_NOT_REACHED(); | 214 ASSERT_NOT_REACHED(); |
211 return false; | 215 return false; |
212 } | 216 } |
213 | 217 |
| 218 static bool isGamepadEvent(const AtomicString& eventType) |
| 219 { |
| 220 return eventType == EventTypeNames::gamepadconnected || eventType == EventTy
peNames::gamepaddisconnected; |
| 221 } |
| 222 |
214 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event
Type) | 223 void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event
Type) |
215 { | 224 { |
216 if (RuntimeEnabledFeatures::gamepadEnabled() && (eventType == EventTypeNames
::gamepadconnected || eventType == EventTypeNames::gamepaddisconnected)) { | 225 if (RuntimeEnabledFeatures::gamepadEnabled() && isGamepadEvent(eventType)) { |
217 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | 226 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
218 startUpdating(); | 227 startUpdating(); |
219 m_hasEventListener = true; | 228 m_hasEventListener = true; |
220 } | 229 } |
221 } | 230 } |
222 | 231 |
223 void NavigatorGamepad::didRemoveEventListener(DOMWindow*, const AtomicString& ev
entType) | 232 void NavigatorGamepad::didRemoveEventListener(DOMWindow*, const AtomicString& ev
entType) |
224 { | 233 { |
225 if (eventType == EventTypeNames::gamepadconnected || eventType == EventTypeN
ames::gamepaddisconnected) | 234 if (isGamepadEvent(eventType)) |
226 m_hasEventListener = false; | 235 m_hasEventListener = false; |
227 } | 236 } |
228 | 237 |
229 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*) | 238 void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*) |
230 { | 239 { |
231 m_hasEventListener = false; | 240 m_hasEventListener = false; |
232 } | 241 } |
233 | 242 |
234 } // namespace WebCore | 243 } // namespace WebCore |
OLD | NEW |