This source file includes following definitions.
- create
- rendererIsNeeded
- createRenderer
- attach
- collectStyleForPresentationAttribute
- isPresentationAttribute
- parseAttribute
- supportsFullscreen
- videoWidth
- videoHeight
- isURLAttribute
- imageSourceURL
- setDisplayMode
- updateDisplayState
- paintCurrentFrameInContext
- copyVideoTextureToPlatformTexture
- hasAvailableVideoFrame
- webkitEnterFullscreen
- webkitExitFullscreen
- webkitSupportsFullscreen
- webkitDisplayingFullscreen
- didMoveToNewDocument
- webkitDecodedFrameCount
- webkitDroppedFrameCount
- posterImageURL
- mediaPlayerPosterURL
- getSourceImageForCanvas
- wouldTaintOrigin
- sourceSize
#include "config.h"
#include "core/html/HTMLVideoElement.h"
#include "CSSPropertyNames.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/Attribute.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/html/HTMLImageLoader.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/frame/Settings.h"
#include "core/rendering/RenderImage.h"
#include "core/rendering/RenderVideo.h"
#include "platform/UserGestureIndicator.h"
namespace WebCore {
using namespace HTMLNames;
inline HTMLVideoElement::HTMLVideoElement(Document& document)
: HTMLMediaElement(videoTag, document)
{
ScriptWrappable::init(this);
if (document.settings())
m_defaultPosterURL = AtomicString(document.settings()->defaultVideoPosterURL());
}
PassRefPtr<HTMLVideoElement> HTMLVideoElement::create(Document& document)
{
RefPtr<HTMLVideoElement> videoElement(adoptRef(new HTMLVideoElement(document)));
videoElement->suspendIfNeeded();
return videoElement.release();
}
bool HTMLVideoElement::rendererIsNeeded(const RenderStyle& style)
{
return HTMLElement::rendererIsNeeded(style);
}
RenderObject* HTMLVideoElement::createRenderer(RenderStyle*)
{
return new RenderVideo(this);
}
void HTMLVideoElement::attach(const AttachContext& context)
{
HTMLMediaElement::attach(context);
updateDisplayState();
if (shouldDisplayPosterImage()) {
if (!m_imageLoader)
m_imageLoader = adoptPtr(new HTMLImageLoader(this));
m_imageLoader->updateFromElement();
if (renderer())
toRenderImage(renderer())->imageResource()->setImageResource(m_imageLoader->image());
}
}
void HTMLVideoElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
{
if (name == widthAttr)
addHTMLLengthToStyle(style, CSSPropertyWidth, value);
else if (name == heightAttr)
addHTMLLengthToStyle(style, CSSPropertyHeight, value);
else
HTMLMediaElement::collectStyleForPresentationAttribute(name, value, style);
}
bool HTMLVideoElement::isPresentationAttribute(const QualifiedName& name) const
{
if (name == widthAttr || name == heightAttr)
return true;
return HTMLMediaElement::isPresentationAttribute(name);
}
void HTMLVideoElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == posterAttr) {
HTMLMediaElement::setDisplayMode(Unknown);
updateDisplayState();
if (shouldDisplayPosterImage()) {
if (!m_imageLoader)
m_imageLoader = adoptPtr(new HTMLImageLoader(this));
m_imageLoader->updateFromElementIgnoringPreviousError();
} else {
if (renderer())
toRenderImage(renderer())->imageResource()->setImageResource(0);
}
if (player())
player()->setPoster(posterImageURL());
} else
HTMLMediaElement::parseAttribute(name, value);
}
bool HTMLVideoElement::supportsFullscreen() const
{
if (!document().page())
return false;
if (!player())
return false;
return true;
}
unsigned HTMLVideoElement::videoWidth() const
{
if (!player())
return 0;
return player()->naturalSize().width();
}
unsigned HTMLVideoElement::videoHeight() const
{
if (!player())
return 0;
return player()->naturalSize().height();
}
bool HTMLVideoElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == posterAttr || HTMLMediaElement::isURLAttribute(attribute);
}
const AtomicString HTMLVideoElement::imageSourceURL() const
{
const AtomicString& url = getAttribute(posterAttr);
if (!stripLeadingAndTrailingHTMLSpaces(url).isEmpty())
return url;
return m_defaultPosterURL;
}
void HTMLVideoElement::setDisplayMode(DisplayMode mode)
{
DisplayMode oldMode = displayMode();
KURL poster = posterImageURL();
if (!poster.isEmpty()) {
if (mode == Video && !hasAvailableVideoFrame())
mode = PosterWaitingForVideo;
}
HTMLMediaElement::setDisplayMode(mode);
if (renderer() && displayMode() != oldMode)
renderer()->updateFromElement();
}
void HTMLVideoElement::updateDisplayState()
{
if (posterImageURL().isEmpty())
setDisplayMode(Video);
else if (displayMode() < Poster)
setDisplayMode(Poster);
}
void HTMLVideoElement::paintCurrentFrameInContext(GraphicsContext* context, const IntRect& destRect) const
{
MediaPlayer* player = HTMLMediaElement::player();
if (!player)
return;
player->paint(context, destRect);
}
bool HTMLVideoElement::copyVideoTextureToPlatformTexture(blink::WebGraphicsContext3D* context, Platform3DObject texture, GLint level, GLenum type, GLenum internalFormat, bool premultiplyAlpha, bool flipY)
{
if (!player())
return false;
return player()->copyVideoTextureToPlatformTexture(context, texture, level, type, internalFormat, premultiplyAlpha, flipY);
}
bool HTMLVideoElement::hasAvailableVideoFrame() const
{
if (!player())
return false;
return player()->hasVideo() && player()->readyState() >= MediaPlayer::HaveCurrentData;
}
void HTMLVideoElement::webkitEnterFullscreen(ExceptionState& exceptionState)
{
if (isFullscreen())
return;
if (!supportsFullscreen()) {
exceptionState.throwDOMException(InvalidStateError, "This element does not support fullscreen mode.");
return;
}
enterFullscreen();
}
void HTMLVideoElement::webkitExitFullscreen()
{
if (isFullscreen())
exitFullscreen();
}
bool HTMLVideoElement::webkitSupportsFullscreen()
{
return supportsFullscreen();
}
bool HTMLVideoElement::webkitDisplayingFullscreen()
{
return isFullscreen();
}
void HTMLVideoElement::didMoveToNewDocument(Document& oldDocument)
{
if (m_imageLoader)
m_imageLoader->elementDidMoveToNewDocument();
HTMLMediaElement::didMoveToNewDocument(oldDocument);
}
unsigned HTMLVideoElement::webkitDecodedFrameCount() const
{
if (!player())
return 0;
return player()->decodedFrameCount();
}
unsigned HTMLVideoElement::webkitDroppedFrameCount() const
{
if (!player())
return 0;
return player()->droppedFrameCount();
}
KURL HTMLVideoElement::posterImageURL() const
{
String url = stripLeadingAndTrailingHTMLSpaces(imageSourceURL());
if (url.isEmpty())
return KURL();
return document().completeURL(url);
}
KURL HTMLVideoElement::mediaPlayerPosterURL()
{
return posterImageURL();
}
PassRefPtr<Image> HTMLVideoElement::getSourceImageForCanvas(SourceImageMode mode, SourceImageStatus* status) const
{
if (!hasAvailableVideoFrame()) {
*status = InvalidSourceImageStatus;
return nullptr;
}
IntSize intrinsicSize(videoWidth(), videoHeight());
OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(intrinsicSize);
if (!imageBuffer) {
*status = InvalidSourceImageStatus;
return nullptr;
}
paintCurrentFrameInContext(imageBuffer->context(), IntRect(IntPoint(0, 0), intrinsicSize));
*status = NormalSourceImageStatus;
return imageBuffer->copyImage(mode == CopySourceImageIfVolatile ? CopyBackingStore : DontCopyBackingStore, Unscaled);
}
bool HTMLVideoElement::wouldTaintOrigin(SecurityOrigin* destinationSecurityOrigin) const
{
return !hasSingleSecurityOrigin() || (!(player() && player()->didPassCORSAccessCheck()) && destinationSecurityOrigin->taintsCanvas(currentSrc()));
}
FloatSize HTMLVideoElement::sourceSize() const
{
return FloatSize(videoWidth(), videoHeight());
}
}