auto merge of #1827 : Ms2ger/servo/Node, r=jdm

This commit is contained in:
bors-servo 2014-03-05 14:01:33 -05:00
commit a2c611e8f1
2 changed files with 62 additions and 60 deletions

View file

@ -840,6 +840,7 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-baseuri // http://dom.spec.whatwg.org/#dom-node-baseuri
pub fn GetBaseURI(&self) -> Option<DOMString> { pub fn GetBaseURI(&self) -> Option<DOMString> {
// FIXME (#1824) implement.
None None
} }
@ -873,6 +874,20 @@ impl Node {
self.first_child.is_some() self.first_child.is_some()
} }
// http://dom.spec.whatwg.org/#dom-node-childnodes
pub fn ChildNodes(&mut self, abstract_self: &JS<Node>) -> JS<NodeList> {
match self.child_list {
None => {
let doc = self.owner_doc();
let doc = doc.get();
let list = NodeList::new_child_list(&doc.window, abstract_self);
self.child_list = Some(list.clone());
list
}
Some(ref list) => list.clone()
}
}
// http://dom.spec.whatwg.org/#dom-node-firstchild // http://dom.spec.whatwg.org/#dom-node-firstchild
pub fn GetFirstChild(&self) -> Option<JS<Node>> { pub fn GetFirstChild(&self) -> Option<JS<Node>> {
self.first_child.clone() self.first_child.clone()
@ -911,7 +926,7 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-nodevalue // http://dom.spec.whatwg.org/#dom-node-nodevalue
pub fn SetNodeValue(&mut self, _abstract_self: &JS<Node>, _val: Option<DOMString>) pub fn SetNodeValue(&mut self, _abstract_self: &JS<Node>, _val: Option<DOMString>)
-> ErrorResult { -> ErrorResult {
// FIXME: Stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1825) implement.
Ok(()) Ok(())
} }
@ -942,18 +957,39 @@ impl Node {
} }
} }
// http://dom.spec.whatwg.org/#dom-node-childnodes // http://dom.spec.whatwg.org/#dom-node-textcontent
pub fn ChildNodes(&mut self, abstract_self: &JS<Node>) -> JS<NodeList> { pub fn SetTextContent(&mut self, abstract_self: &mut JS<Node>, value: Option<DOMString>)
match self.child_list { -> ErrorResult {
None => { let value = null_str_as_empty(&value);
let doc = self.owner_doc(); match self.type_id {
let doc = doc.get(); DocumentFragmentNodeTypeId |
let list = NodeList::new_child_list(&doc.window, abstract_self); ElementNodeTypeId(..) => {
self.child_list = Some(list.clone()); // Step 1-2.
list let node = if value.len() == 0 {
None
} else {
let document = self.owner_doc();
Some(NodeCast::from(&document.get().CreateTextNode(&document, value)))
};
// Step 3.
Node::replace_all(node, abstract_self);
} }
Some(ref list) => list.clone() CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom();
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
characterdata.get_mut().data = value.clone();
// Notify the document that the content of this node is different
let document = self.owner_doc();
document.get().content_changed();
}
DoctypeNodeTypeId |
DocumentNodeTypeId => {}
} }
Ok(())
} }
// http://dom.spec.whatwg.org/#concept-node-adopt // http://dom.spec.whatwg.org/#concept-node-adopt
@ -1227,41 +1263,6 @@ impl Node {
} }
} }
// http://dom.spec.whatwg.org/#dom-node-textcontent
pub fn SetTextContent(&mut self, abstract_self: &mut JS<Node>, value: Option<DOMString>)
-> ErrorResult {
let value = null_str_as_empty(&value);
match self.type_id {
DocumentFragmentNodeTypeId |
ElementNodeTypeId(..) => {
// Step 1-2.
let node = if value.len() == 0 {
None
} else {
let document = self.owner_doc();
Some(NodeCast::from(&document.get().CreateTextNode(&document, value)))
};
// Step 3.
Node::replace_all(node, abstract_self);
}
CommentNodeTypeId |
TextNodeTypeId |
ProcessingInstructionNodeTypeId => {
self.wait_until_safe_to_modify_dom();
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
characterdata.get_mut().data = value.clone();
// Notify the document that the content of this node is different
let document = self.owner_doc();
document.get().content_changed();
}
DoctypeNodeTypeId |
DocumentNodeTypeId => {}
}
Ok(())
}
// http://dom.spec.whatwg.org/#dom-node-insertbefore // http://dom.spec.whatwg.org/#dom-node-insertbefore
pub fn InsertBefore(&self, abstract_self: &mut JS<Node>, node: &mut JS<Node>, child: Option<JS<Node>>) pub fn InsertBefore(&self, abstract_self: &mut JS<Node>, node: &mut JS<Node>, child: Option<JS<Node>>)
-> Fallible<JS<Node>> { -> Fallible<JS<Node>> {
@ -1415,7 +1416,7 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-normalize // http://dom.spec.whatwg.org/#dom-node-normalize
pub fn Normalize(&mut self) { pub fn Normalize(&mut self) {
// FIXME: stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1823) implement.
} }
// http://dom.spec.whatwg.org/#dom-node-clonenode // http://dom.spec.whatwg.org/#dom-node-clonenode
@ -1500,7 +1501,7 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
pub fn CompareDocumentPosition(&self, _other: &JS<Node>) -> u16 { pub fn CompareDocumentPosition(&self, _other: &JS<Node>) -> u16 {
// FIXME: stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1794) implement.
0 0
} }
@ -1514,19 +1515,19 @@ impl Node {
// http://dom.spec.whatwg.org/#dom-node-lookupprefix // http://dom.spec.whatwg.org/#dom-node-lookupprefix
pub fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString> { pub fn LookupPrefix(&self, _prefix: Option<DOMString>) -> Option<DOMString> {
// FIXME: stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1826) implement.
None None
} }
// http://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri // http://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri
pub fn LookupNamespaceURI(&self, _namespace: Option<DOMString>) -> Option<DOMString> { pub fn LookupNamespaceURI(&self, _namespace: Option<DOMString>) -> Option<DOMString> {
// FIXME: stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1826) implement.
None None
} }
// http://dom.spec.whatwg.org/#dom-node-isdefaultnamespace // http://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
pub fn IsDefaultNamespace(&self, _namespace: Option<DOMString>) -> bool { pub fn IsDefaultNamespace(&self, _namespace: Option<DOMString>) -> bool {
// FIXME: stub - https://github.com/mozilla/servo/issues/1655 // FIXME (#1826) implement.
false false
} }

View file

@ -50,14 +50,6 @@ interface Node : EventTarget {
attribute DOMString? nodeValue; attribute DOMString? nodeValue;
[SetterThrows, Pure] [SetterThrows, Pure]
attribute DOMString? textContent; attribute DOMString? textContent;
[Throws]
Node insertBefore(Node node, Node? child);
[Throws]
Node appendChild(Node node);
[Throws]
Node replaceChild(Node node, Node child);
[Throws]
Node removeChild(Node child);
void normalize(); void normalize();
[Throws] [Throws]
@ -69,7 +61,7 @@ interface Node : EventTarget {
const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04;
const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08;
const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; // historical const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
unsigned short compareDocumentPosition(Node other); unsigned short compareDocumentPosition(Node other);
boolean contains(Node? other); boolean contains(Node? other);
@ -77,6 +69,15 @@ interface Node : EventTarget {
DOMString? lookupNamespaceURI(DOMString? prefix); DOMString? lookupNamespaceURI(DOMString? prefix);
boolean isDefaultNamespace(DOMString? namespace); boolean isDefaultNamespace(DOMString? namespace);
[Throws]
Node insertBefore(Node node, Node? child);
[Throws]
Node appendChild(Node node);
[Throws]
Node replaceChild(Node node, Node child);
[Throws]
Node removeChild(Node child);
// Mozilla-specific stuff // Mozilla-specific stuff
// These have been moved to Element in the spec. // These have been moved to Element in the spec.
// If we move namespaceURI, prefix and localName to Element they should return // If we move namespaceURI, prefix and localName to Element they should return