Skip to content

Commit

Permalink
Implement adopting steps
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Sep 6, 2015
1 parent 3f9b6f8 commit 00362b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
20 changes: 6 additions & 14 deletions components/script/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,24 +1415,16 @@ impl Node {
// https://dom.spec.whatwg.org/#concept-node-adopt
pub fn adopt(node: &Node, document: &Document) {
// Step 1.
let parent_node = node.GetParentNode();
match parent_node {
Some(ref parent) => {
Node::remove(node, parent, SuppressObserver::Unsuppressed);
}
None => (),
}

let old_doc = node.owner_doc();
// Step 2.
let node_doc = document_from_node(node);
if node_doc.r() != document {
node.remove_self();
if &*old_doc != document {
// Step 3.
for descendant in node.traverse_preorder() {
descendant.r().set_owner_doc(document);
descendant.set_owner_doc(document);
vtable_for(&descendant).adopting_steps(&old_doc);
}
}

// Step 3.
// If node is an element, it is _affected by a base URL change_.
}

// https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
Expand Down
9 changes: 8 additions & 1 deletion components/script/dom/virtualmethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ pub trait VirtualMethods {
}
}

/// https://dom.spec.whatwg.org/#concept-node-clone (step 5)
/// https://dom.spec.whatwg.org/#concept-node-adopt-ext
fn adopting_steps(&self, old_doc: &Document) {
if let Some(ref s) = self.super_type() {
s.adopting_steps(old_doc);
}
}

/// https://dom.spec.whatwg.org/#concept-node-clone-ext
fn cloning_steps(&self, copy: &Node, maybe_doc: Option<&Document>,
clone_children: CloneChildrenFlag) {
if let Some(ref s) = self.super_type() {
Expand Down

0 comments on commit 00362b2

Please sign in to comment.