Changeset 163415 in webkit
- Timestamp:
- Feb 4, 2014 4:09:15 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 32 added
- 6 deleted
- 32 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r163413 r163415 1 2014-02-04 Yoav Weiss <yoav@yoav.ws> 2 3 Use srcset's pixel density to determine intrinsic size 4 https://bugs.webkit.org/show_bug.cgi?id=123832 5 6 Reviewed by Dean Jackson. 7 8 The patch is a port of a similar Blink patch: https://codereview.chromium.org/25105004 9 According to the spec "When an img element has a current pixel density that is not 1.0, 10 the element's image data must be treated as if its resolution, in device pixels per CSS pixels, 11 was the current pixel density." 12 13 Layout test changes include modifications of existing tests to accomodate the new image dimensions, as well as new tests for this 14 specific functionality. 15 16 * fast/hidpi/image-srcset-change-dynamically-from-js-2x-expected.txt: 17 * fast/hidpi/image-srcset-change-dynamically-from-js-2x.html: 18 * fast/hidpi/image-srcset-data-escaped-srcset-expected.txt: 19 * fast/hidpi/image-srcset-data-escaped-srcset.html: 20 * fast/hidpi/image-srcset-data-src.html: 21 * fast/hidpi/image-srcset-data-srcset.html: 22 * fast/hidpi/image-srcset-fraction.html: 23 * fast/hidpi/image-srcset-intrinsic-size-expected.txt: Added. 24 * fast/hidpi/image-srcset-intrinsic-size.html: Added. 25 * fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.txt: 26 * fast/hidpi/image-srcset-invalid-inputs-correct-src.html: 27 * fast/hidpi/image-srcset-invalid-inputs.html: 28 * fast/hidpi/image-srcset-invalid-inputs-expected.txt: Added. 29 * fast/hidpi/image-srcset-only-src-attribute-expected.txt: Added. 30 * fast/hidpi/image-srcset-only-src-attribute.html: 31 * fast/hidpi/image-srcset-png-canvas-expected.html: Added. 32 * fast/hidpi/image-srcset-png-canvas.html: Added. 33 * fast/hidpi/image-srcset-png-expected.html: Added. 34 * fast/hidpi/image-srcset-png.html: Added. 35 * fast/hidpi/image-srcset-relative-svg-expected.html: Added. 36 * fast/hidpi/image-srcset-relative-svg.html: Added. 37 * fast/hidpi/image-srcset-remove-dynamically-from-js.html: 38 * fast/hidpi/image-srcset-simple-2x-expected.txt: 39 * fast/hidpi/image-srcset-simple-2x.html: 40 * fast/hidpi/image-srcset-space-left-nomodifier-expected.txt: Added. 41 * fast/hidpi/image-srcset-space-left-nomodifier.html: Copied from LayoutTests/fast/hidpi/image-srcset-data-srcset.html. 42 * fast/hidpi/image-srcset-svg-expected.html: Added. 43 * fast/hidpi/image-srcset-svg.html: Added. 44 * fast/hidpi/image-srcset-svg2-expected.html: Added. 45 * fast/hidpi/image-srcset-svg2.html: Added. 46 * fast/hidpi/resources/green-400-px-square.png: Added. 47 * fast/hidpi/resources/relativesrcset.svg: Added. 48 * fast/hidpi/resources/srcset-helper.js: 49 (runTest): 50 * fast/hidpi/resources/srcset.png: Added. 51 * fast/hidpi/resources/srcset.svg: Added. 52 * fast/hidpi/resources/srcset_100px.svg: Added. 53 * fast/hidpi/resources/svg_canvas_helper.js: Added. 54 (drawCanvas): 55 * fast/hidpi/resources/svg_tests.css: Added. 56 (.test): 57 (.test img, .test canvas): 58 (.test .stats): 59 (.expected, .actual): 60 * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.png: Removed. 61 * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.txt: Removed. 62 63 The following tests were added, but skipped, since they reveal an unrelated SVG on canvas rendering issue: 64 * fast/hidpi/image-srcset-svg-canvas-2x-expected.html: Added. 65 * fast/hidpi/image-srcset-svg-canvas-2x.html: Added. 66 * fast/hidpi/image-srcset-svg-canvas-expected.html: Added. 67 * fast/hidpi/image-srcset-svg-canvas.html: Added. 68 * fast/hidpi/image-srcset-relative-svg-canvas-2x-expected.html: Added. 69 * fast/hidpi/image-srcset-relative-svg-canvas-2x.html: Added. 70 * fast/hidpi/image-srcset-relative-svg-canvas-expected.html: Added. 71 * fast/hidpi/image-srcset-relative-svg-canvas.html: Added. 72 1 73 2014-02-04 Geoffrey Garen <ggaren@apple.com> 2 74 -
trunk/LayoutTests/TestExpectations
r163329 r163415 59 59 webkit.org/b/120148 [ Debug ] webaudio/javascriptaudionode-downmix8-2channel-input.html [ Pass Crash ] 60 60 61 webkit.org/b/124342 fast/hidpi/image-srcset-svg-canvas.html [ Failure ] 62 webkit.org/b/124342 fast/hidpi/image-srcset-svg-canvas-2x.html [ Failure ] 63 webkit.org/b/124349 fast/hidpi/image-srcset-relative-svg-canvas-2x.html [ Failure ] 64 webkit.org/b/124349 fast/hidpi/image-srcset-relative-svg-canvas.html [ Failure ] 65 61 66 webaudio/javascriptaudionode-downmix8-2channel-input.html 62 67 -
trunk/LayoutTests/fast/hidpi/image-srcset-change-dynamically-from-js-2x-expected.txt
r154582 r163415 1 PASS internals.isPreloaded("resources/blue-100-px-square.png") is false 1 blue-100-px-square.png has MIME type image/png 2 image-srcset-change-dynamically-from-js-2x.html has MIME type text/html 3 srcset-helper.js has MIME type text/javascript 4 js-test-pre.js has MIME type text/javascript 5 green-400-px-square.png has MIME type image/png 2 6 PASS document.getElementById("foo").clientWidth==200 is true 3 7 This test passes if this img tag below is a green square when the scale factor is 2. It ensures that attributes can be changed dynamically from javascript, and that only the correct resource is loaded. -
trunk/LayoutTests/fast/hidpi/image-srcset-change-dynamically-from-js-2x.html
r155269 r163415 6 6 if (window.testRunner) { 7 7 testRunner.dumpAsText(); 8 testRunner.dumpResourceResponseMIMETypes(); 8 9 } 9 10 … … 11 12 var img = document.getElementById("foo"); 12 13 // srcset must be set first, otherwise 'src' is loaded as well 13 img.srcset = "resources/ green-200-px-square.png 2x";14 img.srcset = "resources/blue-100-px-square.png 1x, resources/green-400-px-square.png 2x"; 14 15 img.src = "resources/blue-100-px-square.png" 15 16 } … … 19 20 }, false); 20 21 addEventListener("load", function() { 21 if (internals)22 shouldBeFalse('internals.isPreloaded("resources/blue-100-px-square.png")');23 22 shouldBeTrue('document.getElementById("foo").clientWidth==200'); 24 23 }, false); -
trunk/LayoutTests/fast/hidpi/image-srcset-data-escaped-srcset-expected.txt
r155988 r163415 1 PASS document.getElementById("foo").clientWidth== 100 is true1 PASS document.getElementById("foo").clientWidth==50 is true 2 2 This test passes if the image below is not empty. It ensures that the srcset attribute support data URI schemes with escaped characters. 3 3 -
trunk/LayoutTests/fast/hidpi/image-srcset-data-escaped-srcset.html
r155988 r163415 8 8 9 9 addEventListener("load", function() { 10 shouldBeTrue('document.getElementById("foo").clientWidth== 100');10 shouldBeTrue('document.getElementById("foo").clientWidth==50'); 11 11 }, false); 12 12 </script> -
trunk/LayoutTests/fast/hidpi/image-srcset-data-src.html
r155269 r163415 3 3 <script src="../../resources/js-test-pre.js"></script> 4 4 <script> 5 if (window.testRunner) {6 testRunner.dumpAsText();7 }8 9 5 addEventListener("load", function() { 10 6 shouldBeTrue('document.getElementById("foo").clientWidth==150'); -
trunk/LayoutTests/fast/hidpi/image-srcset-data-srcset.html
r155988 r163415 3 3 <script src="../../resources/js-test-pre.js"></script> 4 4 <script> 5 if (window.testRunner) {6 testRunner.dumpAsText();7 }8 9 5 addEventListener("load", function() { 10 6 shouldBeTrue('document.getElementById("foo").clientWidth==150'); -
trunk/LayoutTests/fast/hidpi/image-srcset-fraction-1.5x.html
r155988 r163415 19 19 <body> 20 20 <div>This test passes if the srcset resource is loaded and displayed as the image</div> 21 <img src="resources/blue-100-px-square.png" srcset="resources/green- 200-px-square.png 2x" id="testimg">21 <img src="resources/blue-100-px-square.png" srcset="resources/green-400-px-square.png 2x" id="testimg"> 22 22 </body> 23 23 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-fraction.html
r155269 r163415 7 7 <script src="../../resources/js-test-pre.js"></script> 8 8 <script> 9 if (window.testRunner) {10 testRunner.dumpAsText();11 }12 13 9 addEventListener("load", function() { 14 10 if (internals) … … 19 15 <body> 20 16 <div>This test passes if the srcset resource is loaded and displayed as the image</div> 21 <img src="resources/blue-100-px-square.png" srcset="resources/green- 200-px-square.png 2x" id="testimg">17 <img src="resources/blue-100-px-square.png" srcset="resources/green-400-px-square.png 2x" id="testimg"> 22 18 </body> 23 19 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.txt
r154582 r163415 1 PASS document.getElementById("foo").clientWidth== 200 is true1 PASS document.getElementById("foo").clientWidth==400 is true 2 2 This test passes if this img tag below is a green square regardless of the scale factor. It ensures that invalid inputs from srcset are ignored, and src is selected (since it's the only candidate left) 3 3 -
trunk/LayoutTests/fast/hidpi/image-srcset-invalid-inputs-correct-src.html
r155269 r163415 9 9 10 10 addEventListener("load", function() { 11 shouldBeTrue('document.getElementById("foo").clientWidth== 200');11 shouldBeTrue('document.getElementById("foo").clientWidth==400'); 12 12 }, false); 13 13 </script> … … 17 17 <div>This test passes if this img tag below is a green square regardless of the scale factor. It ensures that invalid inputs 18 18 from srcset are ignored, and src is selected (since it's the only candidate left)</div> 19 <img id="foo" src="resources/green- 200-px-square.png" srcset="1x,, , , 2x ,,">19 <img id="foo" src="resources/green-400-px-square.png" srcset="1x,, , , 2x ,,"> 20 20 </body> 21 21 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-invalid-inputs-except-one.html
r155988 r163415 17 17 <div>This test passes if the img tag below is a green square regardless of the scale factor. It ensures that invalid inputs are 18 18 ignored and well-formed images are chosen regardless of their qualifiers, once they are the only candidate left</div> 19 <img id="foo" src="" srcset="1x,, , x ,2x , foo.jpg, 3x, bar.jpg 4x 100h, foo.jpg 5, bar.jpg dx, resources/green- 200-px-square.png 2x ,"></img>19 <img id="foo" src="" srcset="1x,, , x ,2x , foo.jpg, 3x, bar.jpg 4x 100h, foo.jpg 5, bar.jpg dx, resources/green-400-px-square.png 2x ,"></img> 20 20 </body> 21 21 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-invalid-inputs.html
r155988 r163415 1 1 <html> 2 2 <head> 3 <script src=" resources/srcset-helper.js"></script>3 <script src="../../resources/js-test-pre.js"></script> 4 4 </head> 5 5 6 6 <body id="body"> 7 7 <div>This test passes if this img tag below is empty and displays nothing. It ensures that the srcset attribute supports invalid inputs</div> 8 <img height="100" width="100" src="" srcset="1x,, , x ,2x , foo.jpg, 3x, bar.jpg 4x 100h, foo.jpg 5, bar.jpg dx,foo.jpg,bar.jpg,"></img> 8 <img id="foo" src="" srcset="1x,, , x ,2x " onerror="testPassed('did not load invalid inputs')" onload="testFailed('Loaded 9 invalid inputs')"></img> 9 10 </body> 10 11 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-only-src-attribute.html
r153625 r163415 1 <head> 1 2 <html> 2 <head>3 3 <script src="resources/srcset-helper.js"></script> 4 <script src="../../resources/js-test-pre.js"></script> 5 <script> 6 if (window.testRunner) { 7 testRunner.dumpAsText(); 8 } 9 addEventListener("load", function() { 10 shouldBeTrue('document.getElementById("foo").clientWidth==200'); 11 }, false); 12 </script> 4 13 </head> 5 6 14 <body id="body"> 7 15 <div>This test passes if this img tag below is a green square when the scale factor is 2. It ensures that the selection algorithm does not change the behavior of the src attribute, even with a scale factor greater than 1</div> 8 <img height="100" width="100" src="resources/green-200-px-square.png"></img>16 <img id="foo" src="resources/green-200-px-square.png"></img> 9 17 </body> 10 18 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-remove-dynamically-from-js.html
r155269 r163415 27 27 <body id="body"> 28 28 <div>This test passes if this img tag below is a green square. It ensures that attributes can be removed dynamically from javascript</div> 29 <img id="foo" src="resources/blue-100-px-square.png" srcset="resources/green- 200-px-square.png 2x">29 <img id="foo" src="resources/blue-100-px-square.png" srcset="resources/green-400-px-square.png 2x"> 30 30 </body> 31 31 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-simple-2x-expected.txt
r154582 r163415 1 PASS document.getElementById("foo").clientWidth== 800 is true1 PASS document.getElementById("foo").clientWidth==200 is true 2 2 This test passes if the image below says 1x with a reddish background when the deviceScaleFactor is 1, and if says 2x with a greenish background when the deviceScaleFactor is 2. 3 3 -
trunk/LayoutTests/fast/hidpi/image-srcset-simple-2x.html
r155269 r163415 7 7 <script src="../../resources/js-test-pre.js"></script> 8 8 <script> 9 if (window.testRunner) {10 testRunner.dumpAsText();11 }12 13 9 addEventListener("load", function() { 14 shouldBeTrue('document.getElementById("foo").clientWidth== 800');10 shouldBeTrue('document.getElementById("foo").clientWidth==200'); 15 11 }, false); 16 12 </script> … … 19 15 <body id="body"> 20 16 <div>This test passes if the image below says 1x with a reddish background when the deviceScaleFactor is 1, and if says 2x with a greenish background when the deviceScaleFactor is 2.</div> 21 <img id="foo" src="" srcset="resources/ image-set-1x.png 1x, resources/deleteButton.png 3x, resources/image-set-2x.png 2x">17 <img id="foo" src="" srcset="resources/blue-100-px-square.png 1x, resources/deleteButton.png 3x, resources/green-400-px-square.png 2x"> 22 18 </body> 23 19 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-space-left-nomodifier.html
r163413 r163415 1 1 <html> 2 2 <head> 3 <script src="resources/srcset-helper.js"></script> 3 4 <script src="../../resources/js-test-pre.js"></script> 4 5 <script> … … 12 13 </script> 13 14 </head> 15 14 16 <body id="body"> 15 <div>This test passes if the image below looks like a 2x2 grid (yellow, gray, light green, dark green). In this case the srcset attribute has a base64 url.</div>16 <img id="foo" src="" srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAA8CAIAAAAL5NQ9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2woaBQc4oLEFpAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACMSURBVHja7dNBEYAgFEVRPhHMYgAzUIsmVnFvB/fsoQb+ObfBmzMvxneW1D1vzz2wFiEUQiFEKIRCKIQIhVAIhRChEAqhECIUQiEUQoRCKIRCiFAIhVAIEep3xTWTLzzu5oVCKIRCiFAIhVAIEQqhEAohQiEUQiFEKIRCKIQIhVAIhRChEAqhECLUZi3VEwcBMGr1NgAAAABJRU5ErkJggg== 2x, data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAA8CAIAAAAL5NQ9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2woaBQc4oLEFpAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACMSURBVHja7dNBEYAgFEVRPhHMYgAzUIsmVnFvB/fsoQb+ObfBmzMvxneW1D1vzz2wFiEUQiFEKIRCKIQIhVAIhRChEAqhECIUQiEUQoRCKIRCiFAIhVAIEep3xTWTLzzu5oVCKIRCiFAIhVAIEQqhEAohQiEUQiFEKIRCKIQIhVAIhRChEAqhECLUZi3VEwcBMGr1NgAAAABJRU5ErkJggg== 1x">17 <div>This test passes if the image below is not empty. It ensures that a candidate without scale modifier get a default one, even with space left at the end.</div> 18 <img id="foo" src="" srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAA8CAIAAAAL5NQ9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2woaBQc4oLEFpAAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACMSURBVHja7dNBEYAgFEVRPhHMYgAzUIsmVnFvB/fsoQb+ObfBmzMvxneW1D1vzz2wFiEUQiFEKIRCKIQIhVAIhRChEAqhECIUQiEUQoRCKIRCiFAIhVAIEep3xTWTLzzu5oVCKIRCiFAIhVAIEQqhEAohQiEUQiFEKIRCKIQIhVAIhRChEAqhECLUZi3VEwcBMGr1NgAAAABJRU5ErkJggg== "> 17 19 </body> 18 20 </html> -
trunk/LayoutTests/fast/hidpi/image-srcset-src-selection-2x.html
r155269 r163415 19 19 <body id="body"> 20 20 <div>This test passes if the div below is a green 200px square when the deviceScaleFactor is 2. It simply ensures that the src attribute is taken into account by the selection algorithm when this one is processing the images candidates</div> 21 <img id="foo" src="resources/blue-100-px-square.png" srcset="resources/green- 200-px-square.png 2x">21 <img id="foo" src="resources/blue-100-px-square.png" srcset="resources/green-400-px-square.png 2x"> 22 22 </body> 23 23 </html> -
trunk/LayoutTests/fast/hidpi/resources/srcset-helper.js
r153625 r163415 14 14 delete sessionStorage.pageReloaded; 15 15 delete sessionStorage.scaleFactorIsSet; 16 testRunner.notifyDone(); 16 if (!window.manualNotifyDone) 17 testRunner.notifyDone(); 17 18 } else { 18 19 // Right now there is a bug that srcset does not properly deal with dynamic changes to the scale factor, -
trunk/Source/WebCore/ChangeLog
r163413 r163415 1 2014-02-04 Yoav Weiss <yoav@yoav.ws> 2 3 Use srcset's pixel density to determine intrinsic size 4 https://bugs.webkit.org/show_bug.cgi?id=123832 5 6 Reviewed by Dean Jackson. 7 8 The patch is a port of a similar Blink patch: https://codereview.chromium.org/25105004 9 According to the spec "When an img element has a current pixel density that is not 1.0, 10 the element's image data must be treated as if its resolution, in device pixels per CSS pixels, 11 was the current pixel density." 12 13 I've added that support using the following changes: 14 - bestFitSourceForImageAttributes now returns the image candidate to HTMLImageElement. 15 - HTMLImageElement passes the devicePixelRatio data to RenderImage, which stores it. 16 - Bitmap images are scaled using the devicePixelRatio at RenderImageResource's intrinsicSize() and imageSize(). 17 - SVG images are scaled using the devicePixelRatio at RenderReplaced::computeAspectRatioInformationForRenderBox. 18 - Canvas support added at CanvasRenderingContext2D::size. 19 20 Tests: fast/hidpi/image-srcset-intrinsic-size.html 21 fast/hidpi/image-srcset-png-canvas.html 22 fast/hidpi/image-srcset-png.html 23 fast/hidpi/image-srcset-relative-svg-canvas-2x.html 24 fast/hidpi/image-srcset-relative-svg.html 25 fast/hidpi/image-srcset-space-left-nomodifier.html 26 fast/hidpi/image-srcset-svg-canvas-2x.html 27 fast/hidpi/image-srcset-svg-canvas.html 28 fast/hidpi/image-srcset-svg.html 29 fast/hidpi/image-srcset-svg2.html 30 31 * html/HTMLImageElement.cpp: 32 (WebCore::HTMLImageElement::HTMLImageElement): 33 (WebCore::HTMLImageElement::parseAttribute): 34 (WebCore::HTMLImageElement::createRenderer): 35 * html/HTMLImageElement.h: 36 * html/canvas/CanvasRenderingContext2D.cpp: 37 (WebCore::size): 38 (WebCore::CanvasRenderingContext2D::drawImage): 39 * html/parser/HTMLParserIdioms.cpp: 40 (WebCore::compareByScaleFactor): 41 (WebCore::parseImagesWithScaleFromSrcsetAttribute): 42 (WebCore::bestFitSourceForImageAttributes): 43 * html/parser/HTMLParserIdioms.h: 44 (WebCore::ImageWithScale::ImageWithScale): 45 (WebCore::ImageWithScale::imageURL): 46 (WebCore::ImageWithScale::scaleFactor): 47 * html/parser/HTMLPreloadScanner.cpp: 48 (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): 49 * rendering/RenderImage.cpp: 50 (WebCore::RenderImage::RenderImage): 51 * rendering/RenderImage.h: 52 (WebCore::RenderImage::setImageDevicePixelRatio): 53 (WebCore::RenderImage::imageDevicePixelRatio): 54 * rendering/RenderImageResource.cpp: 55 (WebCore::RenderImageResource::imageSize): 56 (WebCore::RenderImageResource::intrinsicSize): 57 (WebCore::RenderImageResource::getImageSize): 58 * rendering/RenderImageResource.h: 59 * rendering/RenderReplaced.cpp: 60 (WebCore::RenderReplaced::computeAspectRatioInformationForRenderBox): 61 1 62 2014-02-04 Geoffrey Garen <ggaren@apple.com> 2 63 -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r162679 r163415 46 46 , m_form(form) 47 47 , m_compositeOperator(CompositeSourceOver) 48 , m_imageDevicePixelRatio(1.0f) 48 49 { 49 50 ASSERT(hasTagName(imgTag)); … … 119 120 toRenderImage(renderer())->updateAltText(); 120 121 } else if (name == srcAttr || name == srcsetAttr) { 121 m_bestFitImageURL = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr)); 122 ImageWithScale candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr)); 123 m_bestFitImageURL = candidate.imageURL(fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr)); 124 float candidateScaleFactor = candidate.scaleFactor(); 125 if (candidateScaleFactor > 0) 126 m_imageDevicePixelRatio = 1 / candidateScaleFactor; 127 if (renderer() && renderer()->isImage()) 128 toRenderImage(renderer())->setImageDevicePixelRatio(m_imageDevicePixelRatio); 122 129 m_imageLoader.updateFromElementIgnoringPreviousError(); 123 130 } else if (name == usemapAttr) { … … 180 187 return RenderElement::createFor(*this, std::move(style)); 181 188 182 return createRenderer<RenderImage>(*this, std::move(style) );189 return createRenderer<RenderImage>(*this, std::move(style), nullptr, m_imageDevicePixelRatio); 183 190 } 184 191 -
trunk/Source/WebCore/html/HTMLImageElement.h
r162158 r163415 122 122 AtomicString m_bestFitImageURL; 123 123 AtomicString m_lowercasedUsemap; 124 float m_imageDevicePixelRatio; 124 125 }; 125 126 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r163079 r163415 49 49 #include "ImageData.h" 50 50 #include "RenderElement.h" 51 #include "RenderImage.h" 51 52 #include "RenderLayer.h" 52 53 #include "SecurityOrigin.h" … … 1197 1198 } 1198 1199 1199 static LayoutSize size(HTMLImageElement* image) 1200 { 1201 if (CachedImage* cachedImage = image->cachedImage()) 1202 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FIXME: Not sure about this. 1203 return IntSize(); 1200 enum ImageSizeType { 1201 ImageSizeAfterDevicePixelRatio, 1202 ImageSizeBeforeDevicePixelRatio 1203 }; 1204 1205 static LayoutSize size(HTMLImageElement* image, ImageSizeType sizeType) 1206 { 1207 LayoutSize size; 1208 if (CachedImage* cachedImage = image->cachedImage()) { 1209 size = cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FIXME: Not sure about this. 1210 1211 if (sizeType == ImageSizeAfterDevicePixelRatio && image->renderer() && image->renderer()->isRenderImage() && cachedImage->image() && !cachedImage->image()->hasRelativeWidth()) 1212 size.scale(toRenderImage(image->renderer())->imageDevicePixelRatio()); 1213 } 1214 return size; 1204 1215 } 1205 1216 … … 1227 1238 return; 1228 1239 } 1229 LayoutSize s = size(image);1230 drawImage(image, x, y, s.width(), s.height(), ec);1240 LayoutSize destRectSize = size(image, ImageSizeAfterDevicePixelRatio); 1241 drawImage(image, x, y, destRectSize.width(), destRectSize.height(), ec); 1231 1242 } 1232 1243 … … 1238 1249 return; 1239 1250 } 1240 LayoutSize s = size(image);1241 drawImage(image, FloatRect(0, 0, s .width(), s.height()), FloatRect(x, y, width, height), ec);1251 LayoutSize sourceRectSize = size(image, ImageSizeBeforeDevicePixelRatio); 1252 drawImage(image, FloatRect(0, 0, sourceRectSize.width(), sourceRectSize.height()), FloatRect(x, y, width, height), ec); 1242 1253 } 1243 1254 … … 1276 1287 FloatRect normalizedDstRect = normalizeRect(dstRect); 1277 1288 1278 FloatRect imageRect = FloatRect(FloatPoint(), size(image ));1289 FloatRect imageRect = FloatRect(FloatPoint(), size(image, ImageSizeBeforeDevicePixelRatio)); 1279 1290 if (!srcRect.width() || !srcRect.height()) { 1280 1291 ec = INDEX_SIZE_ERR; -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp
r163398 r163415 291 291 } 292 292 293 struct ImageWithScale {294 unsigned imageURLStart;295 unsigned imageURLLength;296 float scaleFactor;297 298 ImageWithScale()299 : imageURLStart(0)300 , imageURLLength(0)301 , scaleFactor(1)302 {303 }304 305 bool hasImageURL() const306 {307 return imageURLLength;308 }309 };310 293 typedef Vector<ImageWithScale> ImageCandidates; 311 294 312 295 static inline bool compareByScaleFactor(const ImageWithScale& first, const ImageWithScale& second) 313 296 { 314 return first.scaleFactor < second.scaleFactor;297 return first.scaleFactor() < second.scaleFactor(); 315 298 } 316 299 … … 390 373 } 391 374 } 392 ImageWithScale image; 393 image.imageURLStart = imageURLStart; 394 image.imageURLLength = imageURLEnd - imageURLStart; 395 image.scaleFactor = imageScaleFactor; 396 375 ImageWithScale image(imageURLStart, imageURLEnd - imageURLStart, imageScaleFactor); 397 376 imageCandidates.append(image); 398 377 // 11. Return to the step labeled splitting loop. … … 401 380 } 402 381 403 StringbestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& srcsetAttribute)382 ImageWithScale bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& srcsetAttribute) 404 383 { 405 384 ImageCandidates imageCandidates; … … 413 392 414 393 if (imageCandidates.isEmpty()) 415 return String();394 return ImageWithScale(); 416 395 417 396 std::stable_sort(imageCandidates.begin(), imageCandidates.end(), compareByScaleFactor); 418 397 419 398 for (size_t i = 0; i < imageCandidates.size() - 1; ++i) { 420 if (imageCandidates[i].scaleFactor >= deviceScaleFactor)421 return imageCandidates[i] .hasImageURL() ? srcsetAttribute.substringSharingImpl(imageCandidates[i].imageURLStart, imageCandidates[i].imageURLLength) : srcAttribute;399 if (imageCandidates[i].scaleFactor() >= deviceScaleFactor) 400 return imageCandidates[i]; 422 401 } 423 402 const ImageWithScale& lastCandidate = imageCandidates.last(); 424 return lastCandidate .hasImageURL() ? srcsetAttribute.substringSharingImpl(lastCandidate.imageURLStart, lastCandidate.imageURLLength) : srcAttribute;425 } 426 427 } 403 return lastCandidate; 404 } 405 406 } -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.h
r162258 r163415 33 33 34 34 class Decimal; 35 36 class ImageWithScale { 37 public: 38 ImageWithScale() 39 : m_imageURLStart(0) 40 , m_imageURLLength(0) 41 , m_scaleFactor(1) 42 { 43 } 44 45 ImageWithScale(unsigned start, unsigned length, float scaleFactor) 46 : m_imageURLStart(start) 47 , m_imageURLLength(length) 48 , m_scaleFactor(scaleFactor) 49 { 50 } 51 52 String imageURL(const String& srcAttribute, const String& srcsetAttribute) const 53 { 54 return m_imageURLLength ? srcsetAttribute.substringSharingImpl(m_imageURLStart, m_imageURLLength) : srcAttribute; 55 } 56 57 float scaleFactor() const 58 { 59 return m_scaleFactor; 60 } 61 62 private: 63 unsigned m_imageURLStart; 64 unsigned m_imageURLLength; 65 float m_scaleFactor; 66 }; 35 67 36 68 // Space characters as defined by the HTML specification. … … 100 132 bool threadSafeMatch(const QualifiedName&, const QualifiedName&); 101 133 102 StringbestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& sourceSetAttribute);134 ImageWithScale bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& sourceSetAttribute); 103 135 104 136 } -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp
r162275 r163415 105 105 // Resolve between src and srcSet if we have them. 106 106 if (!m_srcSetAttribute.isEmpty()) { 107 String srcMatchingScale = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute); 107 ImageWithScale imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute); 108 String srcMatchingScale = imageCandidate.imageURL(m_urlToLoad, m_srcSetAttribute); 108 109 setUrlToLoad(srcMatchingScale, true); 109 110 } -
trunk/Source/WebCore/rendering/RenderImage.cpp
r163079 r163415 117 117 using namespace HTMLNames; 118 118 119 RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style, StyleImage* styleImage )119 RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style, StyleImage* styleImage, const float imageDevicePixelRatio) 120 120 : RenderReplaced(element, std::move(style), IntSize()) 121 121 , m_imageResource(styleImage ? std::make_unique<RenderImageResourceStyleImage>(*styleImage) : std::make_unique<RenderImageResource>()) … … 123 123 , m_didIncrementVisuallyNonEmptyPixelCount(false) 124 124 , m_isGeneratedContent(false) 125 , m_imageDevicePixelRatio(imageDevicePixelRatio) 125 126 { 126 127 updateAltText(); … … 134 135 , m_didIncrementVisuallyNonEmptyPixelCount(false) 135 136 , m_isGeneratedContent(false) 137 , m_imageDevicePixelRatio(1.0f) 136 138 { 137 139 imageResource().initialize(this); -
trunk/Source/WebCore/rendering/RenderImage.h
r162972 r163415 36 36 class RenderImage : public RenderReplaced { 37 37 public: 38 RenderImage(Element&, PassRef<RenderStyle>, StyleImage* = nullptr );38 RenderImage(Element&, PassRef<RenderStyle>, StyleImage* = nullptr, const float = 1.0f); 39 39 RenderImage(Document&, PassRef<RenderStyle>, StyleImage* = nullptr); 40 40 virtual ~RenderImage(); … … 63 63 const String& altText() const { return m_altText; } 64 64 void setAltText(const String& altText) { m_altText = altText; } 65 65 66 inline void setImageDevicePixelRatio(float factor) { m_imageDevicePixelRatio = factor; } 67 float imageDevicePixelRatio() const { return m_imageDevicePixelRatio; } 68 66 69 protected: 67 70 virtual bool needsPreferredWidthsRecalculation() const override final; … … 114 117 bool m_didIncrementVisuallyNonEmptyPixelCount; 115 118 bool m_isGeneratedContent; 119 float m_imageDevicePixelRatio; 116 120 117 121 friend class RenderImageScaleObserver; -
trunk/Source/WebCore/rendering/RenderImageResource.cpp
r160478 r163415 32 32 #include "Image.h" 33 33 #include "RenderElement.h" 34 #include "RenderImage.h" 34 35 #include "RenderImageResourceStyleImage.h" 35 36 … … 119 120 LayoutSize RenderImageResource::imageSize(float multiplier) const 120 121 { 121 return m_cachedImage ? m_cachedImage->imageSizeForRenderer(m_renderer, multiplier) : LayoutSize();122 return getImageSize(multiplier, CachedImage::UsedSize); 122 123 } 123 124 124 125 LayoutSize RenderImageResource::intrinsicSize(float multiplier) const 125 126 { 126 return m_cachedImage ? m_cachedImage->imageSizeForRenderer(m_renderer, multiplier, CachedImage::IntrinsicSize) : LayoutSize(); 127 return getImageSize(multiplier, CachedImage::IntrinsicSize); 128 } 129 130 LayoutSize RenderImageResource::getImageSize(float multiplier, CachedImage::SizeType type) const 131 { 132 if (!m_cachedImage) 133 return LayoutSize(); 134 LayoutSize size = m_cachedImage->imageSizeForRenderer(m_renderer, multiplier, type); 135 if (m_renderer && m_renderer->isRenderImage()) 136 size.scale(toRenderImage(m_renderer)->imageDevicePixelRatio()); 137 return size; 127 138 } 128 139 -
trunk/Source/WebCore/rendering/RenderImageResource.h
r162356 r163415 27 27 #define RenderImageResource_h 28 28 29 #include "CachedImage.h" 29 30 #include "CachedResourceHandle.h" 30 31 #include "StyleImage.h" … … 66 67 RenderElement* m_renderer; 67 68 CachedResourceHandle<CachedImage> m_cachedImage; 69 70 private: 71 LayoutSize getImageSize(float multiplier, CachedImage::SizeType) const; 68 72 }; 69 73 -
trunk/Source/WebCore/rendering/RenderReplaced.cpp
r162907 r163415 32 32 #include "RenderBlock.h" 33 33 #include "RenderFlowThread.h" 34 #include "RenderImage.h" 34 35 #include "RenderLayer.h" 35 36 #include "RenderRegion.h" … … 271 272 272 273 // Handle zoom & vertical writing modes here, as the embedded document doesn't know about them. 273 if (!isPercentageIntrinsicSize) 274 if (!isPercentageIntrinsicSize) { 274 275 intrinsicSize.scale(style().effectiveZoom()); 276 if (isRenderImage()) 277 intrinsicSize.scale(toRenderImage(this)->imageDevicePixelRatio()); 278 } 275 279 276 280 if (hasAspectRatio() && isPercentageIntrinsicSize)
Note: See TracChangeset
for help on using the changeset viewer.