Drawing an SVG image into a <canvas> that is not in the DOM draws the wrong region
https://bugs.webkit.org/show_bug.cgi?id=159276

Patch by Antoine Quint <graouts@apple.com> on 2016-06-30
Reviewed by Dean Jackson.

Source/WebCore:

In the event where the <img> element that we are passing to CanvasRenderingContext2D.drawImage()
points to an SVG resource, we ensure that the container for the SVG image is sized to match the
HTML element. The necessity for setting this container size, explained in webkit.org/b/148845,
is that we must ensure a cached image does not have an outdated container size.

Tests: svg/as-image/img-with-svg-resource-in-dom-and-drawImage.html
       svg/as-image/img-with-svg-resource-in-dom-no-size-and-drawImage.html
       svg/as-image/img-with-svg-resource-not-in-dom-and-drawImage.html
       svg/as-image/img-with-svg-resource-not-in-dom-no-size-and-drawImage.html

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):

LayoutTests:

Adding a series of new tests to check we correctly respect mismatching source and
destination rectangles with SVG images as sources, both with the source <img> element
being present and absent from the DOM, and explicit sizes being set or not set.

* svg/as-image/img-with-svg-resource-in-dom-and-drawImage-expected.html: Added.
* svg/as-image/img-with-svg-resource-in-dom-and-drawImage.html: Added.
* svg/as-image/img-with-svg-resource-in-dom-no-size-and-drawImage-expected.html: Added.
* svg/as-image/img-with-svg-resource-in-dom-no-size-and-drawImage.html: Added.
* svg/as-image/img-with-svg-resource-not-in-dom-and-drawImage-expected.html: Added.
* svg/as-image/img-with-svg-resource-not-in-dom-and-drawImage.html: Added.
* svg/as-image/img-with-svg-resource-not-in-dom-no-size-and-drawImage-expected.html: Added.
* svg/as-image/img-with-svg-resource-not-in-dom-no-size-and-drawImage.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@202712 268f45cc-cd09-0410-ab3c-d52691b4dbfc
11 files changed