| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "core/html/MediaDocument.h" | 28 #include "core/html/MediaDocument.h" |
| 29 | 29 |
| 30 #include "HTMLNames.h" | 30 #include "HTMLNames.h" |
| 31 #include "bindings/v8/ExceptionStatePlaceholder.h" | 31 #include "bindings/v8/ExceptionStatePlaceholder.h" |
| 32 #include "core/dom/NodeTraversal.h" | 32 #include "core/dom/ElementTraversal.h" |
| 33 #include "core/dom/RawDataDocumentParser.h" | 33 #include "core/dom/RawDataDocumentParser.h" |
| 34 #include "core/events/KeyboardEvent.h" | 34 #include "core/events/KeyboardEvent.h" |
| 35 #include "core/events/ThreadLocalEventNames.h" | 35 #include "core/events/ThreadLocalEventNames.h" |
| 36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 37 #include "core/html/HTMLBodyElement.h" | 37 #include "core/html/HTMLBodyElement.h" |
| 38 #include "core/html/HTMLHeadElement.h" | 38 #include "core/html/HTMLHeadElement.h" |
| 39 #include "core/html/HTMLHtmlElement.h" | 39 #include "core/html/HTMLHtmlElement.h" |
| 40 #include "core/html/HTMLMetaElement.h" | 40 #include "core/html/HTMLMetaElement.h" |
| 41 #include "core/html/HTMLSourceElement.h" | 41 #include "core/html/HTMLSourceElement.h" |
| 42 #include "core/html/HTMLVideoElement.h" | 42 #include "core/html/HTMLVideoElement.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 { | 122 { |
| 123 setCompatibilityMode(QuirksMode); | 123 setCompatibilityMode(QuirksMode); |
| 124 lockCompatibilityMode(); | 124 lockCompatibilityMode(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 PassRefPtr<DocumentParser> MediaDocument::createParser() | 127 PassRefPtr<DocumentParser> MediaDocument::createParser() |
| 128 { | 128 { |
| 129 return MediaDocumentParser::create(this); | 129 return MediaDocumentParser::create(this); |
| 130 } | 130 } |
| 131 | 131 |
| 132 static inline HTMLVideoElement* descendentVideoElement(Node* root) | |
| 133 { | |
| 134 ASSERT(root); | |
| 135 | |
| 136 for (Node* node = root; node; node = NodeTraversal::next(*node, root)) { | |
| 137 if (node->hasTagName(videoTag)) | |
| 138 return toHTMLVideoElement(node); | |
| 139 } | |
| 140 | |
| 141 return 0; | |
| 142 } | |
| 143 | |
| 144 void MediaDocument::defaultEventHandler(Event* event) | 132 void MediaDocument::defaultEventHandler(Event* event) |
| 145 { | 133 { |
| 146 Node* targetNode = event->target()->toNode(); | 134 Node* targetNode = event->target()->toNode(); |
| 147 if (!targetNode) | 135 if (!targetNode) |
| 148 return; | 136 return; |
| 149 | 137 |
| 150 if (event->type() == EventTypeNames::keydown && event->isKeyboardEvent()) { | 138 if (event->type() == EventTypeNames::keydown && event->isKeyboardEvent()) { |
| 151 HTMLVideoElement* video = descendentVideoElement(targetNode); | 139 HTMLVideoElement* video = Traversal<HTMLVideoElement>::firstWithin(*targ
etNode); |
| 152 if (!video) | 140 if (!video) |
| 153 return; | 141 return; |
| 154 | 142 |
| 155 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); | 143 KeyboardEvent* keyboardEvent = toKeyboardEvent(event); |
| 156 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode
() == VKEY_MEDIA_PLAY_PAUSE) { | 144 if (keyboardEvent->keyIdentifier() == "U+0020" || keyboardEvent->keyCode
() == VKEY_MEDIA_PLAY_PAUSE) { |
| 157 // space or media key (play/pause) | 145 // space or media key (play/pause) |
| 158 if (video->paused()) { | 146 if (video->paused()) { |
| 159 if (video->canPlay()) | 147 if (video->canPlay()) |
| 160 video->play(); | 148 video->play(); |
| 161 } else | 149 } else |
| 162 video->pause(); | 150 video->pause(); |
| 163 event->setDefaultHandled(); | 151 event->setDefaultHandled(); |
| 164 } | 152 } |
| 165 } | 153 } |
| 166 } | 154 } |
| 167 | 155 |
| 168 } | 156 } |
| OLD | NEW |