diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 0671bbd8bf7..e2716bfca83 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -46,6 +46,10 @@ pub struct AbstractNode { priv obj: *mut Node, } +pub struct AbstractNodeChildrenIterator { + priv current_node: Option>, +} + /// An HTML node. /// /// `View` describes extra data associated with this node that this task has access to. For @@ -200,7 +204,7 @@ impl TreeNodeRef> for AbstractNode { } } -impl AbstractNode { +impl<'self, View> AbstractNode { // Unsafe accessors /// Returns the layout data, unsafely cast to whatever type layout wishes. Only layout is @@ -396,6 +400,22 @@ impl AbstractNode { pub fn debug_str(&self) -> ~str { fmt!("%?", self.type_id()) } + + pub fn children(&self) -> AbstractNodeChildrenIterator { + AbstractNodeChildrenIterator { + current_node: self.first_child(), + } + } +} + +impl Iterator> for AbstractNodeChildrenIterator { + pub fn next(&mut self) -> Option> { + self.current_node = match self.current_node { + None => None, + Some(node) => node.next_sibling(), + }; + self.current_node + } } impl Node { diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 72eac9c51ed..d9dd9cc5636 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -275,24 +275,7 @@ pub fn parse_html(url: Url, parser.set_document_node(unsafe { root.to_hubbub_node() }); parser.enable_scripting(true); - // Performs various actions necessary after appending has taken place. Currently, this - // consists of processing inline stylesheets, but in the future it might perform - // prefetching, etc. - let css_chan2 = css_chan.clone(); - let append_hook: ~fn(AbstractNode, AbstractNode) = |parent_node, child_node| { - if parent_node.is_style_element() && child_node.is_text() { - debug!("found inline CSS stylesheet"); - let url = url::from_str("http://example.com/"); // FIXME - let url_cell = Cell::new(url); - do child_node.with_imm_text |text_node| { - let data = text_node.parent.data.to_str(); // FIXME: Bad copy. - let provenance = InlineProvenance(result::unwrap(url_cell.take()), data); - css_chan2.send(CSSTaskNewFile(provenance)); - } - } - }; - - let (css_chan2, js_chan2) = (css_chan.clone(), js_chan.clone()); + let (css_chan2, css_chan3, js_chan2) = (css_chan.clone(), css_chan.clone(), js_chan.clone()); parser.set_tree_handler(~hubbub::TreeHandler { create_comment: |data: ~str| { debug!("create comment"); @@ -393,15 +376,32 @@ pub fn parse_html(url: Url, Node::as_abstract_node(~Text::new(data)).to_hubbub_node() } }, - ref_node: |_| {}, - unref_node: |_| {}, + ref_node: |_| { debug!("ref node"); }, + unref_node: |node| { + // check for the end of a

I am a paragraph. My background color is blue.

I am a paragraph. My background color is red.

\ No newline at end of file