Bug 726904: Make nsVideoFrame::GetVideoIntrinsicSize return the video size before the poster size. r=cpearce

This commit is contained in:
Christopher De Cairos 2012-05-11 20:32:15 +12:00
parent 6ad81bbb5c
commit a51913e89c
26 changed files with 122 additions and 46 deletions

View File

@ -83,9 +83,9 @@ public:
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
// Returns the current video frame width and height.
// If there is no video frame, returns the given default size.
nsIntSize GetVideoSize(nsIntSize defaultSize);
// Set size with the current video frame's height and width.
// If there is no video frame, returns NS_ERROR_FAILURE.
nsresult GetVideoSize(nsIntSize* size);
virtual nsresult SetAcceptHeader(nsIHttpChannel* aChannel);

View File

@ -112,9 +112,15 @@ nsHTMLVideoElement::~nsHTMLVideoElement()
{
}
nsIntSize nsHTMLVideoElement::GetVideoSize(nsIntSize aDefaultSize)
nsresult nsHTMLVideoElement::GetVideoSize(nsIntSize* size)
{
return mMediaSize.width == -1 && mMediaSize.height == -1 ? aDefaultSize : mMediaSize;
if (mMediaSize.width == -1 && mMediaSize.height == -1) {
return NS_ERROR_FAILURE;
}
size->height = mMediaSize.height;
size->width = mMediaSize.width;
return NS_OK;
}
bool

View File

@ -283,6 +283,7 @@ _TEST_FILES += \
test_audio_event_adopt.html \
test_framebuffer.html \
test_referer.html \
test_bug726904.html \
test_bug686137.html \
$(NULL)
else

View File

@ -8,7 +8,7 @@ var gSmallTests = [
{ name:"small-shot.ogg", type:"audio/ogg", duration:0.276 },
{ name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
{ name:"320x240.ogv", type:"video/ogg", width:320, height:240, duration:0.233 },
{ name:"seek.webm", type:"video/webm", duration:3.966 },
{ name:"seek.webm", type:"video/webm", width:320, height:240, duration:3.966 },
{ name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 },
{ name:"bogus.duh", type:"bogus/duh" }
];

View File

@ -0,0 +1,53 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=726904
-->
<head>
<title>Media test: default video size</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="manifest.js"></script>
</head>
<body onload="bodyLoaded();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=726904">Mozilla Bug 726904</a>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var v1 = document.createElement("video"),
v2 = document.createElement("video"),
poster = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAAAAACl1GkQAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAALJJREFUeNrtwQENAAAAwqD3T20ON6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHg0cq4AATRk8BYAAAAASUVORK5CYII",
resource = getPlayableVideo(gSmallTests);
function bodyLoaded(){
is(v1.videoWidth, resource.width, "Intrinsic width should match video width");
is(v1.videoHeight, resource.height, "Intrinsic height should match video height");
is(v2.clientWidth, 400, "clientWidth should be 400");
is(v2.clientHeight, 400, "clientHeight should be 400");
SimpleTest.finish();
}
if (resource) {
v1.poster = v2.poster = poster;
v1.src = v2.src = "http://mochi.test:8888/tests/content/media/test/" + resource.name;
v1.preload = "auto";
v2.preload = "none";
v1.muted = v2.muted = true;
document.body.appendChild(v1);
document.body.appendChild(v2);
} else {
todo(false, "No types supported");
}
</script>
</pre>
</body>
</html>

View File

@ -190,9 +190,10 @@ nsVideoFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
{
nsRect area = GetContentRect() - GetPosition() + aItem->ToReferenceFrame();
nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent());
nsIntSize videoSize = element->GetVideoSize(nsIntSize(0, 0));
if (videoSize.width <= 0 || videoSize.height <= 0 || area.IsEmpty())
nsIntSize videoSize;
if (NS_FAILED(element->GetVideoSize(&videoSize)) || area.IsEmpty()) {
return nsnull;
}
nsRefPtr<ImageContainer> container = element->GetImageContainer();
if (!container)
@ -525,19 +526,7 @@ nsVideoFrame::GetVideoIntrinsicSize(nsRenderingContext *aRenderingContext)
{
// Defaulting size to 300x150 if no size given.
nsIntSize size(300, 150);
if (ShouldDisplayPoster()) {
// Use the poster image frame's size.
nsIFrame *child = mFrames.FirstChild();
if (child && child->GetType() == nsGkAtoms::imageFrame) {
nsImageFrame* imageFrame = static_cast<nsImageFrame*>(child);
nsSize imgsize;
if (NS_SUCCEEDED(imageFrame->GetIntrinsicImageSize(imgsize))) {
return imgsize;
}
}
}
if (!HasVideoElement()) {
if (!aRenderingContext || !mFrames.FirstChild()) {
// We just want our intrinsic ratio, but audio elements need no
@ -553,7 +542,15 @@ nsVideoFrame::GetVideoIntrinsicSize(nsRenderingContext *aRenderingContext)
}
nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent());
size = element->GetVideoSize(size);
if (NS_FAILED(element->GetVideoSize(&size)) && ShouldDisplayPoster()) {
// Use the poster image frame's size.
nsIFrame *child = mPosterImage->GetPrimaryFrame();
nsImageFrame* imageFrame = do_QueryFrame(child);
nsSize imgsize;
if (NS_SUCCEEDED(imageFrame->GetIntrinsicImageSize(imgsize))) {
return imgsize;
}
}
return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width),
nsPresContext::CSSPixelsToAppUnits(size.height));
@ -599,6 +596,7 @@ bool nsVideoFrame::HasVideoData()
if (!HasVideoElement())
return false;
nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent());
nsIntSize size = element->GetVideoSize(nsIntSize(0,0));
nsIntSize size(0, 0);
element->GetVideoSize(&size);
return size != nsIntSize(0,0);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

View File

@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<!-- Test if poster frame displays correctly when poster is different size. -->
<video src="black140x100.ogv" poster="blue250x200.png"></video>
<!-- Ensure video element displays at poster size when video's intrinsic size isn't available. -->
<video preload="none" src="black140x100.ogv" poster="blue250x200.png"></video>
</body>
</html>

View File

@ -11,7 +11,7 @@ function runTest() {
var addPoster = function() {
v.removeEventListener('loadeddata', addPoster, false);
v.poster = "blue250x200.png";
v.poster = "blue140x100.png";
v.addEventListener('loadeddata', endTest, false);
v.load();
};

View File

@ -17,7 +17,7 @@ function runTest() {
var addPoster = function() {
v.removeEventListener('playing', addPoster,false);
v.poster = "blue250x200.png";
v.poster = "blue140x100.png";
v.addEventListener('loadeddata', endTest, false);
v.load();
};

View File

@ -6,7 +6,7 @@
<body style="background:white;">
<video src="black140x100.ogv"
poster="green70x30.png"
preload="auto"
preload="none"
style="border: solid blue 2px;">
</video>
</body>

View File

@ -3,9 +3,9 @@
<body style="background:white;">
<!-- Test that poster frame changes when you change the poster attribute. -->
<video src="black140x100.ogv"
preload="auto"
preload="none"
id="v"
onload="document.getElementById('v').poster = 'red160x120.png'; setTimeout(function(){document.documentElement.className = '';}, 0);"
onload="document.getElementById('v').poster = 'red140x100.png'; setTimeout(function(){document.documentElement.className = '';}, 0);"
poster="blue250x200.png"></video>
</body>
</html>

View File

@ -0,0 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<img src="blue140x100.png" alt="poster">
</body>
</html>

View File

@ -1,6 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<img src="red160x120.png" alt="poster">
<img src="red140x100.png" alt="poster">
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

View File

@ -24,10 +24,10 @@ skip-if(Android) == poster-3.html poster-ref-black140x100.html
skip-if(Android) == poster-4.html poster-ref-black140x100.html
skip-if(Android) == poster-5.html poster-ref-black140x100.html
skip-if(Android) == poster-6.html poster-ref-black140x100.html
skip-if(Android) == poster-7.html poster-ref-red160x120.html
skip-if(Android) == poster-7.html poster-ref-red140x100.html
skip-if(Android) == poster-8.html poster-ref-black140x100.html
skip-if(Android) == poster-10.html poster-ref-blue250x200.html
skip-if(Android) == poster-11.html poster-ref-blue250x200.html
skip-if(Android) == poster-12.html poster-ref-blue250x200.html
skip-if(Android) == poster-10.html poster-ref-blue140x100.html
skip-if(Android) == poster-11.html poster-ref-blue140x100.html
skip-if(Android) == poster-12.html poster-ref-blue140x100.html
skip-if(Android) == poster-13.html poster-ref-blue400x300.html
skip-if(Android) == poster-15.html poster-ref-green70x30.html

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

View File

@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<!-- Test if poster frame displays correctly when poster is different size. -->
<video src="black140x100.webm" poster="blue250x200.png"></video>
<!-- Ensure video element displays at poster size when video's intrinsic size isn't available -->
<video preload="none" src="black140x100.webm" poster="blue250x200.png"></video>
</body>
</html>

View File

@ -11,7 +11,7 @@ function runTest() {
var addPoster = function() {
v.removeEventListener('loadeddata', addPoster, false);
v.poster = "blue250x200.png";
v.poster = "blue140x100.png";
v.addEventListener('loadeddata', endTest, false);
v.load();
};

View File

@ -17,7 +17,7 @@ function runTest() {
var addPoster = function() {
v.removeEventListener('playing', addPoster,false);
v.poster = "blue250x200.png";
v.poster = "blue140x100.png";
v.addEventListener('loadeddata', endTest, false);
v.load();
};

View File

@ -6,7 +6,7 @@
<body style="background:white;">
<video src="black140x100.webm"
poster="green70x30.png"
preload="auto"
preload="none"
style="border: solid blue 2px;">
</video>
</body>

View File

@ -3,9 +3,9 @@
<body style="background:white;">
<!-- Test that poster frame changes when you change the poster attribute. -->
<video src="black140x100.webm"
preload="auto"
preload="none"
id="v"
onload="document.getElementById('v').poster = 'red160x120.png'; setTimeout(function(){document.documentElement.className = '';}, 0);"
onload="document.getElementById('v').poster = 'red140x100.png'; setTimeout(function(){document.documentElement.className = '';}, 0);"
poster="blue250x200.png"></video>
</body>
</html>

View File

@ -0,0 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<img src="blue140x100.png" alt="poster">
</body>
</html>

View File

@ -0,0 +1,6 @@
<!DOCTYPE HTML>
<html>
<body style="background:white;">
<img src="red140x100.png" alt="poster">
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

View File

@ -24,11 +24,11 @@ skip-if(Android) == poster-3.html poster-ref-black140x100.html
skip-if(Android) == poster-4.html poster-ref-black140x100.html
skip-if(Android) == poster-5.html poster-ref-black140x100.html
skip-if(Android) == poster-6.html poster-ref-black140x100.html
skip-if(Android) == poster-7.html poster-ref-red160x120.html
skip-if(Android) == poster-7.html poster-ref-red140x100.html
skip-if(Android) == poster-8.html poster-ref-black140x100.html
skip-if(Android) == poster-10.html poster-ref-blue250x200.html
skip-if(Android) == poster-11.html poster-ref-blue250x200.html
skip-if(Android) == poster-12.html poster-ref-blue250x200.html
skip-if(Android) == poster-10.html poster-ref-blue140x100.html
skip-if(Android) == poster-11.html poster-ref-blue140x100.html
skip-if(Android) == poster-12.html poster-ref-blue140x100.html
skip-if(Android) == poster-13.html poster-ref-blue400x300.html
skip-if(Android) == poster-15.html poster-ref-green70x30.html
== bug686957.html bug686957-ref.html