| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "core/html/HTMLVideoElement.h" | |
| 28 | |
| 29 #include "bindings/core/v8/ExceptionState.h" | |
| 30 #include "core/CSSPropertyNames.h" | |
| 31 #include "core/HTMLNames.h" | |
| 32 #include "core/dom/Attribute.h" | |
| 33 #include "core/dom/Document.h" | |
| 34 #include "core/dom/ExceptionCode.h" | |
| 35 #include "core/frame/Settings.h" | |
| 36 #include "core/html/HTMLImageLoader.h" | |
| 37 #include "core/html/canvas/CanvasRenderingContext.h" | |
| 38 #include "core/html/parser/HTMLParserIdioms.h" | |
| 39 #include "core/rendering/RenderImage.h" | |
| 40 #include "core/rendering/RenderVideo.h" | |
| 41 #include "platform/UserGestureIndicator.h" | |
| 42 #include "platform/graphics/GraphicsContext.h" | |
| 43 #include "platform/graphics/gpu/Extensions3DUtil.h" | |
| 44 #include "public/platform/WebCanvas.h" | |
| 45 #include "public/platform/WebGraphicsContext3D.h" | |
| 46 | |
| 47 namespace blink { | |
| 48 | |
| 49 inline HTMLVideoElement::HTMLVideoElement(Document& document) | |
| 50 : HTMLMediaElement(HTMLNames::videoTag, document) | |
| 51 { | |
| 52 ScriptWrappable::init(this); | |
| 53 if (document.settings()) | |
| 54 m_defaultPosterURL = AtomicString(document.settings()->defaultVideoPoste
rURL()); | |
| 55 } | |
| 56 | |
| 57 PassRefPtr<HTMLVideoElement> HTMLVideoElement::create(Document& document) | |
| 58 { | |
| 59 RefPtr<HTMLVideoElement> video = adoptRef(new HTMLVideoElement(document)); | |
| 60 video->suspendIfNeeded(); | |
| 61 return video.release(); | |
| 62 } | |
| 63 | |
| 64 bool HTMLVideoElement::rendererIsNeeded(const RenderStyle& style) | |
| 65 { | |
| 66 return HTMLElement::rendererIsNeeded(style); | |
| 67 } | |
| 68 | |
| 69 RenderObject* HTMLVideoElement::createRenderer(RenderStyle*) | |
| 70 { | |
| 71 return new RenderVideo(this); | |
| 72 } | |
| 73 | |
| 74 void HTMLVideoElement::attach(const AttachContext& context) | |
| 75 { | |
| 76 HTMLMediaElement::attach(context); | |
| 77 | |
| 78 updateDisplayState(); | |
| 79 if (shouldDisplayPosterImage()) { | |
| 80 if (!m_imageLoader) | |
| 81 m_imageLoader = HTMLImageLoader::create(this); | |
| 82 m_imageLoader->updateFromElement(); | |
| 83 if (renderer()) | |
| 84 toRenderImage(renderer())->imageResource()->setImageResource(m_image
Loader->image()); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void HTMLVideoElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | |
| 89 { | |
| 90 if (name == HTMLNames::posterAttr) { | |
| 91 // Force a poster recalc by setting m_displayMode to Unknown directly be
fore calling updateDisplayState. | |
| 92 HTMLMediaElement::setDisplayMode(Unknown); | |
| 93 updateDisplayState(); | |
| 94 if (shouldDisplayPosterImage()) { | |
| 95 if (!m_imageLoader) | |
| 96 m_imageLoader = HTMLImageLoader::create(this); | |
| 97 m_imageLoader->updateFromElement(ImageLoader::UpdateIgnorePreviousEr
ror); | |
| 98 } else { | |
| 99 if (renderer()) | |
| 100 toRenderImage(renderer())->imageResource()->setImageResource(0); | |
| 101 } | |
| 102 // Notify the player when the poster image URL changes. | |
| 103 if (webMediaPlayer()) | |
| 104 webMediaPlayer()->setPoster(posterImageURL()); | |
| 105 } else | |
| 106 HTMLMediaElement::parseAttribute(name, value); | |
| 107 } | |
| 108 | |
| 109 unsigned HTMLVideoElement::videoWidth() const | |
| 110 { | |
| 111 if (!webMediaPlayer()) | |
| 112 return 0; | |
| 113 return webMediaPlayer()->naturalSize().width; | |
| 114 } | |
| 115 | |
| 116 unsigned HTMLVideoElement::videoHeight() const | |
| 117 { | |
| 118 if (!webMediaPlayer()) | |
| 119 return 0; | |
| 120 return webMediaPlayer()->naturalSize().height; | |
| 121 } | |
| 122 | |
| 123 bool HTMLVideoElement::isURLAttribute(const Attribute& attribute) const | |
| 124 { | |
| 125 return attribute.name() == HTMLNames::posterAttr || HTMLMediaElement::isURLA
ttribute(attribute); | |
| 126 } | |
| 127 | |
| 128 const AtomicString HTMLVideoElement::imageSourceURL() const | |
| 129 { | |
| 130 const AtomicString& url = getAttribute(HTMLNames::posterAttr); | |
| 131 if (!stripLeadingAndTrailingHTMLSpaces(url).isEmpty()) | |
| 132 return url; | |
| 133 return m_defaultPosterURL; | |
| 134 } | |
| 135 | |
| 136 void HTMLVideoElement::setDisplayMode(DisplayMode mode) | |
| 137 { | |
| 138 DisplayMode oldMode = displayMode(); | |
| 139 KURL poster = posterImageURL(); | |
| 140 | |
| 141 if (!poster.isEmpty()) { | |
| 142 // We have a poster path, but only show it until the user triggers displ
ay by playing or seeking and the | |
| 143 // media engine has something to display. | |
| 144 // Don't show the poster if there is a seek operation or | |
| 145 // the video has restarted because of loop attribute | |
| 146 if (mode == Video && oldMode == Poster && !hasAvailableVideoFrame()) | |
| 147 mode = PosterWaitingForVideo; | |
| 148 } | |
| 149 | |
| 150 HTMLMediaElement::setDisplayMode(mode); | |
| 151 | |
| 152 if (renderer() && displayMode() != oldMode) | |
| 153 renderer()->updateFromElement(); | |
| 154 } | |
| 155 | |
| 156 void HTMLVideoElement::updateDisplayState() | |
| 157 { | |
| 158 if (posterImageURL().isEmpty()) | |
| 159 setDisplayMode(Video); | |
| 160 else if (displayMode() < Poster) | |
| 161 setDisplayMode(Poster); | |
| 162 } | |
| 163 | |
| 164 void HTMLVideoElement::paintCurrentFrameInContext(GraphicsContext* context, cons
t IntRect& destRect) const | |
| 165 { | |
| 166 if (!webMediaPlayer()) | |
| 167 return; | |
| 168 | |
| 169 WebCanvas* canvas = context->canvas(); | |
| 170 SkXfermode::Mode mode = WebCoreCompositeToSkiaComposite(context->compositeOp
eration(), context->blendModeOperation()); | |
| 171 webMediaPlayer()->paint(canvas, destRect, context->getNormalizedAlpha(), mod
e); | |
| 172 } | |
| 173 | |
| 174 bool HTMLVideoElement::copyVideoTextureToPlatformTexture(WebGraphicsContext3D* c
ontext, Platform3DObject texture, GLint level, GLenum internalFormat, GLenum typ
e, bool premultiplyAlpha, bool flipY) | |
| 175 { | |
| 176 if (!webMediaPlayer()) | |
| 177 return false; | |
| 178 | |
| 179 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, type, level
)) | |
| 180 return false; | |
| 181 | |
| 182 return webMediaPlayer()->copyVideoTextureToPlatformTexture(context, texture,
level, internalFormat, type, premultiplyAlpha, flipY); | |
| 183 } | |
| 184 | |
| 185 bool HTMLVideoElement::hasAvailableVideoFrame() const | |
| 186 { | |
| 187 if (!webMediaPlayer()) | |
| 188 return false; | |
| 189 | |
| 190 return webMediaPlayer()->hasVideo() && webMediaPlayer()->readyState() >= bli
nk::WebMediaPlayer::ReadyStateHaveCurrentData; | |
| 191 } | |
| 192 | |
| 193 void HTMLVideoElement::didMoveToNewDocument(Document& oldDocument) | |
| 194 { | |
| 195 if (m_imageLoader) | |
| 196 m_imageLoader->elementDidMoveToNewDocument(); | |
| 197 HTMLMediaElement::didMoveToNewDocument(oldDocument); | |
| 198 } | |
| 199 | |
| 200 KURL HTMLVideoElement::posterImageURL() const | |
| 201 { | |
| 202 String url = stripLeadingAndTrailingHTMLSpaces(imageSourceURL()); | |
| 203 if (url.isEmpty()) | |
| 204 return KURL(); | |
| 205 return document().completeURL(url); | |
| 206 } | |
| 207 | |
| 208 KURL HTMLVideoElement::mediaPlayerPosterURL() | |
| 209 { | |
| 210 return posterImageURL(); | |
| 211 } | |
| 212 | |
| 213 PassRefPtr<Image> HTMLVideoElement::getSourceImageForCanvas(SourceImageMode mode
, SourceImageStatus* status) const | |
| 214 { | |
| 215 if (!hasAvailableVideoFrame()) { | |
| 216 *status = InvalidSourceImageStatus; | |
| 217 return nullptr; | |
| 218 } | |
| 219 | |
| 220 IntSize intrinsicSize(videoWidth(), videoHeight()); | |
| 221 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(intrinsicSize); | |
| 222 if (!imageBuffer) { | |
| 223 *status = InvalidSourceImageStatus; | |
| 224 return nullptr; | |
| 225 } | |
| 226 | |
| 227 paintCurrentFrameInContext(imageBuffer->context(), IntRect(IntPoint(0, 0), i
ntrinsicSize)); | |
| 228 | |
| 229 *status = NormalSourceImageStatus; | |
| 230 return imageBuffer->copyImage(mode == CopySourceImageIfVolatile ? CopyBackin
gStore : DontCopyBackingStore, Unscaled); | |
| 231 } | |
| 232 | |
| 233 FloatSize HTMLVideoElement::sourceSize() const | |
| 234 { | |
| 235 return FloatSize(videoWidth(), videoHeight()); | |
| 236 } | |
| 237 | |
| 238 } | |
| OLD | NEW |