From cad810f21b803229eb11403f9209855525a25d57 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Fri, 6 May 2011 11:45:16 +0100 Subject: Merge WebKit at r75315: Initial merge by git. Change-Id: I570314b346ce101c935ed22a626b48c2af266b84 --- Source/WebCore/rendering/RenderVideo.cpp | 284 +++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 Source/WebCore/rendering/RenderVideo.cpp (limited to 'Source/WebCore/rendering/RenderVideo.cpp') diff --git a/Source/WebCore/rendering/RenderVideo.cpp b/Source/WebCore/rendering/RenderVideo.cpp new file mode 100644 index 0000000..5b82deb --- /dev/null +++ b/Source/WebCore/rendering/RenderVideo.cpp @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(VIDEO) +#include "RenderVideo.h" + +#include "Document.h" +#include "FrameView.h" +#include "GraphicsContext.h" +#include "HTMLNames.h" +#include "HTMLVideoElement.h" +#include "MediaPlayer.h" +#include "RenderView.h" + +#if USE(ACCELERATED_COMPOSITING) +#include "RenderLayer.h" +#include "RenderLayerBacking.h" +#endif + +using namespace std; + +namespace WebCore { + +using namespace HTMLNames; + +RenderVideo::RenderVideo(HTMLVideoElement* video) + : RenderMedia(video) +{ + setIntrinsicSize(calculateIntrinsicSize()); +} + +RenderVideo::~RenderVideo() +{ + if (MediaPlayer* p = player()) { + p->setVisible(false); + p->setFrameView(0); + } +} + +IntSize RenderVideo::defaultSize() +{ + // These values are specified in the spec. + static const int cDefaultWidth = 300; + static const int cDefaultHeight = 150; + + return IntSize(cDefaultWidth, cDefaultHeight); +} + +void RenderVideo::intrinsicSizeChanged() +{ + if (videoElement()->shouldDisplayPosterImage()) + RenderMedia::intrinsicSizeChanged(); + updateIntrinsicSize(); +} + +void RenderVideo::updateIntrinsicSize() +{ + IntSize size = calculateIntrinsicSize(); + size.scale(style()->effectiveZoom()); + + // Never set the element size to zero when in a media document. + if (size.isEmpty() && node()->ownerDocument() && node()->ownerDocument()->isMediaDocument()) + return; + + if (size == intrinsicSize()) + return; + + setIntrinsicSize(size); + setPreferredLogicalWidthsDirty(true); + setNeedsLayout(true); +} + +IntSize RenderVideo::calculateIntrinsicSize() +{ + HTMLVideoElement* video = videoElement(); + + // Spec text from 4.8.6 + // + // The intrinsic width of a video element's playback area is the intrinsic width + // of the video resource, if that is available; otherwise it is the intrinsic + // width of the poster frame, if that is available; otherwise it is 300 CSS pixels. + // + // The intrinsic height of a video element's playback area is the intrinsic height + // of the video resource, if that is available; otherwise it is the intrinsic + // height of the poster frame, if that is available; otherwise it is 150 CSS pixels. + + if (player() && video->readyState() >= HTMLVideoElement::HAVE_METADATA) + return player()->naturalSize(); + + if (video->shouldDisplayPosterImage() && !m_cachedImageSize.isEmpty() && !imageResource()->errorOccurred()) + return m_cachedImageSize; + + // When the natural size of the video is unavailable, we use the provided + // width and height attributes of the video element as the intrinsic size until + // better values become available. + if (video->hasAttribute(widthAttr) && video->hasAttribute(heightAttr)) + return IntSize(video->width(), video->height()); + + //