mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Add node.appendChild
This commit is contained in:
parent
47c5279e31
commit
0d4cfd0eb9
3 changed files with 44 additions and 4 deletions
|
@ -291,7 +291,7 @@ DOMInterfaces = {
|
||||||
'nativeType': 'AbstractNode<ScriptView>',
|
'nativeType': 'AbstractNode<ScriptView>',
|
||||||
'concreteType': 'Node<ScriptView>',
|
'concreteType': 'Node<ScriptView>',
|
||||||
'pointerType': '',
|
'pointerType': '',
|
||||||
'needsAbstract': ['removeChild']
|
'needsAbstract': ['appendChild', 'removeChild']
|
||||||
},
|
},
|
||||||
|
|
||||||
'NodeList': [
|
'NodeList': [
|
||||||
|
|
|
@ -797,6 +797,7 @@ impl DerivedWrapper for AbstractNode<ScriptView> {
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
FailureUnknown,
|
FailureUnknown,
|
||||||
NotFound,
|
NotFound,
|
||||||
|
HierarchyRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ErrorResult = Result<(), Error>;
|
pub type ErrorResult = Result<(), Error>;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements.
|
//! The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements.
|
||||||
|
|
||||||
use dom::bindings::node;
|
use dom::bindings::node;
|
||||||
use dom::bindings::utils::{WrapperCache, DOMString, null_string, str, ErrorResult, NotFound};
|
use dom::bindings::utils::{WrapperCache, DOMString, null_string, str, ErrorResult, NotFound, HierarchyRequest};
|
||||||
use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box};
|
use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box};
|
||||||
use dom::bindings;
|
use dom::bindings;
|
||||||
use dom::characterdata::CharacterData;
|
use dom::characterdata::CharacterData;
|
||||||
|
@ -263,6 +263,10 @@ impl<'self, View> AbstractNode<View> {
|
||||||
self.transmute_mut(f)
|
self.transmute_mut(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_doctype(self) -> bool {
|
||||||
|
self.type_id() == DoctypeNodeTypeId
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_comment(self) -> bool {
|
pub fn is_comment(self) -> bool {
|
||||||
self.type_id() == CommentNodeTypeId
|
self.type_id() == CommentNodeTypeId
|
||||||
}
|
}
|
||||||
|
@ -553,8 +557,43 @@ impl Node<ScriptView> {
|
||||||
fail!("stub")
|
fail!("stub")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn AppendChild(&mut self, _node: AbstractNode<ScriptView>, _rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
|
pub fn AppendChild(&mut self,
|
||||||
fail!("stub")
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
|
node: AbstractNode<ScriptView>,
|
||||||
|
rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
|
||||||
|
fn is_hierarchy_request_err(this_node: AbstractNode<ScriptView>,
|
||||||
|
new_child: AbstractNode<ScriptView>) -> bool {
|
||||||
|
if new_child.is_doctype() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if !this_node.is_element() {
|
||||||
|
// FIXME: This should also work for Document and DocumentFragments when they inherit from node.
|
||||||
|
// per jgraham
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if this_node == new_child {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for ancestor in this_node.ancestors() {
|
||||||
|
if ancestor == new_child {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_hierarchy_request_err(abstract_self, node) {
|
||||||
|
*rv = Err(HierarchyRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Should we handle WRONG_DOCUMENT_ERR here?
|
||||||
|
|
||||||
|
if rv.is_ok() {
|
||||||
|
// If the node already exists it is removed from current parent node.
|
||||||
|
node.parent_node().map(|parent| parent.remove_child(node));
|
||||||
|
abstract_self.add_child(node);
|
||||||
|
}
|
||||||
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ReplaceChild(&mut self, _node: AbstractNode<ScriptView>, _child: AbstractNode<ScriptView>, _rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
|
pub fn ReplaceChild(&mut self, _node: AbstractNode<ScriptView>, _child: AbstractNode<ScriptView>, _rv: &mut ErrorResult) -> AbstractNode<ScriptView> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue