[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

eric.carlson at apple.com eric.carlson at apple.com
Wed Dec 22 11:50:42 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 4ad835584b2929880984e11f62557003e4abd46f
Author: eric.carlson at apple.com <eric.carlson at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Aug 9 20:29:46 2010 +0000

    2010-08-09  Eric Carlson  <eric.carlson at apple.com>
    
            Reviewed by Darin Adler.
    
            https://bugs.webkit.org/show_bug.cgi?id=43702
            <video> element does not resize correctly
    
            * html/HTMLMediaElement.cpp:
            (WebCore::HTMLMediaElement::setReadyState): RenderVideo::videoSizeChanged is gone, just use
            updateFromElement instead.
            (WebCore::HTMLMediaElement::mediaPlayerDurationChanged): Ditto.
            (WebCore::HTMLMediaElement::mediaPlayerSizeChanged): Ditto.
    
            * html/HTMLVideoElement.cpp:
            (WebCore::HTMLVideoElement::parseMappedAttribute): Clear the image loader and cached image when
            the 'poster' attribute is changed and we aren't displaying a poster.
    
            * rendering/RenderVideo.cpp:
            (WebCore::RenderVideo::RenderVideo):
            (WebCore::RenderVideo::intrinsicSizeChanged): videoSizeChanged -> updateIntrinsicSize.
            (WebCore::RenderVideo::updateIntrinsicSize): Renamed from videoSizeChanged, calculate initial
            intrinsic size with calculateIntrinsicSize
            (WebCore::RenderVideo::calculateIntrinsicSize): New, calculate size according to current spec.
            (WebCore::RenderVideo::imageChanged): Reset intrinsic size to default when poster fails to load.
            (WebCore::RenderVideo::updatePlayer): Call updateIntrinsicSize.
            * rendering/RenderVideo.h: Renamed videoSizeChanged to updateIntrinsicSize and make private.
    
    2010-08-09  Eric Carlson  <eric.carlson at apple.com>
    
            Reviewed by Darin Adler.
    
            https://bugs.webkit.org/show_bug.cgi?id=43702
            <video> element does not resize correctly
    
            * media/video-poster-expected.txt:
            * media/video-poster.html:
            * media/video-size-expected.txt:
            * media/video-size.html:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64997 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 6ce2547..db95602 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2010-08-09  Eric Carlson  <eric.carlson at apple.com>
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=43702
+        <video> element does not resize correctly
+
+        * media/video-poster-expected.txt:
+        * media/video-poster.html:
+        * media/video-size-expected.txt:
+        * media/video-size.html:
+
 2010-08-09  Jian Li  <jianli at chromium.org>
 
         Update chromium test results.
diff --git a/LayoutTests/media/video-poster-expected.txt b/LayoutTests/media/video-poster-expected.txt
index 2602ff9..6989813 100644
--- a/LayoutTests/media/video-poster-expected.txt
+++ b/LayoutTests/media/video-poster-expected.txt
@@ -1,15 +1,38 @@
+Test <video> element with and without a poster.
 
-Set 'poster' to 'content/greenbox.png'.
+Testing poster null, with 'width' and 'height' attributes.
+EXPECTED (video.getAttribute('poster') == 'null') OK
+EXPECTED (relativeURL(video.poster) == '') OK
+EXPECTED (video.clientWidth == '320') OK
+EXPECTED (video.clientHeight == '240') OK
+
+Setting poster to "content/greenbox.png"
+Testing 25x25 poster 'content/greenbox.png', size should equal image size.
 EXPECTED (video.getAttribute('poster') == 'content/greenbox.png') OK
 EXPECTED (relativeURL(video.poster) == 'content/greenbox.png') OK
+EXPECTED (video.clientWidth == '25') OK
+EXPECTED (video.clientHeight == '25') OK
 
-Set 'poster' to ''.
+Setting poster to ""
+Testing poster '', with NO 'width' or 'height' attributes so size should be <video> default.
 EXPECTED (video.getAttribute('poster') == '') OK
 EXPECTED (relativeURL(video.poster) == 'video-poster.html') OK
+EXPECTED (video.clientWidth == '300') OK
+EXPECTED (video.clientHeight == '150') OK
 
-Set 'poster' to 'content/abe.png'.
+Setting poster to "content/abe.png"
+Testing 76x103 poster 'content/abe.png', size should equal image size.
 EXPECTED (video.getAttribute('poster') == 'content/abe.png') OK
 EXPECTED (relativeURL(video.poster) == 'content/abe.png') OK
+EXPECTED (video.clientWidth == '76') OK
+EXPECTED (video.clientHeight == '103') OK
+
+Setting poster to "content/bogus.png"
+Testing 300x150 poster 'content/bogus.png', invalid url so size should revert to <video> default.
+EXPECTED (video.getAttribute('poster') == 'content/bogus.png') OK
+EXPECTED (relativeURL(video.poster) == 'content/bogus.png') OK
+EXPECTED (video.clientWidth == '300') OK
+EXPECTED (video.clientHeight == '150') OK
 
 END OF TEST
 
diff --git a/LayoutTests/media/video-poster.html b/LayoutTests/media/video-poster.html
index b57456e..188cf2d 100644
--- a/LayoutTests/media/video-poster.html
+++ b/LayoutTests/media/video-poster.html
@@ -1,39 +1,102 @@
 <html>
     <head>
+        <title>&lt;video&gt; element with poster size test</title>
         <script src=video-test.js></script>
         <script>
+            var posterInfo = 
+            {
+                current:0,
+                posters: 
+                [ 
+                    {
+                        description:", with 'width' and 'height' attributes",
+                        url:null,
+                        reflectedUrl:"",
+                        width:320,
+                        height:240
+                    },
+                    {
+                        description:", size should equal image size",
+                        url:"content/greenbox.png",
+                        width:25,
+                        height:25
+                    },
+                    {
+                        description:", with NO 'width' or 'height' attributes so size should be &lt;video&gt; default",
+                        url:"",
+                        reflectedUrl:"video-poster.html",
+                        width:300,
+                        height:150
+                    },
+                    {
+                        description:", size should equal image size",
+                        url:"content/abe.png",
+                        width:76,
+                        height:103
+                    },
+                    {
+                        description:", invalid url so size should revert to &lt;video&gt; default",
+                        url:"content/bogus.png",
+                        width:300,
+                        height:150
+                    },
+                ]
+            };
 
-            function testPoster(url)
+            function openNextPoster()
             {
-                testExpected("video.getAttribute('poster')", url);
-                testExpected("relativeURL(video.poster)", url);
+                consoleWrite("");
+                if (posterInfo.current >= posterInfo.posters.length)
+                {
+                    endTest();
+                    return;
+                }
+
+                var url = posterInfo.posters[posterInfo.current].url;
+                var desc = "<b>Setting poster to <em>\""+ url + "\"</em></b>";
+                consoleWrite(desc);
+                video.poster = url;
+                setTimeout(testPoster, 100);
             }
-            
-            function test()
+
+            function testPoster()
             {
-                findMediaElement();
+                var temp = document.body.offsetWidth;
+                var poster = posterInfo.posters[posterInfo.current];
+
+                var size = poster.url ? (" " + poster.width + "x" + poster.height) : "";
+                var urlStr = typeof(poster.url) == "string" ? ("'" + poster.url + "'") : 'null';
+                var desc = "<b>Testing" + size + " poster <em>"+ urlStr + "</em>" + poster.description + ".</b>";
+                consoleWrite(desc);
 
-                consoleWrite("<br><i>Set 'poster' to 'content/greenbox.png'.<" + "/i>");
-                testPoster('content/greenbox.png');
+                testExpected("video.getAttribute('poster')", poster.url);
+                testExpected("relativeURL(video.poster)", poster.hasOwnProperty("reflectedUrl") ? poster.reflectedUrl : poster.url);
+                testExpected("video.clientWidth", poster.width);
+                testExpected("video.clientHeight", poster.height);
 
-                consoleWrite("<br><i>Set 'poster' to ''.<" + "/i>");
-                video.setAttribute('poster', '');
-                testExpected("video.getAttribute('poster')", '');
-                testExpected("relativeURL(video.poster)", 'video-poster.html');
+                // Remove width/height attributes if present
+                if (video.width)
+                    video.removeAttribute('width');
+                if (video.height)
+                    video.removeAttribute('height');
 
-                consoleWrite("<br><i>Set 'poster' to 'content/abe.png'.<" + "/i>");
-                video.setAttribute('poster', 'content/abe.png');
-                testPoster('content/abe.png');
+                posterInfo.current++;
+                openNextPoster();
+            }
+
+            function test()
+            {
+                findMediaElement();
 
-                consoleWrite('');
-                endTest();
+                testPoster();
             }
         </script>
     </head>
 
     <body onload="setTimeout(test, 100)">
 
-        <video poster="content/greenbox.png" controls></video>
+        <video controls width=320 height=240></video>
+        <p>Test &lt;video&gt; element with and without a poster.</p>
 
     </body>
 </html>
diff --git a/LayoutTests/media/video-size-expected.txt b/LayoutTests/media/video-size-expected.txt
index 53ec040..8e19077 100644
--- a/LayoutTests/media/video-size-expected.txt
+++ b/LayoutTests/media/video-size-expected.txt
@@ -1,7 +1,38 @@
+Test <video> element size with and without 'src' and 'poster' attributes.
+
+Testing movie with no 'src' and no 'poster', with 'width' and 'height' attributes.
+EXPECTED (video.clientWidth == '640') OK
+EXPECTED (video.clientHeight == '480') OK
+EXPECTED (video.videoWidth == '0') OK
+EXPECTED (video.videoHeight == '0') OK
+
+Removing 'width' and 'height' attributes.
+Testing movie with no 'src' and no 'poster', with NO 'width' and 'height' attributes, should be default size.
+EXPECTED (video.clientWidth == '300') OK
+EXPECTED (video.clientHeight == '150') OK
+EXPECTED (video.videoWidth == '0') OK
+EXPECTED (video.videoHeight == '0') OK
+
+Setting 'poster' to "content/abe.png"
+Testing movie with 'poster' but no 'src', should be image size.
+EXPECTED (video.clientWidth == '76') OK
+EXPECTED (video.clientHeight == '103') OK
+EXPECTED (video.videoWidth == '0') OK
+EXPECTED (video.videoHeight == '0') OK
+
+Setting 'src' to "content/test.[extension]" 
+Testing movie with 'poster' and 'src', should be <video> size.
+EXPECTED (video.clientWidth == '320') OK
+EXPECTED (video.clientHeight == '240') OK
+EXPECTED (video.videoWidth == '320') OK
+EXPECTED (video.videoHeight == '240') OK
+
+Setting 'src' to "content/bogus.[extension]" 'poster' to "content/greenbox.png"
+Testing movie with 'poster' and invalid 'src', should be image size.
+EXPECTED (video.clientWidth == '25') OK
+EXPECTED (video.clientHeight == '25') OK
 EXPECTED (video.videoWidth == '0') OK
 EXPECTED (video.videoHeight == '0') OK
-EVENT(loadedmetadata)
-EXPECTED (video.videoWidth > '0') OK
-EXPECTED (video.videoHeight > '0') OK
+
 END OF TEST
 
diff --git a/LayoutTests/media/video-size.html b/LayoutTests/media/video-size.html
index ca219f9..c237ff0 100644
--- a/LayoutTests/media/video-size.html
+++ b/LayoutTests/media/video-size.html
@@ -1,15 +1,129 @@
-<video controls></video>
-<script src=media-file.js></script>
-<script src=video-test.js></script>
-<script>
-    testExpected("video.videoWidth", 0, "==");
-    testExpected("video.videoHeight", 0, "==");
-
-    waitForEvent('loadedmetadata', function () { 
-        testExpected("video.videoWidth", 0, ">");
-        testExpected("video.videoHeight", 0, ">");
-        endTest();
-    } );
-
-    video.src = findMediaFile("video", "content/test");
-</script>
+<html>
+    <head>
+        <title>&lt;video&gt; element size and resize test</title>
+        <script src=video-test.js></script>
+        <script src=media-file.js></script>
+
+        <script>
+            var movieInfo = 
+            {
+                current:0,
+                movies: 
+                [ 
+                    {   
+                        src:null,
+                        poster:null,
+                        description:"no 'src' and no 'poster', with 'width' and 'height' attributes",
+                        width:640,
+                        height:480,
+                        videoWidth:0,
+                        videoHeight:0
+                    },
+                    {
+                        src:null,
+                        poster:null,
+                        description:"no 'src' and no 'poster', with NO 'width' and 'height' attributes, should be default size",
+                        width:300,
+                        height:150,
+                        videoWidth:0,
+                        videoHeight:0
+                    },
+                    {
+                        src:null,
+                        poster:"content/abe.png",
+                        description:"'poster' but no  'src', should be image size",
+                        width:76,
+                        height:103,
+                        videoWidth:0,
+                        videoHeight:0
+                    },
+                    {
+                        src:"content/test",
+                        poster:"content/abe.png",
+                        description:"'poster' and  'src', should be &lt;video&gt; size",
+                        width:320,
+                        height:240,
+                        videoWidth:320,
+                        videoHeight:240
+                    },
+                    {
+                        src:"content/bogus",
+                        poster:"content/greenbox.png",
+                        description:"'poster' and invalid 'src', should be image size",
+                        width:25,
+                        height:25,
+                        videoWidth:0,
+                        videoHeight:0
+                    },
+                ]
+            };
+
+            function setupNextConfiguration()
+            {
+                consoleWrite("");
+                if (movieInfo.current >= movieInfo.movies.length)
+                {
+                    endTest();
+                    return;
+                }
+
+                var movie = movieInfo.movies[movieInfo.current];
+                if (movie.src || movie.poster) {
+                    var desc = "<b>Setting ";
+                    if (movie.src && relativeURL(video.src) != movie.src) {
+                        video.src = findMediaFile("video", movie.src);
+                        desc += "'src' to <em>\""+ movie.src + ".[extension]\"</em> ";
+                    }
+                    if (movie.poster && relativeURL(video.poster) != movie.poster) {
+                        video.poster = movie.poster;
+                        desc += "'poster' to <em>\""+ movie.poster + "\"</em>";
+                    }
+                    consoleWrite(desc + "</b>");
+                }
+
+                // Remove width/height attributes if present
+                if (video.width || video.height) {
+                    consoleWrite("<b>Removing 'width' and 'height' attributes.</b>");
+                    video.removeAttribute('width');
+                    video.removeAttribute('height');
+                }
+
+                if (!movie.src || movie.src.indexOf('bogus') >= 0)
+                    setTimeout(testMovie, 100);
+            }
+
+            function testMovie()
+            {
+                if (movieInfo.current >= movieInfo.movies.length)
+                    return;
+
+                var temp = document.body.offsetWidth;
+                var movie = movieInfo.movies[movieInfo.current];
+
+                var desc = "<b>Testing movie with " + movie.description + ".</b>";
+                consoleWrite(desc);
+
+                testExpected("video.clientWidth", movie.width);
+                testExpected("video.clientHeight", movie.height);
+                testExpected("video.videoWidth", movie.videoWidth);
+                testExpected("video.videoHeight", movie.videoHeight);
+
+                movieInfo.current++;
+                setupNextConfiguration();
+            }
+
+            function test()
+            {
+                findMediaElement();
+                testMovie();
+            }
+        </script>
+    </head>
+
+    <body onload="setTimeout(test, 100)">
+
+        <video controls width=640 height=480 onloadedmetadata="testMovie()"></video>
+        <p>Test &lt;video&gt; element size with and without 'src' and 'poster' attributes.</p>
+
+    </body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f3de4c9..48e1b72 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,30 @@
+2010-08-09  Eric Carlson  <eric.carlson at apple.com>
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=43702
+        <video> element does not resize correctly
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setReadyState): RenderVideo::videoSizeChanged is gone, just use
+        updateFromElement instead.
+        (WebCore::HTMLMediaElement::mediaPlayerDurationChanged): Ditto.
+        (WebCore::HTMLMediaElement::mediaPlayerSizeChanged): Ditto.
+
+        * html/HTMLVideoElement.cpp:
+        (WebCore::HTMLVideoElement::parseMappedAttribute): Clear the image loader and cached image when 
+        the 'poster' attribute is changed and we aren't displaying a poster.
+
+        * rendering/RenderVideo.cpp:
+        (WebCore::RenderVideo::RenderVideo):
+        (WebCore::RenderVideo::intrinsicSizeChanged): videoSizeChanged -> updateIntrinsicSize.
+        (WebCore::RenderVideo::updateIntrinsicSize): Renamed from videoSizeChanged, calculate initial 
+        intrinsic size with calculateIntrinsicSize
+        (WebCore::RenderVideo::calculateIntrinsicSize): New, calculate size according to current spec.
+        (WebCore::RenderVideo::imageChanged): Reset intrinsic size to default when poster fails to load.
+        (WebCore::RenderVideo::updatePlayer): Call updateIntrinsicSize.
+        * rendering/RenderVideo.h: Renamed videoSizeChanged to updateIntrinsicSize and make private.
+
 2010-08-09  Marcus Bulach  <bulach at chromium.org>
 
         Reviewed by Jeremy Orlow.
diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp
index ecd6c03..b1f5819 100644
--- a/WebCore/html/HTMLMediaElement.cpp
+++ b/WebCore/html/HTMLMediaElement.cpp
@@ -910,12 +910,8 @@ void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
     if (m_readyState >= HAVE_METADATA && oldState < HAVE_METADATA) {
         scheduleEvent(eventNames().durationchangeEvent);
         scheduleEvent(eventNames().loadedmetadataEvent);
-
-#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
-        if (renderer() && renderer()->isVideo()) {
-            toRenderVideo(renderer())->videoSizeChanged();
-        }
-#endif        
+        if (renderer())
+            renderer()->updateFromElement();
         m_delayingTheLoadEvent = false;
         m_player->seek(0);
     }
@@ -1579,13 +1575,8 @@ void HTMLMediaElement::mediaPlayerDurationChanged(MediaPlayer*)
 {
     beginProcessingMediaPlayerCallback();
     scheduleEvent(eventNames().durationchangeEvent);
-#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
-    if (renderer()) {
+    if (renderer())
         renderer()->updateFromElement();
-        if (renderer()->isVideo())
-            toRenderVideo(renderer())->videoSizeChanged();
-    }
-#endif        
     endProcessingMediaPlayerCallback();
 }
 
@@ -1622,10 +1613,8 @@ void HTMLMediaElement::mediaPlayerRepaint(MediaPlayer*)
 void HTMLMediaElement::mediaPlayerSizeChanged(MediaPlayer*)
 {
     beginProcessingMediaPlayerCallback();
-#if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
-    if (renderer() && renderer()->isVideo())
-        toRenderVideo(renderer())->videoSizeChanged();
-#endif        
+    if (renderer())
+        renderer()->updateFromElement();
     endProcessingMediaPlayerCallback();
 }
 
