OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 MediaDocument::~MediaDocument() | 124 MediaDocument::~MediaDocument() |
125 { | 125 { |
126 ASSERT(!m_replaceMediaElementTimer.isActive()); | 126 ASSERT(!m_replaceMediaElementTimer.isActive()); |
127 } | 127 } |
128 | 128 |
129 PassRefPtr<DocumentParser> MediaDocument::createParser() | 129 PassRefPtr<DocumentParser> MediaDocument::createParser() |
130 { | 130 { |
131 return MediaDocumentParser::create(this); | 131 return MediaDocumentParser::create(this); |
132 } | 132 } |
133 | 133 |
| 134 static inline HTMLVideoElement* descendentVideoElement(Node* node) |
| 135 { |
| 136 ASSERT(node); |
| 137 |
| 138 if (node->hasTagName(videoTag)) |
| 139 return static_cast<HTMLVideoElement*>(node); |
| 140 |
| 141 RefPtr<NodeList> nodeList = node->getElementsByTagNameNS(videoTag.namespaceU
RI(), videoTag.localName()); |
| 142 |
| 143 if (nodeList.get()->length() > 0) |
| 144 return static_cast<HTMLVideoElement*>(nodeList.get()->item(0)); |
| 145 |
| 146 return 0; |
| 147 } |
| 148 |
134 void MediaDocument::defaultEventHandler(Event* event) | 149 void MediaDocument::defaultEventHandler(Event* event) |
135 { | 150 { |
136 // Match the default Quicktime plugin behavior to allow | 151 // Match the default Quicktime plugin behavior to allow |
137 // clicking and double-clicking to pause and play the media. | 152 // clicking and double-clicking to pause and play the media. |
138 Node* targetNode = event->target()->toNode(); | 153 Node* targetNode = event->target()->toNode(); |
139 if (targetNode && targetNode->hasTagName(videoTag)) { | 154 if (!targetNode) |
140 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(targetNode); | 155 return; |
141 if (event->type() == eventNames().clickEvent) { | 156 |
142 if (!video->canPlay()) { | 157 HTMLVideoElement* video = descendentVideoElement(targetNode); |
| 158 if (!video) |
| 159 return; |
| 160 |
| 161 if (event->type() == eventNames().clickEvent) { |
| 162 if (!video->canPlay()) { |
| 163 video->pause(event->fromUserGesture()); |
| 164 event->setDefaultHandled(); |
| 165 } |
| 166 } else if (event->type() == eventNames().dblclickEvent) { |
| 167 if (video->canPlay()) { |
| 168 video->play(event->fromUserGesture()); |
| 169 event->setDefaultHandled(); |
| 170 } |
| 171 } else if (event->type() == eventNames().keydownEvent && event->isKeyboardEv
ent()) { |
| 172 KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event); |
| 173 if (keyboardEvent->keyIdentifier() == "U+0020") { // space |
| 174 if (video->paused()) { |
| 175 if (video->canPlay()) |
| 176 video->play(event->fromUserGesture()); |
| 177 } else |
143 video->pause(event->fromUserGesture()); | 178 video->pause(event->fromUserGesture()); |
144 event->setDefaultHandled(); | 179 event->setDefaultHandled(); |
145 } | |
146 } else if (event->type() == eventNames().dblclickEvent) { | |
147 if (video->canPlay()) { | |
148 video->play(event->fromUserGesture()); | |
149 event->setDefaultHandled(); | |
150 } | |
151 } | |
152 } | |
153 | |
154 if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent())
{ | |
155 HTMLVideoElement* video = 0; | |
156 if (targetNode) { | |
157 if (targetNode->hasTagName(videoTag)) | |
158 video = static_cast<HTMLVideoElement*>(targetNode); | |
159 else { | |
160 RefPtr<NodeList> nodeList = targetNode->getElementsByTagName("vi
deo"); | |
161 if (nodeList.get()->length() > 0) | |
162 video = static_cast<HTMLVideoElement*>(nodeList.get()->item(
0)); | |
163 } | |
164 } | |
165 if (video) { | |
166 KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event); | |
167 if (keyboardEvent->keyIdentifier() == "U+0020") { // space | |
168 if (video->paused()) { | |
169 if (video->canPlay()) | |
170 video->play(event->fromUserGesture()); | |
171 } else | |
172 video->pause(event->fromUserGesture()); | |
173 event->setDefaultHandled(); | |
174 } | |
175 } | 180 } |
176 } | 181 } |
177 } | 182 } |
178 | 183 |
179 void MediaDocument::mediaElementSawUnsupportedTracks() | 184 void MediaDocument::mediaElementSawUnsupportedTracks() |
180 { | 185 { |
181 // The HTMLMediaElement was told it has something that the underlying | 186 // The HTMLMediaElement was told it has something that the underlying |
182 // MediaPlayer cannot handle so we should switch from <video> to <embed> | 187 // MediaPlayer cannot handle so we should switch from <video> to <embed> |
183 // and let the plugin handle this. Don't do it immediately as this | 188 // and let the plugin handle this. Don't do it immediately as this |
184 // function may be called directly from a media engine callback, and | 189 // function may be called directly from a media engine callback, and |
185 // replaceChild will destroy the element, media player, and media engine. | 190 // replaceChild will destroy the element, media player, and media engine. |
186 m_replaceMediaElementTimer.startOneShot(0); | 191 m_replaceMediaElementTimer.startOneShot(0); |
187 } | 192 } |
188 | 193 |
189 void MediaDocument::replaceMediaElementTimerFired(Timer<MediaDocument>*) | 194 void MediaDocument::replaceMediaElementTimerFired(Timer<MediaDocument>*) |
190 { | 195 { |
191 HTMLElement* htmlBody = body(); | 196 HTMLElement* htmlBody = body(); |
192 if (!htmlBody) | 197 if (!htmlBody) |
193 return; | 198 return; |
194 | 199 |
195 // Set body margin width and height to 0 as that is what a PluginDocument us
es. | 200 // Set body margin width and height to 0 as that is what a PluginDocument us
es. |
196 htmlBody->setAttribute(marginwidthAttr, "0"); | 201 htmlBody->setAttribute(marginwidthAttr, "0"); |
197 htmlBody->setAttribute(marginheightAttr, "0"); | 202 htmlBody->setAttribute(marginheightAttr, "0"); |
198 | 203 |
199 RefPtr<NodeList> nodeList = htmlBody->getElementsByTagName("video"); | 204 if (HTMLVideoElement* videoElement = descendentVideoElement(htmlBody)) { |
200 | |
201 if (nodeList.get()->length() > 0) { | |
202 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(nodeList
.get()->item(0)); | |
203 | |
204 RefPtr<Element> element = Document::createElement(embedTag, false); | 205 RefPtr<Element> element = Document::createElement(embedTag, false); |
205 HTMLEmbedElement* embedElement = static_cast<HTMLEmbedElement*>(element.
get()); | 206 HTMLEmbedElement* embedElement = static_cast<HTMLEmbedElement*>(element.
get()); |
206 | 207 |
207 embedElement->setAttribute(widthAttr, "100%"); | 208 embedElement->setAttribute(widthAttr, "100%"); |
208 embedElement->setAttribute(heightAttr, "100%"); | 209 embedElement->setAttribute(heightAttr, "100%"); |
209 embedElement->setAttribute(nameAttr, "plugin"); | 210 embedElement->setAttribute(nameAttr, "plugin"); |
210 embedElement->setAttribute(srcAttr, url().string()); | 211 embedElement->setAttribute(srcAttr, url().string()); |
211 embedElement->setAttribute(typeAttr, frame()->loader()->writer()->mimeTy
pe()); | 212 embedElement->setAttribute(typeAttr, frame()->loader()->writer()->mimeTy
pe()); |
212 | 213 |
213 ExceptionCode ec; | 214 ExceptionCode ec; |
214 videoElement->parentNode()->replaceChild(embedElement, videoElement, ec)
; | 215 videoElement->parentNode()->replaceChild(embedElement, videoElement, ec)
; |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 } | 219 } |
219 #endif | 220 #endif |
OLD | NEW |