summaryrefslogtreecommitdiffstats
path: root/WebCore/loader/MediaDocument.cpp
diff options
context:
space:
mode:
authorFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
committerFeng Qian <fqian@google.com>2009-06-17 12:12:20 -0700
commit5f1ab04193ad0130ca8204aadaceae083aca9881 (patch)
tree5a92cd389e2cfe7fb67197ce14b38469462379f8 /WebCore/loader/MediaDocument.cpp
parent194315e5a908cc8ed67d597010544803eef1ac59 (diff)
downloadexternal_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.zip
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.gz
external_webkit-5f1ab04193ad0130ca8204aadaceae083aca9881.tar.bz2
Get WebKit r44544.
Diffstat (limited to 'WebCore/loader/MediaDocument.cpp')
-rw-r--r--WebCore/loader/MediaDocument.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/WebCore/loader/MediaDocument.cpp b/WebCore/loader/MediaDocument.cpp
index b89ac10..0b1fd59 100644
--- a/WebCore/loader/MediaDocument.cpp
+++ b/WebCore/loader/MediaDocument.cpp
@@ -38,7 +38,9 @@
#include "HTMLEmbedElement.h"
#include "HTMLNames.h"
#include "HTMLVideoElement.h"
+#include "KeyboardEvent.h"
#include "MainResourceLoader.h"
+#include "NodeList.h"
#include "Page.h"
#include "SegmentedString.h"
#include "Settings.h"
@@ -133,10 +135,16 @@ bool MediaTokenizer::isWaitingForScripts() const
MediaDocument::MediaDocument(Frame* frame)
: HTMLDocument(frame)
+ , m_replaceMediaElementTimer(this, &MediaDocument::replaceMediaElementTimerFired)
{
setParseMode(Compat);
}
+MediaDocument::~MediaDocument()
+{
+ ASSERT(!m_replaceMediaElementTimer.isActive());
+}
+
Tokenizer* MediaDocument::createTokenizer()
{
return new MediaTokenizer(this);
@@ -161,6 +169,69 @@ void MediaDocument::defaultEventHandler(Event* event)
}
}
}
+
+ if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent()) {
+ HTMLVideoElement* video = 0;
+ if (targetNode) {
+ if (targetNode->hasTagName(videoTag))
+ video = static_cast<HTMLVideoElement*>(targetNode);
+ else {
+ RefPtr<NodeList> nodeList = targetNode->getElementsByTagName("video");
+ if (nodeList.get()->length() > 0)
+ video = static_cast<HTMLVideoElement*>(nodeList.get()->item(0));
+ }
+ }
+ if (video) {
+ KeyboardEvent* keyboardEvent = static_cast<KeyboardEvent*>(event);
+ if (keyboardEvent->keyIdentifier() == "U+0020") { // space
+ if (video->paused()) {
+ if (video->canPlay())
+ video->play();
+ } else
+ video->pause();
+ event->setDefaultHandled();
+ }
+ }
+ }
+}
+
+void MediaDocument::mediaElementSawUnsupportedTracks()
+{
+ // The HTMLMediaElement was told it has something that the underlying
+ // MediaPlayer cannot handle so we should switch from <video> to <embed>
+ // and let the plugin handle this. Don't do it immediately as this
+ // function may be called directly from a media engine callback, and
+ // replaceChild will destroy the element, media player, and media engine.
+ m_replaceMediaElementTimer.startOneShot(0);
+}
+
+void MediaDocument::replaceMediaElementTimerFired(Timer<MediaDocument>*)
+{
+ HTMLElement* htmlBody = body();
+ if (!htmlBody)
+ return;
+
+ // Set body margin width and height to 0 as that is what a PluginDocument uses.
+ htmlBody->setAttribute(marginwidthAttr, "0");
+ htmlBody->setAttribute(marginheightAttr, "0");
+
+ RefPtr<NodeList> nodeList = htmlBody->getElementsByTagName("video");
+
+ if (nodeList.get()->length() > 0) {
+ HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(nodeList.get()->item(0));
+
+ RefPtr<Element> element = Document::createElement(embedTag, false);
+ HTMLEmbedElement* embedElement = static_cast<HTMLEmbedElement*>(element.get());
+
+ embedElement->setAttribute(widthAttr, "100%");
+ embedElement->setAttribute(heightAttr, "100%");
+ embedElement->setAttribute(nameAttr, "plugin");
+ embedElement->setSrc(url().string());
+ embedElement->setType(frame()->loader()->responseMIMEType());
+
+ ExceptionCode ec;
+ videoElement->parent()->replaceChild(embedElement, videoElement, ec);
+ }
}
}