haikuwebkit/LayoutTests/media/video-object-fit-change.html

51 lines
1.4 KiB
HTML
Raw Permalink Normal View History

Implement object-fit CSS property https://bugs.webkit.org/show_bug.cgi?id=52040 Source/WebCore: Reviewed by Antti Koivisto, Sam Weinig. Merge object-fit patch from Blink r156535, which started as a patch by me. Since then, the spec has gone to CR. This patch is an implementation of object-fit as described in http://www.w3.org/TR/2012/CR-css3-images-20120417/#object-fit Object-fit is used to maintain the aspect ratio of replaced content within its content box. All object-fit values but the initial one ('fill') will always ensure that the aspect ratio is retained, in different ways (fit inside the content box, cover the content box, or use intrinsic size). Painting is always clipped against the content box, regardless of the 'overflow' property. Tests: fast/css/object-fit/object-fit-canvas.html fast/css/object-fit/object-fit-embed.html fast/css/object-fit/object-fit-grow-landscape.html fast/css/object-fit/object-fit-grow-portrait.html fast/css/object-fit/object-fit-img-svg.html fast/css/object-fit/object-fit-img-svg2.html fast/css/object-fit/object-fit-img.html fast/css/object-fit/object-fit-input-image.html fast/css/object-fit/object-fit-object.html fast/css/object-fit/object-fit-shrink.html fast/css/object-fit/object-fit-video-poster.html fast/css/parsing-object-fit.html http/tests/css/object-fit-delayed-img-svg.html media/video-object-fit-change.html media/video-object-fit.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::propertyValue): * css/CSSParser.cpp: (WebCore::isValidKeywordPropertyAndValue): (WebCore::isKeywordPropertyID): (WebCore::CSSParser::parseValue): * css/CSSPrimitiveValueMappings.h: (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): (WebCore::CSSPrimitiveValue::operator EObjectFit): * css/CSSProperty.cpp: (WebCore::CSSProperty::isInheritedProperty): * css/CSSPropertyNames.in: * css/CSSValueKeywords.in: * css/DeprecatedStyleBuilder.cpp: (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): * css/StyleResolver.cpp: (WebCore::StyleResolver::applyProperty): * css/html.css: (video): Set object-fit to 'contain'. This is how VIDEO elements work, apparently. * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer): * loader/cache/CachedImage.h: * platform/graphics/LayoutSize.h: (WebCore::fitLayoutSizeToAspectRatio): New function to grow or shrink in one dimension to fit to the aspect ratio. * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paintReplaced): Apply object-fit and clip if necessary. * rendering/RenderImage.cpp: (WebCore::RenderImage::updateInnerContentRect): (WebCore::RenderImage::imageDimensionsChanged): Update intrinsic size properly, and recalculate the inner content rectangle (the exact area occupied by the replaced content) again if appropriate. (WebCore::RenderImage::paintReplaced): Apply object-fit and clip if necessary. (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect): object-fit may leave parts of the content box empty, in which case it won't be fully obscured. (WebCore::RenderImage::layout): * rendering/RenderImage.h: * rendering/RenderImageResource.cpp: (WebCore::RenderImageResource::intrinsicSize): Need this to differentiate between intrinsic and extrinsic size for SVG images. * rendering/RenderImageResource.h: * rendering/RenderImageResourceStyleImage.h: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::replacedContentRect): Return the rectangle occupied by the replaced content. This will be identical to the content box if object-fit is 'fill', but will typically be something else for other values. * rendering/RenderReplaced.h: * rendering/RenderVideo.cpp: (WebCore::RenderVideo::videoBox): Not much left to do here, with the new RenderReplaced::replacedContentRect() method in place. (WebCore::RenderVideo::paintReplaced): Apply object-fit and clip if necessary. * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::changeRequiresRepaint): * rendering/style/RenderStyle.h: * rendering/style/RenderStyleConstants.h: * rendering/style/StyleRareNonInheritedData.cpp: (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): (WebCore::StyleRareNonInheritedData::operator==): * rendering/style/StyleRareNonInheritedData.h: LayoutTests: Reviewed by Antti Koivisto, Sam Weinig. Tests for object-fit. * fast/css/object-fit/object-fit-canvas-expected.html: Added. * fast/css/object-fit/object-fit-canvas.html: Added. * fast/css/object-fit/object-fit-embed-expected.html: Added. * fast/css/object-fit/object-fit-embed.html: Added. * fast/css/object-fit/object-fit-grow-landscape-expected.html: Added. * fast/css/object-fit/object-fit-grow-landscape.html: Added. * fast/css/object-fit/object-fit-grow-portrait-expected.html: Added. * fast/css/object-fit/object-fit-grow-portrait.html: Added. * fast/css/object-fit/object-fit-img-expected.html: Added. * fast/css/object-fit/object-fit-img-svg-expected.html: Added. * fast/css/object-fit/object-fit-img-svg.html: Added. * fast/css/object-fit/object-fit-img-svg2-expected.html: Added. * fast/css/object-fit/object-fit-img-svg2.html: Added. * fast/css/object-fit/object-fit-img.html: Added. * fast/css/object-fit/object-fit-input-image-expected.html: Added. * fast/css/object-fit/object-fit-input-image.html: Added. * fast/css/object-fit/object-fit-object-expected.html: Added. * fast/css/object-fit/object-fit-object.html: Added. * fast/css/object-fit/object-fit-shrink-expected.html: Added. * fast/css/object-fit/object-fit-shrink.html: Added. * fast/css/object-fit/object-fit-video-poster-expected.html: Added. * fast/css/object-fit/object-fit-video-poster.html: Added. * fast/css/parsing-object-fit-expected.txt: Added. * fast/css/parsing-object-fit.html: Added. * fast/css/resources/circle.svg: Added. * fast/css/resources/circle2.svg: Added. * fast/css/resources/circles-landscape-small.png: Added. * fast/css/resources/circles-landscape.png: Added. * fast/css/resources/circles-portrait-small.png: Added. * fast/css/resources/circles-portrait.png: Added. * http/tests/css/object-fit-delayed-img-svg-expected.html: Added. * http/tests/css/object-fit-delayed-img-svg.html: Added. * media/video-object-fit-change-expected.html: Added. * media/video-object-fit-change.html: Added. * media/video-object-fit-expected.html: Added. * media/video-object-fit.html: Added. * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/138486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-30 00:23:23 +00:00
<!DOCTYPE html>
<html>
<head>
<title>changing object-fit values on video elements</title>
<style>
video {
width: 120px;
height: 120px;
border: 1px solid blue;
background-color: gray;
margin: 10px;
}
</style>
<script src="../media/media-file.js"></script>
<script>
if (window.testRunner)
testRunner.waitUntilDone();
function init()
{
Video with object-fit: cover can spill outside the box https://bugs.webkit.org/show_bug.cgi?id=52103 Source/WebCore: Reviewed by Dean Jackson. object-fit on renderers which use accelerated compositing needs special treatment. For directly composited images, and video, GraphicsLayer needs to know both the size of the content layer, and also a rectangle at which this should be clipped (because, for the first time, that content layer can be larger than the renderer's content box). AVFoundation would always aspect-ratio fit video by default, so plumb through MediaPlayer a way to override that when object-fit requires it. Added a LAYER_TREE_INCLUDES_CONTENT_LAYERS enum to the layerTreeAsText() flags so we can dump content layers for testing. Tests: compositing/images/direct-image-object-fit.html compositing/reflections/direct-image-object-fit-reflected.html compositing/video/video-object-fit.html * page/Frame.h: New LayerTreeFlagsIncludeContentLayers flag. * platform/graphics/GraphicsLayer.h: New flag. * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::shouldMaintainAspectRatio): (WebCore::MediaPlayer::setShouldMaintainAspectRatio): * platform/graphics/MediaPlayer.h: * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::shouldMaintainAspectRatio): (WebCore::MediaPlayerPrivateInterface::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): (WebCore::MediaPlayerPrivateAVFoundation::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::MediaPlayerPrivateAVFoundationCF::updateVideoLayerGravity): (WebCore::AVFWrapper::platformLayer): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): * platform/graphics/ca/GraphicsLayerCA.cpp: We need a new m_contentsClippingLayer to clip the contents layer, which only gets created when necessary. It has to be cloned for reflections. (WebCore::GraphicsLayerCA::willBeDestroyed): (WebCore::GraphicsLayerCA::setContentsRect): (WebCore::GraphicsLayerCA::setContentsClippingRect): (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers): (WebCore::GraphicsLayerCA::updateSublayerList): (WebCore::GraphicsLayerCA::updateContentsImage): (WebCore::GraphicsLayerCA::updateContentsMediaLayer): (WebCore::GraphicsLayerCA::updateContentsCanvasLayer): (WebCore::GraphicsLayerCA::updateContentsColorLayer): (WebCore::GraphicsLayerCA::updateContentsRects): (WebCore::GraphicsLayerCA::dumpAdditionalProperties): (WebCore::GraphicsLayerCA::ensureCloneLayers): (WebCore::GraphicsLayerCA::removeCloneLayers): (WebCore::GraphicsLayerCA::fetchCloneLayers): * platform/graphics/ca/GraphicsLayerCA.h: * rendering/RenderLayerBacking.cpp: Need to push both the contentsRect and the contentsClippingRect down to the GraphicsLayers. Most of the time they are the same, unless object-fit makes them different. (WebCore::RenderLayerBacking::resetContentsRect): (WebCore::RenderLayerBacking::positionOverflowControlsLayers): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundColor): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundImage): (WebCore::RenderLayerBacking::updateImageContents): (WebCore::RenderLayerBacking::contentsBox): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::layerTreeAsText): * rendering/RenderVideo.cpp: (WebCore::RenderVideo::updatePlayer): * testing/Internals.cpp: (WebCore::Internals::layerTreeAsText): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Reviewed by Dean Jackson. Test cases for directly composited image with object-fit, the same with reflections, and one with video. Tests dump content GraphicsLayers, so have platform-specific results. * compositing/images/direct-image-object-fit-expected.txt: Added. * compositing/images/direct-image-object-fit.html: Added. * compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * compositing/reflections/direct-image-object-fit-reflected.html: Added. * compositing/video/video-object-fit-expected.txt: Added. * compositing/video/video-object-fit.html: Added. * media/video-object-fit-change.html: Fixed * platform/mac/TestExpectations: Unskip two tests. * platform/mac/compositing/images/direct-image-object-fit-expected.txt: Added. * platform/mac/compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * platform/mac/compositing/video/video-object-fit-expected.txt: Added. Canonical link: https://commits.webkit.org/138547@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154921 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-31 00:14:41 +00:00
setSrcByTagName("video", findMediaFile("video", "content/test"));
Implement object-fit CSS property https://bugs.webkit.org/show_bug.cgi?id=52040 Source/WebCore: Reviewed by Antti Koivisto, Sam Weinig. Merge object-fit patch from Blink r156535, which started as a patch by me. Since then, the spec has gone to CR. This patch is an implementation of object-fit as described in http://www.w3.org/TR/2012/CR-css3-images-20120417/#object-fit Object-fit is used to maintain the aspect ratio of replaced content within its content box. All object-fit values but the initial one ('fill') will always ensure that the aspect ratio is retained, in different ways (fit inside the content box, cover the content box, or use intrinsic size). Painting is always clipped against the content box, regardless of the 'overflow' property. Tests: fast/css/object-fit/object-fit-canvas.html fast/css/object-fit/object-fit-embed.html fast/css/object-fit/object-fit-grow-landscape.html fast/css/object-fit/object-fit-grow-portrait.html fast/css/object-fit/object-fit-img-svg.html fast/css/object-fit/object-fit-img-svg2.html fast/css/object-fit/object-fit-img.html fast/css/object-fit/object-fit-input-image.html fast/css/object-fit/object-fit-object.html fast/css/object-fit/object-fit-shrink.html fast/css/object-fit/object-fit-video-poster.html fast/css/parsing-object-fit.html http/tests/css/object-fit-delayed-img-svg.html media/video-object-fit-change.html media/video-object-fit.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::propertyValue): * css/CSSParser.cpp: (WebCore::isValidKeywordPropertyAndValue): (WebCore::isKeywordPropertyID): (WebCore::CSSParser::parseValue): * css/CSSPrimitiveValueMappings.h: (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): (WebCore::CSSPrimitiveValue::operator EObjectFit): * css/CSSProperty.cpp: (WebCore::CSSProperty::isInheritedProperty): * css/CSSPropertyNames.in: * css/CSSValueKeywords.in: * css/DeprecatedStyleBuilder.cpp: (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): * css/StyleResolver.cpp: (WebCore::StyleResolver::applyProperty): * css/html.css: (video): Set object-fit to 'contain'. This is how VIDEO elements work, apparently. * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer): * loader/cache/CachedImage.h: * platform/graphics/LayoutSize.h: (WebCore::fitLayoutSizeToAspectRatio): New function to grow or shrink in one dimension to fit to the aspect ratio. * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paintReplaced): Apply object-fit and clip if necessary. * rendering/RenderImage.cpp: (WebCore::RenderImage::updateInnerContentRect): (WebCore::RenderImage::imageDimensionsChanged): Update intrinsic size properly, and recalculate the inner content rectangle (the exact area occupied by the replaced content) again if appropriate. (WebCore::RenderImage::paintReplaced): Apply object-fit and clip if necessary. (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect): object-fit may leave parts of the content box empty, in which case it won't be fully obscured. (WebCore::RenderImage::layout): * rendering/RenderImage.h: * rendering/RenderImageResource.cpp: (WebCore::RenderImageResource::intrinsicSize): Need this to differentiate between intrinsic and extrinsic size for SVG images. * rendering/RenderImageResource.h: * rendering/RenderImageResourceStyleImage.h: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::replacedContentRect): Return the rectangle occupied by the replaced content. This will be identical to the content box if object-fit is 'fill', but will typically be something else for other values. * rendering/RenderReplaced.h: * rendering/RenderVideo.cpp: (WebCore::RenderVideo::videoBox): Not much left to do here, with the new RenderReplaced::replacedContentRect() method in place. (WebCore::RenderVideo::paintReplaced): Apply object-fit and clip if necessary. * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::changeRequiresRepaint): * rendering/style/RenderStyle.h: * rendering/style/RenderStyleConstants.h: * rendering/style/StyleRareNonInheritedData.cpp: (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): (WebCore::StyleRareNonInheritedData::operator==): * rendering/style/StyleRareNonInheritedData.h: LayoutTests: Reviewed by Antti Koivisto, Sam Weinig. Tests for object-fit. * fast/css/object-fit/object-fit-canvas-expected.html: Added. * fast/css/object-fit/object-fit-canvas.html: Added. * fast/css/object-fit/object-fit-embed-expected.html: Added. * fast/css/object-fit/object-fit-embed.html: Added. * fast/css/object-fit/object-fit-grow-landscape-expected.html: Added. * fast/css/object-fit/object-fit-grow-landscape.html: Added. * fast/css/object-fit/object-fit-grow-portrait-expected.html: Added. * fast/css/object-fit/object-fit-grow-portrait.html: Added. * fast/css/object-fit/object-fit-img-expected.html: Added. * fast/css/object-fit/object-fit-img-svg-expected.html: Added. * fast/css/object-fit/object-fit-img-svg.html: Added. * fast/css/object-fit/object-fit-img-svg2-expected.html: Added. * fast/css/object-fit/object-fit-img-svg2.html: Added. * fast/css/object-fit/object-fit-img.html: Added. * fast/css/object-fit/object-fit-input-image-expected.html: Added. * fast/css/object-fit/object-fit-input-image.html: Added. * fast/css/object-fit/object-fit-object-expected.html: Added. * fast/css/object-fit/object-fit-object.html: Added. * fast/css/object-fit/object-fit-shrink-expected.html: Added. * fast/css/object-fit/object-fit-shrink.html: Added. * fast/css/object-fit/object-fit-video-poster-expected.html: Added. * fast/css/object-fit/object-fit-video-poster.html: Added. * fast/css/parsing-object-fit-expected.txt: Added. * fast/css/parsing-object-fit.html: Added. * fast/css/resources/circle.svg: Added. * fast/css/resources/circle2.svg: Added. * fast/css/resources/circles-landscape-small.png: Added. * fast/css/resources/circles-landscape.png: Added. * fast/css/resources/circles-portrait-small.png: Added. * fast/css/resources/circles-portrait.png: Added. * http/tests/css/object-fit-delayed-img-svg-expected.html: Added. * http/tests/css/object-fit-delayed-img-svg.html: Added. * media/video-object-fit-change-expected.html: Added. * media/video-object-fit-change.html: Added. * media/video-object-fit-expected.html: Added. * media/video-object-fit.html: Added. * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/138486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-30 00:23:23 +00:00
var totalCount = document.getElementsByTagName('video').length;
var count = totalCount;
document.addEventListener("canplaythrough", function () {
if (!--count)
Video with object-fit: cover can spill outside the box https://bugs.webkit.org/show_bug.cgi?id=52103 Source/WebCore: Reviewed by Dean Jackson. object-fit on renderers which use accelerated compositing needs special treatment. For directly composited images, and video, GraphicsLayer needs to know both the size of the content layer, and also a rectangle at which this should be clipped (because, for the first time, that content layer can be larger than the renderer's content box). AVFoundation would always aspect-ratio fit video by default, so plumb through MediaPlayer a way to override that when object-fit requires it. Added a LAYER_TREE_INCLUDES_CONTENT_LAYERS enum to the layerTreeAsText() flags so we can dump content layers for testing. Tests: compositing/images/direct-image-object-fit.html compositing/reflections/direct-image-object-fit-reflected.html compositing/video/video-object-fit.html * page/Frame.h: New LayerTreeFlagsIncludeContentLayers flag. * platform/graphics/GraphicsLayer.h: New flag. * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::shouldMaintainAspectRatio): (WebCore::MediaPlayer::setShouldMaintainAspectRatio): * platform/graphics/MediaPlayer.h: * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::shouldMaintainAspectRatio): (WebCore::MediaPlayerPrivateInterface::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): (WebCore::MediaPlayerPrivateAVFoundation::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::MediaPlayerPrivateAVFoundationCF::updateVideoLayerGravity): (WebCore::AVFWrapper::platformLayer): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): * platform/graphics/ca/GraphicsLayerCA.cpp: We need a new m_contentsClippingLayer to clip the contents layer, which only gets created when necessary. It has to be cloned for reflections. (WebCore::GraphicsLayerCA::willBeDestroyed): (WebCore::GraphicsLayerCA::setContentsRect): (WebCore::GraphicsLayerCA::setContentsClippingRect): (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers): (WebCore::GraphicsLayerCA::updateSublayerList): (WebCore::GraphicsLayerCA::updateContentsImage): (WebCore::GraphicsLayerCA::updateContentsMediaLayer): (WebCore::GraphicsLayerCA::updateContentsCanvasLayer): (WebCore::GraphicsLayerCA::updateContentsColorLayer): (WebCore::GraphicsLayerCA::updateContentsRects): (WebCore::GraphicsLayerCA::dumpAdditionalProperties): (WebCore::GraphicsLayerCA::ensureCloneLayers): (WebCore::GraphicsLayerCA::removeCloneLayers): (WebCore::GraphicsLayerCA::fetchCloneLayers): * platform/graphics/ca/GraphicsLayerCA.h: * rendering/RenderLayerBacking.cpp: Need to push both the contentsRect and the contentsClippingRect down to the GraphicsLayers. Most of the time they are the same, unless object-fit makes them different. (WebCore::RenderLayerBacking::resetContentsRect): (WebCore::RenderLayerBacking::positionOverflowControlsLayers): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundColor): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundImage): (WebCore::RenderLayerBacking::updateImageContents): (WebCore::RenderLayerBacking::contentsBox): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::layerTreeAsText): * rendering/RenderVideo.cpp: (WebCore::RenderVideo::updatePlayer): * testing/Internals.cpp: (WebCore::Internals::layerTreeAsText): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Reviewed by Dean Jackson. Test cases for directly composited image with object-fit, the same with reflections, and one with video. Tests dump content GraphicsLayers, so have platform-specific results. * compositing/images/direct-image-object-fit-expected.txt: Added. * compositing/images/direct-image-object-fit.html: Added. * compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * compositing/reflections/direct-image-object-fit-reflected.html: Added. * compositing/video/video-object-fit-expected.txt: Added. * compositing/video/video-object-fit.html: Added. * media/video-object-fit-change.html: Fixed * platform/mac/TestExpectations: Unskip two tests. * platform/mac/compositing/images/direct-image-object-fit-expected.txt: Added. * platform/mac/compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * platform/mac/compositing/video/video-object-fit-expected.txt: Added. Canonical link: https://commits.webkit.org/138547@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154921 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-31 00:14:41 +00:00
setTimeout(function() { changeStyle(); }, 250);
Implement object-fit CSS property https://bugs.webkit.org/show_bug.cgi?id=52040 Source/WebCore: Reviewed by Antti Koivisto, Sam Weinig. Merge object-fit patch from Blink r156535, which started as a patch by me. Since then, the spec has gone to CR. This patch is an implementation of object-fit as described in http://www.w3.org/TR/2012/CR-css3-images-20120417/#object-fit Object-fit is used to maintain the aspect ratio of replaced content within its content box. All object-fit values but the initial one ('fill') will always ensure that the aspect ratio is retained, in different ways (fit inside the content box, cover the content box, or use intrinsic size). Painting is always clipped against the content box, regardless of the 'overflow' property. Tests: fast/css/object-fit/object-fit-canvas.html fast/css/object-fit/object-fit-embed.html fast/css/object-fit/object-fit-grow-landscape.html fast/css/object-fit/object-fit-grow-portrait.html fast/css/object-fit/object-fit-img-svg.html fast/css/object-fit/object-fit-img-svg2.html fast/css/object-fit/object-fit-img.html fast/css/object-fit/object-fit-input-image.html fast/css/object-fit/object-fit-object.html fast/css/object-fit/object-fit-shrink.html fast/css/object-fit/object-fit-video-poster.html fast/css/parsing-object-fit.html http/tests/css/object-fit-delayed-img-svg.html media/video-object-fit-change.html media/video-object-fit.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::propertyValue): * css/CSSParser.cpp: (WebCore::isValidKeywordPropertyAndValue): (WebCore::isKeywordPropertyID): (WebCore::CSSParser::parseValue): * css/CSSPrimitiveValueMappings.h: (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): (WebCore::CSSPrimitiveValue::operator EObjectFit): * css/CSSProperty.cpp: (WebCore::CSSProperty::isInheritedProperty): * css/CSSPropertyNames.in: * css/CSSValueKeywords.in: * css/DeprecatedStyleBuilder.cpp: (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): * css/StyleResolver.cpp: (WebCore::StyleResolver::applyProperty): * css/html.css: (video): Set object-fit to 'contain'. This is how VIDEO elements work, apparently. * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer): * loader/cache/CachedImage.h: * platform/graphics/LayoutSize.h: (WebCore::fitLayoutSizeToAspectRatio): New function to grow or shrink in one dimension to fit to the aspect ratio. * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paintReplaced): Apply object-fit and clip if necessary. * rendering/RenderImage.cpp: (WebCore::RenderImage::updateInnerContentRect): (WebCore::RenderImage::imageDimensionsChanged): Update intrinsic size properly, and recalculate the inner content rectangle (the exact area occupied by the replaced content) again if appropriate. (WebCore::RenderImage::paintReplaced): Apply object-fit and clip if necessary. (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect): object-fit may leave parts of the content box empty, in which case it won't be fully obscured. (WebCore::RenderImage::layout): * rendering/RenderImage.h: * rendering/RenderImageResource.cpp: (WebCore::RenderImageResource::intrinsicSize): Need this to differentiate between intrinsic and extrinsic size for SVG images. * rendering/RenderImageResource.h: * rendering/RenderImageResourceStyleImage.h: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::replacedContentRect): Return the rectangle occupied by the replaced content. This will be identical to the content box if object-fit is 'fill', but will typically be something else for other values. * rendering/RenderReplaced.h: * rendering/RenderVideo.cpp: (WebCore::RenderVideo::videoBox): Not much left to do here, with the new RenderReplaced::replacedContentRect() method in place. (WebCore::RenderVideo::paintReplaced): Apply object-fit and clip if necessary. * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::changeRequiresRepaint): * rendering/style/RenderStyle.h: * rendering/style/RenderStyleConstants.h: * rendering/style/StyleRareNonInheritedData.cpp: (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): (WebCore::StyleRareNonInheritedData::operator==): * rendering/style/StyleRareNonInheritedData.h: LayoutTests: Reviewed by Antti Koivisto, Sam Weinig. Tests for object-fit. * fast/css/object-fit/object-fit-canvas-expected.html: Added. * fast/css/object-fit/object-fit-canvas.html: Added. * fast/css/object-fit/object-fit-embed-expected.html: Added. * fast/css/object-fit/object-fit-embed.html: Added. * fast/css/object-fit/object-fit-grow-landscape-expected.html: Added. * fast/css/object-fit/object-fit-grow-landscape.html: Added. * fast/css/object-fit/object-fit-grow-portrait-expected.html: Added. * fast/css/object-fit/object-fit-grow-portrait.html: Added. * fast/css/object-fit/object-fit-img-expected.html: Added. * fast/css/object-fit/object-fit-img-svg-expected.html: Added. * fast/css/object-fit/object-fit-img-svg.html: Added. * fast/css/object-fit/object-fit-img-svg2-expected.html: Added. * fast/css/object-fit/object-fit-img-svg2.html: Added. * fast/css/object-fit/object-fit-img.html: Added. * fast/css/object-fit/object-fit-input-image-expected.html: Added. * fast/css/object-fit/object-fit-input-image.html: Added. * fast/css/object-fit/object-fit-object-expected.html: Added. * fast/css/object-fit/object-fit-object.html: Added. * fast/css/object-fit/object-fit-shrink-expected.html: Added. * fast/css/object-fit/object-fit-shrink.html: Added. * fast/css/object-fit/object-fit-video-poster-expected.html: Added. * fast/css/object-fit/object-fit-video-poster.html: Added. * fast/css/parsing-object-fit-expected.txt: Added. * fast/css/parsing-object-fit.html: Added. * fast/css/resources/circle.svg: Added. * fast/css/resources/circle2.svg: Added. * fast/css/resources/circles-landscape-small.png: Added. * fast/css/resources/circles-landscape.png: Added. * fast/css/resources/circles-portrait-small.png: Added. * fast/css/resources/circles-portrait.png: Added. * http/tests/css/object-fit-delayed-img-svg-expected.html: Added. * http/tests/css/object-fit-delayed-img-svg.html: Added. * media/video-object-fit-change-expected.html: Added. * media/video-object-fit-change.html: Added. * media/video-object-fit-expected.html: Added. * media/video-object-fit.html: Added. * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/138486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-30 00:23:23 +00:00
}, true);
}
function changeStyle()
{
video1.style.objectFit = 'contain';
video2.style.objectFit = 'cover';
video3.style.objectFit = 'fill';
video4.style.objectFit = 'scale-down';
Video with object-fit: cover can spill outside the box https://bugs.webkit.org/show_bug.cgi?id=52103 Source/WebCore: Reviewed by Dean Jackson. object-fit on renderers which use accelerated compositing needs special treatment. For directly composited images, and video, GraphicsLayer needs to know both the size of the content layer, and also a rectangle at which this should be clipped (because, for the first time, that content layer can be larger than the renderer's content box). AVFoundation would always aspect-ratio fit video by default, so plumb through MediaPlayer a way to override that when object-fit requires it. Added a LAYER_TREE_INCLUDES_CONTENT_LAYERS enum to the layerTreeAsText() flags so we can dump content layers for testing. Tests: compositing/images/direct-image-object-fit.html compositing/reflections/direct-image-object-fit-reflected.html compositing/video/video-object-fit.html * page/Frame.h: New LayerTreeFlagsIncludeContentLayers flag. * platform/graphics/GraphicsLayer.h: New flag. * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::shouldMaintainAspectRatio): (WebCore::MediaPlayer::setShouldMaintainAspectRatio): * platform/graphics/MediaPlayer.h: * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::shouldMaintainAspectRatio): (WebCore::MediaPlayerPrivateInterface::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): (WebCore::MediaPlayerPrivateAVFoundation::setShouldMaintainAspectRatio): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp: (WebCore::MediaPlayerPrivateAVFoundationCF::updateVideoLayerGravity): (WebCore::AVFWrapper::platformLayer): * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoLayerGravity): * platform/graphics/ca/GraphicsLayerCA.cpp: We need a new m_contentsClippingLayer to clip the contents layer, which only gets created when necessary. It has to be cloned for reflections. (WebCore::GraphicsLayerCA::willBeDestroyed): (WebCore::GraphicsLayerCA::setContentsRect): (WebCore::GraphicsLayerCA::setContentsClippingRect): (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers): (WebCore::GraphicsLayerCA::updateSublayerList): (WebCore::GraphicsLayerCA::updateContentsImage): (WebCore::GraphicsLayerCA::updateContentsMediaLayer): (WebCore::GraphicsLayerCA::updateContentsCanvasLayer): (WebCore::GraphicsLayerCA::updateContentsColorLayer): (WebCore::GraphicsLayerCA::updateContentsRects): (WebCore::GraphicsLayerCA::dumpAdditionalProperties): (WebCore::GraphicsLayerCA::ensureCloneLayers): (WebCore::GraphicsLayerCA::removeCloneLayers): (WebCore::GraphicsLayerCA::fetchCloneLayers): * platform/graphics/ca/GraphicsLayerCA.h: * rendering/RenderLayerBacking.cpp: Need to push both the contentsRect and the contentsClippingRect down to the GraphicsLayers. Most of the time they are the same, unless object-fit makes them different. (WebCore::RenderLayerBacking::resetContentsRect): (WebCore::RenderLayerBacking::positionOverflowControlsLayers): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundColor): (WebCore::RenderLayerBacking::updateDirectlyCompositedBackgroundImage): (WebCore::RenderLayerBacking::updateImageContents): (WebCore::RenderLayerBacking::contentsBox): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::layerTreeAsText): * rendering/RenderVideo.cpp: (WebCore::RenderVideo::updatePlayer): * testing/Internals.cpp: (WebCore::Internals::layerTreeAsText): * testing/Internals.h: * testing/Internals.idl: LayoutTests: Reviewed by Dean Jackson. Test cases for directly composited image with object-fit, the same with reflections, and one with video. Tests dump content GraphicsLayers, so have platform-specific results. * compositing/images/direct-image-object-fit-expected.txt: Added. * compositing/images/direct-image-object-fit.html: Added. * compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * compositing/reflections/direct-image-object-fit-reflected.html: Added. * compositing/video/video-object-fit-expected.txt: Added. * compositing/video/video-object-fit.html: Added. * media/video-object-fit-change.html: Fixed * platform/mac/TestExpectations: Unskip two tests. * platform/mac/compositing/images/direct-image-object-fit-expected.txt: Added. * platform/mac/compositing/reflections/direct-image-object-fit-reflected-expected.txt: Added. * platform/mac/compositing/video/video-object-fit-expected.txt: Added. Canonical link: https://commits.webkit.org/138547@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154921 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-31 00:14:41 +00:00
if (window.testRunner)
setTimeout(function() { testRunner.notifyDone(); }, 250);
Implement object-fit CSS property https://bugs.webkit.org/show_bug.cgi?id=52040 Source/WebCore: Reviewed by Antti Koivisto, Sam Weinig. Merge object-fit patch from Blink r156535, which started as a patch by me. Since then, the spec has gone to CR. This patch is an implementation of object-fit as described in http://www.w3.org/TR/2012/CR-css3-images-20120417/#object-fit Object-fit is used to maintain the aspect ratio of replaced content within its content box. All object-fit values but the initial one ('fill') will always ensure that the aspect ratio is retained, in different ways (fit inside the content box, cover the content box, or use intrinsic size). Painting is always clipped against the content box, regardless of the 'overflow' property. Tests: fast/css/object-fit/object-fit-canvas.html fast/css/object-fit/object-fit-embed.html fast/css/object-fit/object-fit-grow-landscape.html fast/css/object-fit/object-fit-grow-portrait.html fast/css/object-fit/object-fit-img-svg.html fast/css/object-fit/object-fit-img-svg2.html fast/css/object-fit/object-fit-img.html fast/css/object-fit/object-fit-input-image.html fast/css/object-fit/object-fit-object.html fast/css/object-fit/object-fit-shrink.html fast/css/object-fit/object-fit-video-poster.html fast/css/parsing-object-fit.html http/tests/css/object-fit-delayed-img-svg.html media/video-object-fit-change.html media/video-object-fit.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::ComputedStyleExtractor::propertyValue): * css/CSSParser.cpp: (WebCore::isValidKeywordPropertyAndValue): (WebCore::isKeywordPropertyID): (WebCore::CSSParser::parseValue): * css/CSSPrimitiveValueMappings.h: (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): (WebCore::CSSPrimitiveValue::operator EObjectFit): * css/CSSProperty.cpp: (WebCore::CSSProperty::isInheritedProperty): * css/CSSPropertyNames.in: * css/CSSValueKeywords.in: * css/DeprecatedStyleBuilder.cpp: (WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder): * css/StyleResolver.cpp: (WebCore::StyleResolver::applyProperty): * css/html.css: (video): Set object-fit to 'contain'. This is how VIDEO elements work, apparently. * loader/cache/CachedImage.cpp: (WebCore::CachedImage::imageSizeForRenderer): * loader/cache/CachedImage.h: * platform/graphics/LayoutSize.h: (WebCore::fitLayoutSizeToAspectRatio): New function to grow or shrink in one dimension to fit to the aspect ratio. * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paintReplaced): Apply object-fit and clip if necessary. * rendering/RenderImage.cpp: (WebCore::RenderImage::updateInnerContentRect): (WebCore::RenderImage::imageDimensionsChanged): Update intrinsic size properly, and recalculate the inner content rectangle (the exact area occupied by the replaced content) again if appropriate. (WebCore::RenderImage::paintReplaced): Apply object-fit and clip if necessary. (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect): object-fit may leave parts of the content box empty, in which case it won't be fully obscured. (WebCore::RenderImage::layout): * rendering/RenderImage.h: * rendering/RenderImageResource.cpp: (WebCore::RenderImageResource::intrinsicSize): Need this to differentiate between intrinsic and extrinsic size for SVG images. * rendering/RenderImageResource.h: * rendering/RenderImageResourceStyleImage.h: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::replacedContentRect): Return the rectangle occupied by the replaced content. This will be identical to the content box if object-fit is 'fill', but will typically be something else for other values. * rendering/RenderReplaced.h: * rendering/RenderVideo.cpp: (WebCore::RenderVideo::videoBox): Not much left to do here, with the new RenderReplaced::replacedContentRect() method in place. (WebCore::RenderVideo::paintReplaced): Apply object-fit and clip if necessary. * rendering/style/RenderStyle.cpp: (WebCore::RenderStyle::changeRequiresRepaint): * rendering/style/RenderStyle.h: * rendering/style/RenderStyleConstants.h: * rendering/style/StyleRareNonInheritedData.cpp: (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): (WebCore::StyleRareNonInheritedData::operator==): * rendering/style/StyleRareNonInheritedData.h: LayoutTests: Reviewed by Antti Koivisto, Sam Weinig. Tests for object-fit. * fast/css/object-fit/object-fit-canvas-expected.html: Added. * fast/css/object-fit/object-fit-canvas.html: Added. * fast/css/object-fit/object-fit-embed-expected.html: Added. * fast/css/object-fit/object-fit-embed.html: Added. * fast/css/object-fit/object-fit-grow-landscape-expected.html: Added. * fast/css/object-fit/object-fit-grow-landscape.html: Added. * fast/css/object-fit/object-fit-grow-portrait-expected.html: Added. * fast/css/object-fit/object-fit-grow-portrait.html: Added. * fast/css/object-fit/object-fit-img-expected.html: Added. * fast/css/object-fit/object-fit-img-svg-expected.html: Added. * fast/css/object-fit/object-fit-img-svg.html: Added. * fast/css/object-fit/object-fit-img-svg2-expected.html: Added. * fast/css/object-fit/object-fit-img-svg2.html: Added. * fast/css/object-fit/object-fit-img.html: Added. * fast/css/object-fit/object-fit-input-image-expected.html: Added. * fast/css/object-fit/object-fit-input-image.html: Added. * fast/css/object-fit/object-fit-object-expected.html: Added. * fast/css/object-fit/object-fit-object.html: Added. * fast/css/object-fit/object-fit-shrink-expected.html: Added. * fast/css/object-fit/object-fit-shrink.html: Added. * fast/css/object-fit/object-fit-video-poster-expected.html: Added. * fast/css/object-fit/object-fit-video-poster.html: Added. * fast/css/parsing-object-fit-expected.txt: Added. * fast/css/parsing-object-fit.html: Added. * fast/css/resources/circle.svg: Added. * fast/css/resources/circle2.svg: Added. * fast/css/resources/circles-landscape-small.png: Added. * fast/css/resources/circles-landscape.png: Added. * fast/css/resources/circles-portrait-small.png: Added. * fast/css/resources/circles-portrait.png: Added. * http/tests/css/object-fit-delayed-img-svg-expected.html: Added. * http/tests/css/object-fit-delayed-img-svg.html: Added. * media/video-object-fit-change-expected.html: Added. * media/video-object-fit-change.html: Added. * media/video-object-fit-expected.html: Added. * media/video-object-fit.html: Added. * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/138486@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154858 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-08-30 00:23:23 +00:00
}
</script>
</head>
<body onload="init();">
<video id="video1" style="object-fit:fill;"></video>
<video id="video2" style="object-fit:contain;"></video>
<video id="video3" style="object-fit:cover;"></video>
<video id="video4" style="object-fit:none;"></video>
</body>
</html>