From 22a6485708658cc306cc2fbf25d8f59dd4684fec Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Mar 2014 18:52:49 +0100 Subject: [PATCH 1/4] Move Node::Children to a better place. --- src/components/script/dom/node.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index f323421a8d7..56b3b853b48 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -873,6 +873,20 @@ impl Node { self.first_child.is_some() } + // http://dom.spec.whatwg.org/#dom-node-childnodes + pub fn ChildNodes(&mut self, abstract_self: &JS) -> JS { + 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 pub fn GetFirstChild(&self) -> Option> { self.first_child.clone() @@ -942,20 +956,6 @@ impl Node { } } - // http://dom.spec.whatwg.org/#dom-node-childnodes - pub fn ChildNodes(&mut self, abstract_self: &JS) -> JS { - 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/#concept-node-adopt fn adopt(node: &mut JS, document: &JS) { // Step 1. From daf9cf8b9df34aee0a882cc462507746e86b8144 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Mar 2014 18:53:20 +0100 Subject: [PATCH 2/4] Move Node::SetTextContent to a better place. --- src/components/script/dom/node.rs | 70 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 56b3b853b48..98c61716b75 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -956,6 +956,41 @@ impl Node { } } + // http://dom.spec.whatwg.org/#dom-node-textcontent + pub fn SetTextContent(&mut self, abstract_self: &mut JS, value: Option) + -> 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 = 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 fn adopt(node: &mut JS, document: &JS) { // Step 1. @@ -1227,41 +1262,6 @@ impl Node { } } - // http://dom.spec.whatwg.org/#dom-node-textcontent - pub fn SetTextContent(&mut self, abstract_self: &mut JS, value: Option) - -> 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 = 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 pub fn InsertBefore(&self, abstract_self: &mut JS, node: &mut JS, child: Option>) -> Fallible> { From 933f29f5127a131477012f9a302f52478f035bd0 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Mar 2014 18:53:43 +0100 Subject: [PATCH 3/4] Match the spec more closely in Node.webidl. --- src/components/script/dom/webidls/Node.webidl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/script/dom/webidls/Node.webidl b/src/components/script/dom/webidls/Node.webidl index f21d528be26..bc1c45ade9f 100644 --- a/src/components/script/dom/webidls/Node.webidl +++ b/src/components/script/dom/webidls/Node.webidl @@ -50,14 +50,6 @@ interface Node : EventTarget { attribute DOMString? nodeValue; [SetterThrows, Pure] 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(); [Throws] @@ -69,7 +61,7 @@ interface Node : EventTarget { const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; 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); boolean contains(Node? other); @@ -77,6 +69,15 @@ interface Node : EventTarget { DOMString? lookupNamespaceURI(DOMString? prefix); 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 // These have been moved to Element in the spec. // If we move namespaceURI, prefix and localName to Element they should return From efde051666d8a5e3af5ceee2f2752dd75a5737f5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 5 Mar 2014 18:54:20 +0100 Subject: [PATCH 4/4] Add pointers to specific issues in node.rs. --- src/components/script/dom/node.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 98c61716b75..4efa6ddbf9a 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -840,6 +840,7 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-baseuri pub fn GetBaseURI(&self) -> Option { + // FIXME (#1824) implement. None } @@ -925,7 +926,7 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-nodevalue pub fn SetNodeValue(&mut self, _abstract_self: &JS, _val: Option) -> ErrorResult { - // FIXME: Stub - https://github.com/mozilla/servo/issues/1655 + // FIXME (#1825) implement. Ok(()) } @@ -1415,7 +1416,7 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-normalize 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 @@ -1500,7 +1501,7 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition pub fn CompareDocumentPosition(&self, _other: &JS) -> u16 { - // FIXME: stub - https://github.com/mozilla/servo/issues/1655 + // FIXME (#1794) implement. 0 } @@ -1514,19 +1515,19 @@ impl Node { // http://dom.spec.whatwg.org/#dom-node-lookupprefix pub fn LookupPrefix(&self, _prefix: Option) -> Option { - // FIXME: stub - https://github.com/mozilla/servo/issues/1655 + // FIXME (#1826) implement. None } // http://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri pub fn LookupNamespaceURI(&self, _namespace: Option) -> Option { - // FIXME: stub - https://github.com/mozilla/servo/issues/1655 + // FIXME (#1826) implement. None } // http://dom.spec.whatwg.org/#dom-node-isdefaultnamespace pub fn IsDefaultNamespace(&self, _namespace: Option) -> bool { - // FIXME: stub - https://github.com/mozilla/servo/issues/1655 + // FIXME (#1826) implement. false }