ASSERTion failure when SVG element is removed from document and readded
https://bugs.webkit.org/show_bug.cgi?id=95517
<rdar://problem/12175583>
Reviewed by Brady Eidson.
Previously, SVG animations would cease to animate when their parent
<svg> element was removed and re-added to the document.
Instead, to match Firefox and Opera, we should continue the animation
with the same beginTime (i.e. the animation continues as if it had never
been removed from the document).
Test: svg/animations/reinserting-svg-into-document.html
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::insertedInto): Don't call begin() on an already-started SMILTimeContainer().
* svg/animation/SMILTimeContainer.cpp:
(WebCore::SMILTimeContainer::isStarted): Added.
* svg/animation/SMILTimeContainer.h: Add isStarted().
* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::insertedInto): Always reschedule SVGSMILElements with
their parent SMILTimeContainer when they are inserted into the document, otherwise
they are lost (and never again update) when their subtree is removed and then
readded to the document.
Add a test that ensures that removing an SVG element from the document
and readding it continues SMIL animations.
* svg/animations/reinserting-svg-into-document.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127474 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/svg/animations/reinserting-svg-into-document.html b/LayoutTests/svg/animations/reinserting-svg-into-document.html
new file mode 100644
index 0000000..b71853ac
--- /dev/null
+++ b/LayoutTests/svg/animations/reinserting-svg-into-document.html
@@ -0,0 +1,43 @@
+<html>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/SVGAnimationTestCase.js"></script>
+<script>
+function load() {
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ svg = document.getElementById("svg");
+ rect = document.getElementById("rect");
+
+ setTimeout(function () {
+ svg.setCurrentTime(1);
+
+ document.body.removeChild(svg);
+ document.body.appendChild(svg);
+
+ setTimeout(function () {
+ shouldBeCloseEnough("rect.x.animVal.value", "30", 1);
+
+ svg.setCurrentTime(2);
+
+ shouldBeCloseEnough("rect.x.animVal.value", "60", 1);
+
+ if (window.testRunner)
+ testRunner.notifyDone();
+ }, 0);
+ }, 0);
+};
+</script>
+<body onload="load()">
+ <h1>Reinserting SVG animation into document should continue the animation</h1>
+ <p id="description"></p>
+ <div id="console"></div>
+ <svg id="svg" xmlns="http://www.w3.org/2000/svg">
+ <rect id="rect" x="0" y="0" width="20" height="20">
+ <animate attributeName="x" begin="0" from="0" to="90" dur="3s" fill="freeze" />
+ </rect>
+ </svg>
+</body>
+</html>