aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2013-10-10 22:09:34 +0200
committerMs2ger <ms2ger@gmail.com>2013-10-10 22:09:34 +0200
commita5233f2bc48ef10d93e19820458d17b771d97430 (patch)
tree66bd47327d7c7e8b01192a279bbc3108c3270102
parent9d04be98e56f93c5ddfe6c1113707644b8ede413 (diff)
downloadservo-a5233f2bc48ef10d93e19820458d17b771d97430.tar.gz
servo-a5233f2bc48ef10d93e19820458d17b771d97430.zip
Support Node.nodeType and Node.nodeValue.
-rw-r--r--src/components/script/dom/bindings/codegen/Bindings.conf8
-rw-r--r--src/components/script/dom/node.rs72
2 files changed, 63 insertions, 17 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf
index 5d50be2ecd0..de6d5be0435 100644
--- a/src/components/script/dom/bindings/codegen/Bindings.conf
+++ b/src/components/script/dom/bindings/codegen/Bindings.conf
@@ -294,7 +294,13 @@ DOMInterfaces = {
'nativeType': 'AbstractNode<ScriptView>',
'concreteType': 'Node<ScriptView>',
'pointerType': '',
- 'needsAbstract': ['appendChild', 'removeChild', 'textContent']
+ 'needsAbstract': [
+ 'appendChild',
+ 'nodeName',
+ 'nodeValue',
+ 'removeChild',
+ 'textContent',
+ ]
},
'NodeList': [
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index 49b2e982fd9..b345b489308 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -9,6 +9,7 @@ use dom::bindings::utils::{Reflector, DOMString, ErrorResult, Fallible, NotFound
use dom::bindings::utils::{BindingObject, Reflectable, null_str_as_empty};
use dom::characterdata::CharacterData;
use dom::document::AbstractDocument;
+use dom::documenttype::DocumentType;
use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId};
use dom::element::{HTMLStyleElementTypeId};
use dom::htmlimageelement::HTMLImageElement;
@@ -267,6 +268,20 @@ impl<'self, View> AbstractNode<View> {
self.type_id() == DoctypeNodeTypeId
}
+ pub fn with_imm_doctype<R>(self, f: &fn(&DocumentType<View>) -> R) -> R {
+ if !self.is_doctype() {
+ fail!(~"node is not doctype");
+ }
+ self.transmute(f)
+ }
+
+ pub fn with_mut_doctype<R>(self, f: &fn(&mut DocumentType<View>) -> R) -> R {
+ if !self.is_doctype() {
+ fail!(~"node is not doctype");
+ }
+ self.transmute_mut(f)
+ }
+
pub fn is_comment(self) -> bool {
self.type_id() == CommentNodeTypeId
}
@@ -486,15 +501,6 @@ impl Node<ScriptView> {
}
}
- pub fn getNodeType(&self) -> i32 {
- match self.type_id {
- ElementNodeTypeId(_) => 1,
- TextNodeTypeId => 3,
- CommentNodeTypeId => 8,
- DoctypeNodeTypeId => 10
- }
- }
-
pub fn getNextSibling(&mut self) -> Option<&mut AbstractNode<ScriptView>> {
match self.next_sibling {
// transmute because the compiler can't deduce that the reference
@@ -516,11 +522,29 @@ impl Node<ScriptView> {
impl Node<ScriptView> {
pub fn NodeType(&self) -> u16 {
- 0
+ match self.type_id {
+ ElementNodeTypeId(_) => 1,
+ TextNodeTypeId => 3,
+ CommentNodeTypeId => 8,
+ DoctypeNodeTypeId => 10
+ }
}
- pub fn NodeName(&self) -> DOMString {
- None
+ pub fn NodeName(&self, abstract_self: AbstractNode<ScriptView>) -> DOMString {
+ Some(match self.type_id {
+ ElementNodeTypeId(*) => {
+ do abstract_self.with_imm_element |element| {
+ element.TagName().expect("tagName should never be null")
+ }
+ }
+ CommentNodeTypeId => ~"#comment",
+ TextNodeTypeId => ~"#text",
+ DoctypeNodeTypeId => {
+ do abstract_self.with_imm_doctype |doctype| {
+ doctype.name.clone()
+ }
+ }
+ })
}
pub fn GetBaseURI(&self) -> DOMString {
@@ -528,7 +552,13 @@ impl Node<ScriptView> {
}
pub fn GetOwnerDocument(&self) -> Option<AbstractDocument> {
- None
+ match self.type_id {
+ ElementNodeTypeId(*) |
+ CommentNodeTypeId |
+ TextNodeTypeId |
+ DoctypeNodeTypeId => Some(self.owner_doc),
+ // DocumentNodeTypeId => None
+ }
}
pub fn GetParentNode(&self) -> Option<AbstractNode<ScriptView>> {
@@ -559,11 +589,21 @@ impl Node<ScriptView> {
self.next_sibling
}
- pub fn GetNodeValue(&self) -> DOMString {
- None
+ pub fn GetNodeValue(&self, abstract_self: AbstractNode<ScriptView>) -> DOMString {
+ match self.type_id {
+ // ProcessingInstruction
+ CommentNodeTypeId | TextNodeTypeId => {
+ do abstract_self.with_imm_characterdata() |characterdata| {
+ characterdata.Data()
+ }
+ }
+ _ => {
+ None
+ }
+ }
}
- pub fn SetNodeValue(&mut self, _val: &DOMString) -> ErrorResult {
+ pub fn SetNodeValue(&mut self, _abstract_self: AbstractNode<ScriptView>, _val: &DOMString) -> ErrorResult {
Ok(())
}