Commit a10fe4b2 authored by fs@opera.com's avatar fs@opera.com

Rewind the timeline for SVG-in-<img> when resetAnimation() is called

Attempt to mimic the behavior of animated raster images (BitmapImage)
more closely wrt when the timeline is started and reset/rewound.

BUG=177277

Review URL: https://codereview.chromium.org/206033005

git-svn-id: svn://svn.chromium.org/blink/trunk@169694 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ab1a49e3
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>
<!DOCTYPE html>
<title>SVG-in-&lt;img&gt;: Animation resets when all references are removed.</title>
<div style="width: 100px; height: 100px;"></div>
<script>
if (window.testRunner)
testRunner.waitUntilDone();
var div = document.querySelector('div');
var imgurl = "url('../as-image/resources/animated-rect-color.svg')";
div.style.background = imgurl;
setTimeout(function() {
div.style.background = "";
setTimeout(function() {
div.style.background = imgurl;
setTimeout(function() {
if (window.testRunner)
testRunner.notifyDone();
}, 10);
}, 0);
}, 100);
</script>
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>
<!DOCTYPE html>
<title>SVG-in-&lt;img&gt;: Animation resets when all references are removed.</title>
<img></img>
<script>
if (window.testRunner)
testRunner.waitUntilDone();
var img = document.querySelector('img');
var imgurl = "resources/animated-rect-color.svg";
img.src = imgurl;
setTimeout(function() {
img.src = "";
setTimeout(function() {
img.src = imgurl;
setTimeout(function() {
if (window.testRunner)
testRunner.notifyDone();
}, 10);
}, 0);
}, 100);
</script>
<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
<rect width='100' height='100' fill='blue'>
<set attributeName='fill' to='green' dur='0.075s'/>
</rect>
</svg>
......@@ -282,6 +282,11 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
if (imageObserver())
imageObserver()->didDraw(this);
// Start any (SMIL) animations if needed. This will restart or continue
// animations if preceded by calls to resetAnimation or stopAnimation
// respectively.
startAnimation();
}
RenderBox* SVGImage::embeddedContentBox() const
......@@ -351,10 +356,9 @@ void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement)
if (!rootElement || !rootElement->animationsPaused())
return;
rootElement->unpauseAnimations();
rootElement->setCurrentTime(0);
}
void SVGImage::stopAnimation()
......@@ -370,7 +374,14 @@ void SVGImage::stopAnimation()
void SVGImage::resetAnimation()
{
stopAnimation();
if (!m_page)
return;
LocalFrame* frame = m_page->mainFrame();
SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
if (!rootElement)
return;
rootElement->pauseAnimations();
rootElement->setCurrentTime(0);
}
bool SVGImage::hasAnimations() const
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment