diff options
author | bors-servo <release+servo@mozilla.com> | 2013-10-11 07:51:59 -0700 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2013-10-11 07:51:59 -0700 |
commit | fc9fdf30a6b4b4437cfe7a624c52c9a8b5e5a645 (patch) | |
tree | 81e44e4c34830ca94d5dd7d21f4e5e19f85f43ad /src/components/script/dom/node.rs | |
parent | bc3eeb6f1c1b643df72b787ef772f20bcc094856 (diff) | |
parent | 9fe9145be4386ae38facc029946678fb0a54c2f7 (diff) | |
download | servo-fc9fdf30a6b4b4437cfe7a624c52c9a8b5e5a645.tar.gz servo-fc9fdf30a6b4b4437cfe7a624c52c9a8b5e5a645.zip |
auto merge of #1018 : ttaubert/servo/nodelist, r=jdm
This should fix #652 and #775. I'm not sure if that's all that is needed to properly implement NodeList? Should we add tests somewhere? Sorry for any stupid stuff I might have done :)
r? @jdm
Diffstat (limited to 'src/components/script/dom/node.rs')
-rw-r--r-- | src/components/script/dom/node.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 1743c1acabe..46ddc57ec36 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -12,6 +12,7 @@ use dom::document::AbstractDocument; use dom::documenttype::DocumentType; use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId}; use dom::element::{HTMLStyleElementTypeId}; +use dom::nodelist::{NodeList}; use dom::htmlimageelement::HTMLImageElement; use dom::htmliframeelement::HTMLIFrameElement; use dom::text::Text; @@ -89,6 +90,9 @@ pub struct Node<View> { /// The document that this node belongs to. owner_doc: AbstractDocument, + /// The live list of children return by .childNodes. + child_list: Option<@mut NodeList>, + /// Layout information. Only the layout task may touch this data. priv layout_data: LayoutData, } @@ -496,6 +500,7 @@ impl Node<ScriptView> { prev_sibling: None, owner_doc: doc, + child_list: None, layout_data: LayoutData::new(), } @@ -570,7 +575,7 @@ impl Node<ScriptView> { } pub fn HasChildNodes(&self) -> bool { - false + self.first_child.is_some() } pub fn GetFirstChild(&self) -> Option<AbstractNode<ScriptView>> { @@ -632,6 +637,24 @@ impl Node<ScriptView> { } } + pub fn ChildNodes(&mut self, abstract_self: AbstractNode<ScriptView>) -> @mut NodeList { + match self.child_list { + None => { + let (scope, cx) = self.get_scope_and_cx(); + let list = NodeList::new_child_list(abstract_self, cx, scope); + self.child_list = Some(list); + list + } + Some(list) => list + } + } + + pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) { + let win = self.owner_doc.with_base(|doc| doc.window.unwrap()); + let cx = win.page.js_info.get_ref().js_compartment.cx.ptr; + (win.reflector().get_jsobject(), cx) + } + // http://dom.spec.whatwg.org/#concept-node-replace-all pub fn replace_all(&mut self, abstract_self: AbstractNode<ScriptView>, |