diff --git a/WebCore/html/HTMLVideoElement.cpp b/WebCore/html/HTMLVideoElement.cpp
index fc74d32..ed2d35c 100644
--- a/WebCore/html/HTMLVideoElement.cpp
+++ b/WebCore/html/HTMLVideoElement.cpp
@@ -102,13 +102,18 @@ void HTMLVideoElement::parseMappedAttribute(Attribute* attr)
         // Force a poster recalc by setting m_displayMode to Unknown directly before calling updateDisplayState.
         HTMLMediaElement::setDisplayMode(Unknown);
         updateDisplayState();
-        if (shouldDisplayPosterImage()) {
 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
+        if (shouldDisplayPosterImage()) {
             if (!m_imageLoader)
                 m_imageLoader.set(new HTMLImageLoader(this));
             m_imageLoader->updateFromElementIgnoringPreviousError();
-#endif
+        } else {
+            if (m_imageLoader)
+                m_imageLoader.clear();
+            if (renderer())
+                toRenderImage(renderer())->setCachedImage(0); 
         }
+#endif
     } else if (attrName == widthAttr)
         addCSSLength(attr, CSSPropertyWidth, attr->value());
     else if (attrName == heightAttr)
diff --git a/WebCore/rendering/RenderVideo.cpp b/WebCore/rendering/RenderVideo.cpp
index 1e0adc4..ab969cc 100644
--- a/WebCore/rendering/RenderVideo.cpp
+++ b/WebCore/rendering/RenderVideo.cpp
@@ -50,25 +50,7 @@ using namespace HTMLNames;
 RenderVideo::RenderVideo(HTMLVideoElement* video)
     : RenderMedia(video)
 {
-    if (video->player() && video->readyState() >= HTMLVideoElement::HAVE_METADATA)
-        setIntrinsicSize(video->player()->naturalSize());
-    else {
-        // 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 these attributes are not set, we fall back
-        // to a default video size (300x150).
-        if (video->hasAttribute(widthAttr) && video->hasAttribute(heightAttr))
-            setIntrinsicSize(IntSize(video->width(), video->height()));
-        else if (video->ownerDocument() && video->ownerDocument()->isMediaDocument()) {
-            // Video in standalone media documents should not use the default 300x150
-            // size since they also have audio thrown at them. By setting the intrinsic
-            // size to 300x1 the video will resize itself in these cases, and audio will
-            // have the correct height (it needs to be > 0 for controls to render properly).
-            setIntrinsicSize(IntSize(defaultSize().width(), 1));
-        }
-        else
-            setIntrinsicSize(defaultSize());
-    }
+    setIntrinsicSize(calculateIntrinsicSize());
 }
 
 RenderVideo::~RenderVideo()
