haikuwebkit/LayoutTests/fast/hidpi/image-srcset-png.html

60 lines
2.4 KiB
HTML
Raw Permalink Normal View History

Use srcset's pixel density to determine intrinsic size https://bugs.webkit.org/show_bug.cgi?id=123832 Patch by Yoav Weiss <yoav@yoav.ws> on 2014-02-04 Reviewed by Dean Jackson. The patch is a port of a similar Blink patch: https://codereview.chromium.org/25105004 According to the spec "When an img element has a current pixel density that is not 1.0, the element's image data must be treated as if its resolution, in device pixels per CSS pixels, was the current pixel density." Source/WebCore: I've added that support using the following changes: - bestFitSourceForImageAttributes now returns the image candidate to HTMLImageElement. - HTMLImageElement passes the devicePixelRatio data to RenderImage, which stores it. - Bitmap images are scaled using the devicePixelRatio at RenderImageResource's intrinsicSize() and imageSize(). - SVG images are scaled using the devicePixelRatio at RenderReplaced::computeAspectRatioInformationForRenderBox. - Canvas support added at CanvasRenderingContext2D::size. Tests: fast/hidpi/image-srcset-intrinsic-size.html fast/hidpi/image-srcset-png-canvas.html fast/hidpi/image-srcset-png.html fast/hidpi/image-srcset-relative-svg-canvas-2x.html fast/hidpi/image-srcset-relative-svg.html fast/hidpi/image-srcset-space-left-nomodifier.html fast/hidpi/image-srcset-svg-canvas-2x.html fast/hidpi/image-srcset-svg-canvas.html fast/hidpi/image-srcset-svg.html fast/hidpi/image-srcset-svg2.html * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::HTMLImageElement): (WebCore::HTMLImageElement::parseAttribute): (WebCore::HTMLImageElement::createRenderer): * html/HTMLImageElement.h: * html/canvas/CanvasRenderingContext2D.cpp: (WebCore::size): (WebCore::CanvasRenderingContext2D::drawImage): * html/parser/HTMLParserIdioms.cpp: (WebCore::compareByScaleFactor): (WebCore::parseImagesWithScaleFromSrcsetAttribute): (WebCore::bestFitSourceForImageAttributes): * html/parser/HTMLParserIdioms.h: (WebCore::ImageWithScale::ImageWithScale): (WebCore::ImageWithScale::imageURL): (WebCore::ImageWithScale::scaleFactor): * html/parser/HTMLPreloadScanner.cpp: (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): * rendering/RenderImage.cpp: (WebCore::RenderImage::RenderImage): * rendering/RenderImage.h: (WebCore::RenderImage::setImageDevicePixelRatio): (WebCore::RenderImage::imageDevicePixelRatio): * rendering/RenderImageResource.cpp: (WebCore::RenderImageResource::imageSize): (WebCore::RenderImageResource::intrinsicSize): (WebCore::RenderImageResource::getImageSize): * rendering/RenderImageResource.h: * rendering/RenderReplaced.cpp: (WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox): LayoutTests: Layout test changes include modifications of existing tests to accomodate the new image dimensions, as well as new tests for this specific functionality. * fast/hidpi/image-srcset-change-dynamically-from-js-2x-expected.txt: * fast/hidpi/image-srcset-change-dynamically-from-js-2x.html: * fast/hidpi/image-srcset-data-escaped-srcset-expected.txt: * fast/hidpi/image-srcset-data-escaped-srcset.html: * fast/hidpi/image-srcset-data-src.html: * fast/hidpi/image-srcset-data-srcset.html: * fast/hidpi/image-srcset-fraction.html: * fast/hidpi/image-srcset-intrinsic-size-expected.txt: Added. * fast/hidpi/image-srcset-intrinsic-size.html: Added. * fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.txt: * fast/hidpi/image-srcset-invalid-inputs-correct-src.html: * fast/hidpi/image-srcset-invalid-inputs.html: * fast/hidpi/image-srcset-invalid-inputs-expected.txt: Added. * fast/hidpi/image-srcset-only-src-attribute-expected.txt: Added. * fast/hidpi/image-srcset-only-src-attribute.html: * fast/hidpi/image-srcset-png-canvas-expected.html: Added. * fast/hidpi/image-srcset-png-canvas.html: Added. * fast/hidpi/image-srcset-png-expected.html: Added. * fast/hidpi/image-srcset-png.html: Added. * fast/hidpi/image-srcset-relative-svg-expected.html: Added. * fast/hidpi/image-srcset-relative-svg.html: Added. * fast/hidpi/image-srcset-remove-dynamically-from-js.html: * fast/hidpi/image-srcset-simple-2x-expected.txt: * fast/hidpi/image-srcset-simple-2x.html: * fast/hidpi/image-srcset-space-left-nomodifier-expected.txt: Added. * fast/hidpi/image-srcset-space-left-nomodifier.html: Copied from LayoutTests/fast/hidpi/image-srcset-data-srcset.html. * fast/hidpi/image-srcset-svg-expected.html: Added. * fast/hidpi/image-srcset-svg.html: Added. * fast/hidpi/image-srcset-svg2-expected.html: Added. * fast/hidpi/image-srcset-svg2.html: Added. * fast/hidpi/resources/green-400-px-square.png: Added. * fast/hidpi/resources/relativesrcset.svg: Added. * fast/hidpi/resources/srcset-helper.js: (runTest): * fast/hidpi/resources/srcset.png: Added. * fast/hidpi/resources/srcset.svg: Added. * fast/hidpi/resources/srcset_100px.svg: Added. * fast/hidpi/resources/svg_canvas_helper.js: Added. (drawCanvas): * fast/hidpi/resources/svg_tests.css: Added. (.test): (.test img, .test canvas): (.test .stats): (.expected, .actual): * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.png: Removed. * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.txt: Removed. The following tests were added, but skipped, since they reveal an unrelated SVG on canvas rendering issue: * fast/hidpi/image-srcset-svg-canvas-2x-expected.html: Added. * fast/hidpi/image-srcset-svg-canvas-2x.html: Added. * fast/hidpi/image-srcset-svg-canvas-expected.html: Added. * fast/hidpi/image-srcset-svg-canvas.html: Added. * fast/hidpi/image-srcset-relative-svg-canvas-2x-expected.html: Added. * fast/hidpi/image-srcset-relative-svg-canvas-2x.html: Added. * fast/hidpi/image-srcset-relative-svg-canvas-expected.html: Added. * fast/hidpi/image-srcset-relative-svg-canvas.html: Added. Canonical link: https://commits.webkit.org/146218@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163415 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-02-05 00:09:15 +00:00
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="resources/svg_tests.css">
</head>
<body>
<h2><a href="http://www.w3.org/html/wg/drafts/srcset/w3c-srcset">srcset</a> testcases for SVG</h2>
<div class="test">
<h3>PNG without explicit dimensions - 1x</h3>
<div class="expected">expected<br/>
<img src="resources/srcset.png" width="200" height="100">
</div>
<div class="actual">actual<br/>
<img id="png1" src="resources/srcset.png">
</div>
This test should show a PNG image of size 200x100, and intrinsic/natural size 200x100. The left half of the image should be red and there should be a black circle in the center.<br/>
<code class="stats" id="code5"></code>
<br clear="all"/>
</div>
<div class="test">
<h3>PNG with explicit dimensions - 1x</h3>
<div class="expected">expected<br/>
<img src="resources/srcset.png" width="100" height="50">
</div>
<div class="actual">actual<br/>
<img id="png2" src="resources/srcset.png" width="100" height="50">
</div>
This test should show a PNG image of size 100x50, and intrinsic/natural size 100x50. The left half of the image should be red and there should be a black circle in the center.<br/>
<code class="stats" id="code6"></code>
<br clear="all"/>
</div>
<div class="test">
<h3>PNG without explicit dimensions - 2x</h3>
<div class="expected">expected<br/>
<img src="resources/srcset.png" width="100" height="50">
</div>
<div class="actual">actual<br/>
<img id="png3" src="" srcset="resources/srcset.png 2x">
</div>
This test should show a PNG image of size 100x50, and intrinsic/natural size 100x50. The left half of the image should be red and there should be a black circle in the center.<br/>
<code class="stats" id="code7"></code>
<br clear="all"/>
</div>
<div class="test">
<h3>PNG with explicit dimensions - 4x</h3>
<div class="expected">expected<br/>
<img src="resources/srcset.png" width="100" height="50">
</div>
<div class="actual">actual<br/>
<img id="png4" src="" srcset="resources/srcset.png 4x" width="100" height="50">
</div>
This test should show a PNG image of size 100x50, and intrinsic/natural size 50x25. The left half of the image should be red and there should be a black circle in the center.<br/>
<code class="stats" id="code8"></code>
<br clear="all"/>
</div>
</body>
</html>