18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
2d0825bca7fe65beaee391d30da42e937db621564Steve Block * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc.  All rights reserved.
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    documentation and/or other materials provided with the distribution.
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h"
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if ENABLE(VIDEO)
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "RenderVideo.h"
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Document.h"
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "FrameView.h"
338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "GraphicsContext.h"
348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLNames.h"
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLVideoElement.h"
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "MediaPlayer.h"
37d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "RenderView.h"
388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
390bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#if USE(ACCELERATED_COMPOSITING)
400bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#include "RenderLayer.h"
410bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#include "RenderLayerBacking.h"
420bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#endif
430bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace std;
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace HTMLNames;
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
505f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic const int cDefaultWidth = 300;
515f1ab04193ad0130ca8204aadaceae083aca9881Feng Qianstatic const int cDefaultHeight = 150;
525f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
53d0825bca7fe65beaee391d30da42e937db621564Steve BlockRenderVideo::RenderVideo(HTMLVideoElement* video)
545f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    : RenderMedia(video)
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
565f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    if (video->player())
575f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        setIntrinsicSize(video->player()->naturalSize());
585f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    else {
59d0825bca7fe65beaee391d30da42e937db621564Steve Block        // When the natural size of the video is unavailable, we use the provided
60d0825bca7fe65beaee391d30da42e937db621564Steve Block        // width and height attributes of the video element as the intrinsic size until
61d0825bca7fe65beaee391d30da42e937db621564Steve Block        // better values become available. If these attributes are not set, we fall back
62d0825bca7fe65beaee391d30da42e937db621564Steve Block        // to a default video size (300x150).
63d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (video->hasAttribute(widthAttr) && video->hasAttribute(heightAttr))
64d0825bca7fe65beaee391d30da42e937db621564Steve Block            setIntrinsicSize(IntSize(video->width(), video->height()));
65d0825bca7fe65beaee391d30da42e937db621564Steve Block        else if (video->ownerDocument() && video->ownerDocument()->isMediaDocument()) {
66d0825bca7fe65beaee391d30da42e937db621564Steve Block            // Video in standalone media documents should not use the default 300x150
67d0825bca7fe65beaee391d30da42e937db621564Steve Block            // size since they also have audio thrown at them. By setting the intrinsic
68d0825bca7fe65beaee391d30da42e937db621564Steve Block            // size to 300x1 the video will resize itself in these cases, and audio will
69d0825bca7fe65beaee391d30da42e937db621564Steve Block            // have the correct height (it needs to be > 0 for controls to render properly).
705f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            setIntrinsicSize(IntSize(cDefaultWidth, 1));
71d0825bca7fe65beaee391d30da42e937db621564Steve Block        }
725f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        else
735f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian            setIntrinsicSize(IntSize(cDefaultWidth, cDefaultHeight));
745f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    }
758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectRenderVideo::~RenderVideo()
788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (MediaPlayer* p = player()) {
808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        p->setVisible(false);
818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        p->setFrameView(0);
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
84d0825bca7fe65beaee391d30da42e937db621564Steve Block
85d0825bca7fe65beaee391d30da42e937db621564Steve Blockvoid RenderVideo::intrinsicSizeChanged()
86d0825bca7fe65beaee391d30da42e937db621564Steve Block{
87d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (videoElement()->shouldDisplayPosterImage())
885e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block        RenderMedia::intrinsicSizeChanged();
89d0825bca7fe65beaee391d30da42e937db621564Steve Block    videoSizeChanged();
90d0825bca7fe65beaee391d30da42e937db621564Steve Block}
91d0825bca7fe65beaee391d30da42e937db621564Steve Block
92d0825bca7fe65beaee391d30da42e937db621564Steve Block
938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderVideo::videoSizeChanged()
948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!player())
968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    IntSize size = player()->naturalSize();
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!size.isEmpty() && size != intrinsicSize()) {
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        setIntrinsicSize(size);
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        setPrefWidthsDirty(true);
1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        setNeedsLayout(true);
1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
105d0825bca7fe65beaee391d30da42e937db621564Steve Blockvoid RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1075e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block    RenderMedia::imageChanged(newImage, rect);
108d0825bca7fe65beaee391d30da42e937db621564Steve Block
109d0825bca7fe65beaee391d30da42e937db621564Steve Block    // Cache the image intrinsic size so we can continue to use it to draw the image correctly
110d0825bca7fe65beaee391d30da42e937db621564Steve Block    // even after we know the video intrisic size but aren't able to draw video frames yet
111d0825bca7fe65beaee391d30da42e937db621564Steve Block    // (we don't want to scale the poster to the video size).
112d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (videoElement()->shouldDisplayPosterImage())
113d0825bca7fe65beaee391d30da42e937db621564Steve Block        m_cachedImageSize = intrinsicSize();
114d0825bca7fe65beaee391d30da42e937db621564Steve Block}
115d0825bca7fe65beaee391d30da42e937db621564Steve Block
116d0825bca7fe65beaee391d30da42e937db621564Steve BlockIntRect RenderVideo::videoBox() const
117d0825bca7fe65beaee391d30da42e937db621564Steve Block{
118d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (m_cachedImageSize.isEmpty() && videoElement()->shouldDisplayPosterImage())
119d0825bca7fe65beaee391d30da42e937db621564Steve Block        return IntRect();
120d0825bca7fe65beaee391d30da42e937db621564Steve Block
121d0825bca7fe65beaee391d30da42e937db621564Steve Block    IntSize elementSize;
122d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (videoElement()->shouldDisplayPosterImage())
123d0825bca7fe65beaee391d30da42e937db621564Steve Block        elementSize = m_cachedImageSize;
124d0825bca7fe65beaee391d30da42e937db621564Steve Block    else
125d0825bca7fe65beaee391d30da42e937db621564Steve Block        elementSize = intrinsicSize();
126d0825bca7fe65beaee391d30da42e937db621564Steve Block
127635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    IntRect contentRect = contentBoxRect();
128d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (elementSize.isEmpty() || contentRect.isEmpty())
1298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return IntRect();
1308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
131d0825bca7fe65beaee391d30da42e937db621564Steve Block    IntRect renderBox = contentRect;
132d0825bca7fe65beaee391d30da42e937db621564Steve Block    int ratio = renderBox.width() * elementSize.height() - renderBox.height() * elementSize.width();
1338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (ratio > 0) {
134d0825bca7fe65beaee391d30da42e937db621564Steve Block        int newWidth = renderBox.height() * elementSize.width() / elementSize.height();
1358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        // Just fill the whole area if the difference is one pixel or less (in both sides)
136d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (renderBox.width() - newWidth > 2)
137d0825bca7fe65beaee391d30da42e937db621564Steve Block            renderBox.setWidth(newWidth);
138d0825bca7fe65beaee391d30da42e937db621564Steve Block        renderBox.move((contentRect.width() - renderBox.width()) / 2, 0);
1398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    } else if (ratio < 0) {
140d0825bca7fe65beaee391d30da42e937db621564Steve Block        int newHeight = renderBox.width() * elementSize.height() / elementSize.width();
141d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (renderBox.height() - newHeight > 2)
142d0825bca7fe65beaee391d30da42e937db621564Steve Block            renderBox.setHeight(newHeight);
143d0825bca7fe65beaee391d30da42e937db621564Steve Block        renderBox.move(0, (contentRect.height() - renderBox.height()) / 2);
1448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
145d0825bca7fe65beaee391d30da42e937db621564Steve Block
146d0825bca7fe65beaee391d30da42e937db621564Steve Block    return renderBox;
1478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderVideo::paintReplaced(PaintInfo& paintInfo, int tx, int ty)
1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    MediaPlayer* mediaPlayer = player();
152d0825bca7fe65beaee391d30da42e937db621564Steve Block    bool displayingPoster = videoElement()->shouldDisplayPosterImage();
153d0825bca7fe65beaee391d30da42e937db621564Steve Block
154d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (displayingPoster && document()->printing() && !view()->printImages())
1558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
156d0825bca7fe65beaee391d30da42e937db621564Steve Block
157d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (!displayingPoster) {
158d0825bca7fe65beaee391d30da42e937db621564Steve Block        if (!mediaPlayer)
159d0825bca7fe65beaee391d30da42e937db621564Steve Block            return;
160d0825bca7fe65beaee391d30da42e937db621564Steve Block        updatePlayer();
161d0825bca7fe65beaee391d30da42e937db621564Steve Block    }
162d0825bca7fe65beaee391d30da42e937db621564Steve Block
1638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    IntRect rect = videoBox();
1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (rect.isEmpty())
1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    rect.move(tx, ty);
167d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (displayingPoster)
168d0825bca7fe65beaee391d30da42e937db621564Steve Block        paintIntoRect(paintInfo.context, rect);
169d0825bca7fe65beaee391d30da42e937db621564Steve Block    else
170d0825bca7fe65beaee391d30da42e937db621564Steve Block        mediaPlayer->paint(paintInfo.context, rect);
1718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderVideo::layout()
1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    RenderMedia::layout();
1768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    updatePlayer();
1778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
179d0825bca7fe65beaee391d30da42e937db621564Steve BlockHTMLVideoElement* RenderVideo::videoElement() const
180d0825bca7fe65beaee391d30da42e937db621564Steve Block{
181d0825bca7fe65beaee391d30da42e937db621564Steve Block    ASSERT(node()->hasTagName(videoTag));
182d0825bca7fe65beaee391d30da42e937db621564Steve Block    return static_cast<HTMLVideoElement*>(node());
183d0825bca7fe65beaee391d30da42e937db621564Steve Block}
184d0825bca7fe65beaee391d30da42e937db621564Steve Block
1858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderVideo::updateFromElement()
1868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    RenderMedia::updateFromElement();
1888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    updatePlayer();
1898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid RenderVideo::updatePlayer()
1928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    MediaPlayer* mediaPlayer = player();
1948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!mediaPlayer)
1958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
196d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (!videoElement()->inActiveDocument()) {
1978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mediaPlayer->setVisible(false);
1988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
1998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2000bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2010bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#if USE(ACCELERATED_COMPOSITING)
2020bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    layer()->rendererContentChanged();
2030bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#endif
204635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
2058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    IntRect videoBounds = videoBox();
2068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    mediaPlayer->setFrameView(document()->view());
2078f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    mediaPlayer->setSize(IntSize(videoBounds.width(), videoBounds.height()));
2088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    mediaPlayer->setVisible(true);
2098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectint RenderVideo::calcReplacedWidth(bool includeMaxWidth) const
2128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int width;
2148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (isWidthSpecified())
2158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        width = calcReplacedWidthUsing(style()->width());
2168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    else
217635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        width = calcAspectRatioWidth() * style()->effectiveZoom();
2188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int minW = calcReplacedWidthUsing(style()->minWidth());
2208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int maxW = !includeMaxWidth || style()->maxWidth().isUndefined() ? width : calcReplacedWidthUsing(style()->maxWidth());
2218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return max(minW, min(width, maxW));
2238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectint RenderVideo::calcReplacedHeight() const
2268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int height;
2288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (isHeightSpecified())
2298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        height = calcReplacedHeightUsing(style()->height());
2308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    else
231635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        height = calcAspectRatioHeight() * style()->effectiveZoom();
2328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int minH = calcReplacedHeightUsing(style()->minHeight());
2348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int maxH = style()->maxHeight().isUndefined() ? height : calcReplacedHeightUsing(style()->maxHeight());
2358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return max(minH, min(height, maxH));
2378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectint RenderVideo::calcAspectRatioWidth() const
2408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int intrinsicWidth = intrinsicSize().width();
2428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int intrinsicHeight = intrinsicSize().height();
2438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!intrinsicHeight)
2448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
2458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return RenderBox::calcReplacedHeight() * intrinsicWidth / intrinsicHeight;
2468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectint RenderVideo::calcAspectRatioHeight() const
2498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int intrinsicWidth = intrinsicSize().width();
2518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int intrinsicHeight = intrinsicSize().height();
2528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!intrinsicWidth)
2538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
2548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return RenderBox::calcReplacedWidth() * intrinsicHeight / intrinsicWidth;
2558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
257d0825bca7fe65beaee391d30da42e937db621564Steve Blockint RenderVideo::minimumReplacedHeight() const
2588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
259d0825bca7fe65beaee391d30da42e937db621564Steve Block    return 0;
2608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2620bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#if USE(ACCELERATED_COMPOSITING)
2630bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochbool RenderVideo::supportsAcceleratedRendering() const
2640bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch{
2650bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    MediaPlayer* p = player();
2660bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    if (p)
2670bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        return p->supportsAcceleratedRendering();
2680bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2690bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    return false;
2700bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch}
2710bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2720bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochvoid RenderVideo::acceleratedRenderingStateChanged()
2730bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch{
2740bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    MediaPlayer* p = player();
2750bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    if (p)
2760bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        p->acceleratedRenderingStateChanged();
2770bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch}
2780bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2790bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben MurdochGraphicsLayer* RenderVideo::videoGraphicsLayer() const
2800bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch{
2810bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    if (hasLayer() && layer()->isComposited())
2820bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        return layer()->backing()->graphicsLayer();
2830bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2840bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    return 0;
2850bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch}
2860bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#endif  // USE(ACCELERATED_COMPOSITING)
2870bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
2888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore
2898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
291