Changeset 64997 in webkit
- Timestamp:
- Aug 9, 2010 1:29:46 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r64989 r64997 1 2010-08-09 Eric Carlson <eric.carlson@apple.com> 2 3 Reviewed by Darin Adler. 4 5 https://bugs.webkit.org/show_bug.cgi?id=43702 6 <video> element does not resize correctly 7 8 * media/video-poster-expected.txt: 9 * media/video-poster.html: 10 * media/video-size-expected.txt: 11 * media/video-size.html: 12 1 13 2010-08-09 Jian Li <jianli@chromium.org> 2 14 -
trunk/LayoutTests/media/video-poster-expected.txt
r64085 r64997 1 Test <video> element with and without a poster. 1 2 2 Set 'poster' to 'content/greenbox.png'. 3 Testing poster null, with 'width' and 'height' attributes. 4 EXPECTED (video.getAttribute('poster') == 'null') OK 5 EXPECTED (relativeURL(video.poster) == '') OK 6 EXPECTED (video.clientWidth == '320') OK 7 EXPECTED (video.clientHeight == '240') OK 8 9 Setting poster to "content/greenbox.png" 10 Testing 25x25 poster 'content/greenbox.png', size should equal image size. 3 11 EXPECTED (video.getAttribute('poster') == 'content/greenbox.png') OK 4 12 EXPECTED (relativeURL(video.poster) == 'content/greenbox.png') OK 13 EXPECTED (video.clientWidth == '25') OK 14 EXPECTED (video.clientHeight == '25') OK 5 15 6 Set 'poster' to ''. 16 Setting poster to "" 17 Testing poster '', with NO 'width' or 'height' attributes so size should be <video> default. 7 18 EXPECTED (video.getAttribute('poster') == '') OK 8 19 EXPECTED (relativeURL(video.poster) == 'video-poster.html') OK 20 EXPECTED (video.clientWidth == '300') OK 21 EXPECTED (video.clientHeight == '150') OK 9 22 10 Set 'poster' to 'content/abe.png'. 23 Setting poster to "content/abe.png" 24 Testing 76x103 poster 'content/abe.png', size should equal image size. 11 25 EXPECTED (video.getAttribute('poster') == 'content/abe.png') OK 12 26 EXPECTED (relativeURL(video.poster) == 'content/abe.png') OK 27 EXPECTED (video.clientWidth == '76') OK 28 EXPECTED (video.clientHeight == '103') OK 29 30 Setting poster to "content/bogus.png" 31 Testing 300x150 poster 'content/bogus.png', invalid url so size should revert to <video> default. 32 EXPECTED (video.getAttribute('poster') == 'content/bogus.png') OK 33 EXPECTED (relativeURL(video.poster) == 'content/bogus.png') OK 34 EXPECTED (video.clientWidth == '300') OK 35 EXPECTED (video.clientHeight == '150') OK 13 36 14 37 END OF TEST -
trunk/LayoutTests/media/video-poster.html
r64085 r64997 1 1 <html> 2 2 <head> 3 <title><video> element with poster size test</title> 3 4 <script src=video-test.js></script> 4 5 <script> 6 var posterInfo = 7 { 8 current:0, 9 posters: 10 [ 11 { 12 description:", with 'width' and 'height' attributes", 13 url:null, 14 reflectedUrl:"", 15 width:320, 16 height:240 17 }, 18 { 19 description:", size should equal image size", 20 url:"content/greenbox.png", 21 width:25, 22 height:25 23 }, 24 { 25 description:", with NO 'width' or 'height' attributes so size should be <video> default", 26 url:"", 27 reflectedUrl:"video-poster.html", 28 width:300, 29 height:150 30 }, 31 { 32 description:", size should equal image size", 33 url:"content/abe.png", 34 width:76, 35 height:103 36 }, 37 { 38 description:", invalid url so size should revert to <video> default", 39 url:"content/bogus.png", 40 width:300, 41 height:150 42 }, 43 ] 44 }; 5 45 6 function testPoster(url)46 function openNextPoster() 7 47 { 8 testExpected("video.getAttribute('poster')", url); 9 testExpected("relativeURL(video.poster)", url); 48 consoleWrite(""); 49 if (posterInfo.current >= posterInfo.posters.length) 50 { 51 endTest(); 52 return; 53 } 54 55 var url = posterInfo.posters[posterInfo.current].url; 56 var desc = "<b>Setting poster to <em>\""+ url + "\"</em></b>"; 57 consoleWrite(desc); 58 video.poster = url; 59 setTimeout(testPoster, 100); 10 60 } 11 61 62 function testPoster() 63 { 64 var temp = document.body.offsetWidth; 65 var poster = posterInfo.posters[posterInfo.current]; 66 67 var size = poster.url ? (" " + poster.width + "x" + poster.height) : ""; 68 var urlStr = typeof(poster.url) == "string" ? ("'" + poster.url + "'") : 'null'; 69 var desc = "<b>Testing" + size + " poster <em>"+ urlStr + "</em>" + poster.description + ".</b>"; 70 consoleWrite(desc); 71 72 testExpected("video.getAttribute('poster')", poster.url); 73 testExpected("relativeURL(video.poster)", poster.hasOwnProperty("reflectedUrl") ? poster.reflectedUrl : poster.url); 74 testExpected("video.clientWidth", poster.width); 75 testExpected("video.clientHeight", poster.height); 76 77 // Remove width/height attributes if present 78 if (video.width) 79 video.removeAttribute('width'); 80 if (video.height) 81 video.removeAttribute('height'); 82 83 posterInfo.current++; 84 openNextPoster(); 85 } 86 12 87 function test() 13 88 { 14 89 findMediaElement(); 15 90 16 consoleWrite("<br><i>Set 'poster' to 'content/greenbox.png'.<" + "/i>"); 17 testPoster('content/greenbox.png'); 18 19 consoleWrite("<br><i>Set 'poster' to ''.<" + "/i>"); 20 video.setAttribute('poster', ''); 21 testExpected("video.getAttribute('poster')", ''); 22 testExpected("relativeURL(video.poster)", 'video-poster.html'); 23 24 consoleWrite("<br><i>Set 'poster' to 'content/abe.png'.<" + "/i>"); 25 video.setAttribute('poster', 'content/abe.png'); 26 testPoster('content/abe.png'); 27 28 consoleWrite(''); 29 endTest(); 91 testPoster(); 30 92 } 31 93 </script> … … 34 96 <body onload="setTimeout(test, 100)"> 35 97 36 <video poster="content/greenbox.png" controls></video> 98 <video controls width=320 height=240></video> 99 <p>Test <video> element with and without a poster.</p> 37 100 38 101 </body> -
trunk/LayoutTests/media/video-size-expected.txt
r41413 r64997 1 Test <video> element size with and without 'src' and 'poster' attributes. 2 3 Testing movie with no 'src' and no 'poster', with 'width' and 'height' attributes. 4 EXPECTED (video.clientWidth == '640') OK 5 EXPECTED (video.clientHeight == '480') OK 1 6 EXPECTED (video.videoWidth == '0') OK 2 7 EXPECTED (video.videoHeight == '0') OK 3 EVENT(loadedmetadata) 4 EXPECTED (video.videoWidth > '0') OK 5 EXPECTED (video.videoHeight > '0') OK 8 9 Removing 'width' and 'height' attributes. 10 Testing movie with no 'src' and no 'poster', with NO 'width' and 'height' attributes, should be default size. 11 EXPECTED (video.clientWidth == '300') OK 12 EXPECTED (video.clientHeight == '150') OK 13 EXPECTED (video.videoWidth == '0') OK 14 EXPECTED (video.videoHeight == '0') OK 15 16 Setting 'poster' to "content/abe.png" 17 Testing movie with 'poster' but no 'src', should be image size. 18 EXPECTED (video.clientWidth == '76') OK 19 EXPECTED (video.clientHeight == '103') OK 20 EXPECTED (video.videoWidth == '0') OK 21 EXPECTED (video.videoHeight == '0') OK 22 23 Setting 'src' to "content/test.[extension]" 24 Testing movie with 'poster' and 'src', should be <video> size. 25 EXPECTED (video.clientWidth == '320') OK 26 EXPECTED (video.clientHeight == '240') OK 27 EXPECTED (video.videoWidth == '320') OK 28 EXPECTED (video.videoHeight == '240') OK 29 30 Setting 'src' to "content/bogus.[extension]" 'poster' to "content/greenbox.png" 31 Testing movie with 'poster' and invalid 'src', should be image size. 32 EXPECTED (video.clientWidth == '25') OK 33 EXPECTED (video.clientHeight == '25') OK 34 EXPECTED (video.videoWidth == '0') OK 35 EXPECTED (video.videoHeight == '0') OK 36 6 37 END OF TEST 7 38 -
trunk/LayoutTests/media/video-size.html
r48539 r64997 1 <video controls></video> 2 <script src=media-file.js></script> 3 <script src=video-test.js></script> 4 <script> 5 testExpected("video.videoWidth", 0, "=="); 6 testExpected("video.videoHeight", 0, "=="); 1 <html> 2 <head> 3 <title><video> element size and resize test</title> 4 <script src=video-test.js></script> 5 <script src=media-file.js></script> 7 6 8 waitForEvent('loadedmetadata', function () { 9 testExpected("video.videoWidth", 0, ">"); 10 testExpected("video.videoHeight", 0, ">"); 11 endTest(); 12 } ); 7 <script> 8 var movieInfo = 9 { 10 current:0, 11 movies: 12 [ 13 { 14 src:null, 15 poster:null, 16 description:"no 'src' and no 'poster', with 'width' and 'height' attributes", 17 width:640, 18 height:480, 19 videoWidth:0, 20 videoHeight:0 21 }, 22 { 23 src:null, 24 poster:null, 25 description:"no 'src' and no 'poster', with NO 'width' and 'height' attributes, should be default size", 26 width:300, 27 height:150, 28 videoWidth:0, 29 videoHeight:0 30 }, 31 { 32 src:null, 33 poster:"content/abe.png", 34 description:"'poster' but no 'src', should be image size", 35 width:76, 36 height:103, 37 videoWidth:0, 38 videoHeight:0 39 }, 40 { 41 src:"content/test", 42 poster:"content/abe.png", 43 description:"'poster' and 'src', should be <video> size", 44 width:320, 45 height:240, 46 videoWidth:320, 47 videoHeight:240 48 }, 49 { 50 src:"content/bogus", 51 poster:"content/greenbox.png", 52 description:"'poster' and invalid 'src', should be image size", 53 width:25, 54 height:25, 55 videoWidth:0, 56 videoHeight:0 57 }, 58 ] 59 }; 13 60 14 video.src = findMediaFile("video", "content/test"); 15 </script> 61 function setupNextConfiguration() 62 { 63 consoleWrite(""); 64 if (movieInfo.current >= movieInfo.movies.length) 65 { 66 endTest(); 67 return; 68 } 69 70 var movie = movieInfo.movies[movieInfo.current]; 71 if (movie.src || movie.poster) { 72 var desc = "<b>Setting "; 73 if (movie.src && relativeURL(video.src) != movie.src) { 74 video.src = findMediaFile("video", movie.src); 75 desc += "'src' to <em>\""+ movie.src + ".[extension]\"</em> "; 76 } 77 if (movie.poster && relativeURL(video.poster) != movie.poster) { 78 video.poster = movie.poster; 79 desc += "'poster' to <em>\""+ movie.poster + "\"</em>"; 80 } 81 consoleWrite(desc + "</b>"); 82 } 83 84 // Remove width/height attributes if present 85 if (video.width || video.height) { 86 consoleWrite("<b>Removing 'width' and 'height' attributes.</b>"); 87 video.removeAttribute('width'); 88 video.removeAttribute('height'); 89 } 90 91 if (!movie.src || movie.src.indexOf('bogus') >= 0) 92 setTimeout(testMovie, 100); 93 } 94 95 function testMovie() 96 { 97 if (movieInfo.current >= movieInfo.movies.length) 98 return; 99 100 var temp = document.body.offsetWidth; 101 var movie = movieInfo.movies[movieInfo.current]; 102 103 var desc = "<b>Testing movie with " + movie.description + ".</b>"; 104 consoleWrite(desc); 105 106 testExpected("video.clientWidth", movie.width); 107 testExpected("video.clientHeight", movie.height); 108 testExpected("video.videoWidth", movie.videoWidth); 109 testExpected("video.videoHeight", movie.videoHeight); 110 111 movieInfo.current++; 112 setupNextConfiguration(); 113 } 114 115 function test() 116 { 117 findMediaElement(); 118 testMovie(); 119 } 120 </script> 121 </head> 122 123 <body onload="setTimeout(test, 100)"> 124 125 <video controls width=640 height=480 onloadedmetadata="testMovie()"></video> 126 <p>Test <video> element size with and without 'src' and 'poster' attributes.</p> 127 128 </body> 129 </html> -
trunk/WebCore/ChangeLog
r64996 r64997 1 2010-08-09 Eric Carlson <eric.carlson@apple.com> 2 3 Reviewed by Darin Adler. 4 5 https://bugs.webkit.org/show_bug.cgi?id=43702 6 <video> element does not resize correctly 7 8 * html/HTMLMediaElement.cpp: 9 (WebCore::HTMLMediaElement::setReadyState): RenderVideo::videoSizeChanged is gone, just use 10 updateFromElement instead. 11 (WebCore::HTMLMediaElement::mediaPlayerDurationChanged): Ditto. 12 (WebCore::HTMLMediaElement::mediaPlayerSizeChanged): Ditto. 13 14 * html/HTMLVideoElement.cpp: 15 (WebCore::HTMLVideoElement::parseMappedAttribute): Clear the image loader and cached image when 16 the 'poster' attribute is changed and we aren't displaying a poster. 17 18 * rendering/RenderVideo.cpp: 19 (WebCore::RenderVideo::RenderVideo): 20 (WebCore::RenderVideo::intrinsicSizeChanged): videoSizeChanged -> updateIntrinsicSize. 21 (WebCore::RenderVideo::updateIntrinsicSize): Renamed from videoSizeChanged, calculate initial 22 intrinsic size with calculateIntrinsicSize 23 (WebCore::RenderVideo::calculateIntrinsicSize): New, calculate size according to current spec. 24 (WebCore::RenderVideo::imageChanged): Reset intrinsic size to default when poster fails to load. 25 (WebCore::RenderVideo::updatePlayer): Call updateIntrinsicSize. 26 * rendering/RenderVideo.h: Renamed videoSizeChanged to updateIntrinsicSize and make private. 27 1 28 2010-08-09 Marcus Bulach <bulach@chromium.org> 2 29 -
trunk/WebCore/html/HTMLMediaElement.cpp
r64884 r64997 911 911 scheduleEvent(eventNames().durationchangeEvent); 912 912 scheduleEvent(eventNames().loadedmetadataEvent); 913 914 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) 915 if (renderer() && renderer()->isVideo()) { 916 toRenderVideo(renderer())->videoSizeChanged(); 917 } 918 #endif 913 if (renderer()) 914 renderer()->updateFromElement(); 919 915 m_delayingTheLoadEvent = false; 920 916 m_player->seek(0); … … 1580 1576 beginProcessingMediaPlayerCallback(); 1581 1577 scheduleEvent(eventNames().durationchangeEvent); 1582 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) 1583 if (renderer()) { 1578 if (renderer()) 1584 1579 renderer()->updateFromElement(); 1585 if (renderer()->isVideo())1586 toRenderVideo(renderer())->videoSizeChanged();1587 }1588 #endif1589 1580 endProcessingMediaPlayerCallback(); 1590 1581 } … … 1623 1614 { 1624 1615 beginProcessingMediaPlayerCallback(); 1625 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) 1626 if (renderer() && renderer()->isVideo()) 1627 toRenderVideo(renderer())->videoSizeChanged(); 1628 #endif 1616 if (renderer()) 1617 renderer()->updateFromElement(); 1629 1618 endProcessingMediaPlayerCallback(); 1630 1619 } -
trunk/WebCore/html/HTMLVideoElement.cpp
r64884 r64997 103 103 HTMLMediaElement::setDisplayMode(Unknown); 104 104 updateDisplayState(); 105 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) 105 106 if (shouldDisplayPosterImage()) { 106 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)107 107 if (!m_imageLoader) 108 108 m_imageLoader.set(new HTMLImageLoader(this)); 109 109 m_imageLoader->updateFromElementIgnoringPreviousError(); 110 #endif 110 } else { 111 if (m_imageLoader) 112 m_imageLoader.clear(); 113 if (renderer()) 114 toRenderImage(renderer())->setCachedImage(0); 111 115 } 116 #endif 112 117 } else if (attrName == widthAttr) 113 118 addCSSLength(attr, CSSPropertyWidth, attr->value()); -
trunk/WebCore/rendering/RenderVideo.cpp
r64884 r64997 51 51 : RenderMedia(video) 52 52 { 53 if (video->player() && video->readyState() >= HTMLVideoElement::HAVE_METADATA) 54 setIntrinsicSize(video->player()->naturalSize()); 55 else { 56 // When the natural size of the video is unavailable, we use the provided 57 // width and height attributes of the video element as the intrinsic size until 58 // better values become available. If these attributes are not set, we fall back 59 // to a default video size (300x150). 60 if (video->hasAttribute(widthAttr) && video->hasAttribute(heightAttr)) 61 setIntrinsicSize(IntSize(video->width(), video->height())); 62 else if (video->ownerDocument() && video->ownerDocument()->isMediaDocument()) { 63 // Video in standalone media documents should not use the default 300x150 64 // size since they also have audio thrown at them. By setting the intrinsic 65 // size to 300x1 the video will resize itself in these cases, and audio will 66 // have the correct height (it needs to be > 0 for controls to render properly). 67 setIntrinsicSize(IntSize(defaultSize().width(), 1)); 68 } 69 else 70 setIntrinsicSize(defaultSize()); 71 } 53 setIntrinsicSize(calculateIntrinsicSize()); 72 54 } 73 55 … … 93 75 if (videoElement()->shouldDisplayPosterImage()) 94 76 RenderMedia::intrinsicSizeChanged(); 95 videoSizeChanged(); 96 } 97 98 99 void RenderVideo::videoSizeChanged() 100 { 101 if (!player()) 102 return; 103 IntSize size = player()->naturalSize(); 104 if (size.isEmpty()) { 105 if (node()->ownerDocument() && node()->ownerDocument()->isMediaDocument()) 106 return; 107 } 108 if (size != intrinsicSize()) { 109 setIntrinsicSize(size); 110 setPrefWidthsDirty(true); 111 setNeedsLayout(true); 112 } 77 updateIntrinsicSize(); 78 } 79 80 void RenderVideo::updateIntrinsicSize() 81 { 82 IntSize size = calculateIntrinsicSize(); 83 84 // Never set the element size to zero when in a media document. 85 if (size.isEmpty() && node()->ownerDocument() && node()->ownerDocument()->isMediaDocument()) 86 return; 87 88 if (size == intrinsicSize()) 89 return; 90 91 setIntrinsicSize(size); 92 setPrefWidthsDirty(true); 93 setNeedsLayout(true); 94 } 95 96 IntSize RenderVideo::calculateIntrinsicSize() 97 { 98 HTMLVideoElement* video = videoElement(); 99 100 // Spec text from 4.8.6 101 // 102 // The intrinsic width of a video element's playback area is the intrinsic width 103 // of the video resource, if that is available; otherwise it is the intrinsic 104 // width of the poster frame, if that is available; otherwise it is 300 CSS pixels. 105 // 106 // The intrinsic height of a video element's playback area is the intrinsic height 107 // of the video resource, if that is available; otherwise it is the intrinsic 108 // height of the poster frame, if that is available; otherwise it is 150 CSS pixels. 109 110 if (player() && video->readyState() >= HTMLVideoElement::HAVE_METADATA) 111 return player()->naturalSize(); 112 113 if (video->shouldDisplayPosterImage() && !m_cachedImageSize.isEmpty() && !errorOccurred()) 114 return m_cachedImageSize; 115 116 // When the natural size of the video is unavailable, we use the provided 117 // width and height attributes of the video element as the intrinsic size until 118 // better values become available. 119 if (video->hasAttribute(widthAttr) && video->hasAttribute(heightAttr)) 120 return IntSize(video->width(), video->height()); 121 122 // <video> in standalone media documents should not use the default 300x150 123 // size since they also have audio-only files. By setting the intrinsic 124 // size to 300x1 the video will resize itself in these cases, and audio will 125 // have the correct height (it needs to be > 0 for controls to render properly). 126 if (video->ownerDocument() && video->ownerDocument()->isMediaDocument()) 127 return IntSize(defaultSize().width(), 1); 128 129 return defaultSize(); 113 130 } 114 131 … … 120 137 // even after we know the video intrisic size but aren't able to draw video frames yet 121 138 // (we don't want to scale the poster to the video size). 122 if (videoElement()->shouldDisplayPosterImage()) 139 if (videoElement()->shouldDisplayPosterImage()) { 140 if (errorOccurred()) 141 updateIntrinsicSize(); 123 142 m_cachedImageSize = intrinsicSize(); 143 } 124 144 } 125 145 … … 207 227 void RenderVideo::updatePlayer() 208 228 { 229 updateIntrinsicSize(); 230 209 231 MediaPlayer* mediaPlayer = player(); 210 232 if (!mediaPlayer) 211 233 return; 234 212 235 if (!videoElement()->inActiveDocument()) { 213 236 mediaPlayer->setVisible(false); -
trunk/WebCore/rendering/RenderVideo.h
r64884 r64997 41 41 virtual ~RenderVideo(); 42 42 43 void videoSizeChanged();44 43 IntRect videoBox() const; 45 44 … … 58 57 59 58 virtual void intrinsicSizeChanged(); 59 IntSize calculateIntrinsicSize(); 60 void updateIntrinsicSize(); 61 60 62 virtual void imageChanged(WrappedImagePtr, const IntRect*); 61 63 … … 72 74 virtual int calcReplacedHeight() const; 73 75 virtual int minimumReplacedHeight() const; 74 76 75 77 int calcAspectRatioWidth() const; 76 78 int calcAspectRatioHeight() const;
Note: See TracChangeset
for help on using the changeset viewer.