@@ -92,24 +74,59 @@ void RenderVideo::intrinsicSizeChanged()
 {
     if (videoElement()->shouldDisplayPosterImage())
         RenderMedia::intrinsicSizeChanged();
-    videoSizeChanged(); 
+    updateIntrinsicSize(); 
 }
 
-
-void RenderVideo::videoSizeChanged()
+void RenderVideo::updateIntrinsicSize()
 {
-    if (!player())
+    IntSize size = calculateIntrinsicSize();
+
+    // Never set the element size to zero when in a media document.
+    if (size.isEmpty() && node()->ownerDocument() && node()->ownerDocument()->isMediaDocument())
         return;
-    IntSize size = player()->naturalSize();
-    if (size.isEmpty()) {
-        if (node()->ownerDocument() && node()->ownerDocument()->isMediaDocument())
-            return;
-    }
-    if (size != intrinsicSize()) {
-        setIntrinsicSize(size);
-        setPrefWidthsDirty(true);
-        setNeedsLayout(true);
-    }
+
+    if (size == intrinsicSize())
+        return;
+
+    setIntrinsicSize(size);
+    setPrefWidthsDirty(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() && !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());
+
+    // <video> in standalone media documents should not use the default 300x150
+    // size since they also have audio-only files. By setting the intrinsic
+    // size to 300x1 the video will resize itself in these cases, and audio will
+    // have the correct height (it needs to be > 0 for controls to render properly).
+    if (video->ownerDocument() && video->ownerDocument()->isMediaDocument())
+        return IntSize(defaultSize().width(), 1);
+
+    return defaultSize();
 }
 
 void RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
@@ -119,8 +136,11 @@ void RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
     // Cache the image intrinsic size so we can continue to use it to draw the image correctly
     // even after we know the video intrisic size but aren't able to draw video frames yet
     // (we don't want to scale the poster to the video size).
-    if (videoElement()->shouldDisplayPosterImage())
+    if (videoElement()->shouldDisplayPosterImage()) {
+        if (errorOccurred())
+            updateIntrinsicSize();
         m_cachedImageSize = intrinsicSize();
+    }
 }
 
 IntRect RenderVideo::videoBox() const
@@ -206,9 +226,12 @@ void RenderVideo::updateFromElement()
 
 void RenderVideo::updatePlayer()
 {
+    updateIntrinsicSize();
+
     MediaPlayer* mediaPlayer = player();
     if (!mediaPlayer)
         return;
+
     if (!videoElement()->inActiveDocument()) {
         mediaPlayer->setVisible(false);
         return;
diff --git a/WebCore/rendering/RenderVideo.h b/WebCore/rendering/RenderVideo.h
index d2f0ed4..dd7a531 100644
--- a/WebCore/rendering/RenderVideo.h
+++ b/WebCore/rendering/RenderVideo.h
@@ -40,7 +40,6 @@ public:
     RenderVideo(HTMLVideoElement*);
     virtual ~RenderVideo();
 
-    void videoSizeChanged();
     IntRect videoBox() const;
 
     static IntSize defaultSize();
@@ -57,6 +56,9 @@ private:
     inline HTMLVideoElement* videoElement() const;
 
     virtual void intrinsicSizeChanged();
+    IntSize calculateIntrinsicSize();
+    void updateIntrinsicSize();
+
     virtual void imageChanged(WrappedImagePtr, const IntRect*);
 
     virtual const char* renderName() const { return "RenderVideo"; }
@@ -71,7 +73,7 @@ private:
     virtual int calcReplacedWidth(bool includeMaxWidth = true) const;
     virtual int calcReplacedHeight() const;
     virtual int minimumReplacedHeight() const;
-    
+
     int calcAspectRatioWidth() const;
     int calcAspectRatioHeight() const;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list