From c5e101b6e53e17824a227742213ac4fd1a7dbf37 Mon Sep 17 00:00:00 2001 From: nithin murali Date: Tue, 21 Apr 2015 14:34:40 -0400 Subject: [PATCH] Implement child reparenting and node removal during parsing. --- components/script/parse/html.rs | 18 ++++++++++++++---- tests/wpt/mozilla/meta/MANIFEST.json | 8 +++++++- .../tests/mozilla/child_reparenting.html | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/wpt/mozilla/tests/mozilla/child_reparenting.html diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 1424c72181c..73501809300 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -166,8 +166,11 @@ impl<'a> TreeSink for servohtmlparser::Sink { } } - fn remove_from_parent(&mut self, _target: JS) { - error!("remove_from_parent not implemented!"); + fn remove_from_parent(&mut self, target: JS) { + let node = target.root(); + if let Some(ref parent) = node.r().GetParentNode().root() { + parent.r().RemoveChild(node.r()).unwrap(); + } } fn mark_script_already_started(&mut self, node: JS) { @@ -182,8 +185,15 @@ impl<'a> TreeSink for servohtmlparser::Sink { script.map(|script| script.prepare()); } - fn reparent_children(&mut self, _node: JS, _new_parent: JS) { - panic!("unimplemented") + fn reparent_children(&mut self, node: JS, new_parent: JS) { + let new_parent = new_parent.root(); + let new_parent = new_parent.r(); + let old_parent = node.root(); + let old_parent = old_parent.r(); + while let Some(ref child) = old_parent.GetFirstChild().root() { + new_parent.AppendChild(child.r()).unwrap(); + } + } } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index efd18936509..5f01ff27f14 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -71,6 +71,12 @@ "url": "/_mozilla/mozilla/characterdata.html" } ], + "mozilla/child_reparenting.html": [ + { + "path": "mozilla/child_reparenting.html", + "url": "/_mozilla/mozilla/child_reparenting.html" + } + ], "mozilla/collections.html": [ { "path": "mozilla/collections.html", @@ -548,4 +554,4 @@ "rev": null, "url_base": "/_mozilla/", "version": 2 -} \ No newline at end of file +} diff --git a/tests/wpt/mozilla/tests/mozilla/child_reparenting.html b/tests/wpt/mozilla/tests/mozilla/child_reparenting.html new file mode 100644 index 00000000000..502a493ebb7 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/child_reparenting.html @@ -0,0 +1,14 @@ + + + + + +

+ + +