servo: Merge #609 - Fix broken inline CSS (from metajack:broken-css); r=pcwalton
authorJack Moffitt <jack@metajack.im>
Fri, 19 Jul 2013 18:12:22 -0700
changeset 333530 b139f325526e2fc0f0da1732661797c1b0c060d6
parent 333529 a59efaa30e017290d4aeac66db439ac39647d6c4
child 333531 364b352d07a5355f9b814e7367afd1a5ccecb7a4
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
servo: Merge #609 - Fix broken inline CSS (from metajack:broken-css); r=pcwalton The fix for #606 broke all inline CSS, and this fixes it correctly. Source-Repo: https://github.com/servo/servo Source-Revision: 841b91f1b607635dc7fb2762b6f7e85c52f67589
servo/src/components/script/dom/node.rs
servo/src/components/script/html/hubbub_html_parser.rs
--- a/servo/src/components/script/dom/node.rs
+++ b/servo/src/components/script/dom/node.rs
@@ -405,21 +405,22 @@ impl<'self, View> AbstractNode<View> {
         AbstractNodeChildrenIterator {
             current_node: self.first_child(),
         }
     }
 }
 
 impl<View> Iterator<AbstractNode<View>> for AbstractNodeChildrenIterator<View> {
     pub fn next(&mut self) -> Option<AbstractNode<View>> {
+        let node = self.current_node;
         self.current_node = match self.current_node {
             None => None,
             Some(node) => node.next_sibling(),
         };
-        self.current_node
+        node
     }
 }
 
 impl Node<ScriptView> {
     pub unsafe fn as_abstract_node<N>(node: ~N) -> AbstractNode<ScriptView> {
         // This surrenders memory management of the node!
         let mut node = AbstractNode {
             obj: transmute(node),
--- a/servo/src/components/script/html/hubbub_html_parser.rs
+++ b/servo/src/components/script/html/hubbub_html_parser.rs
@@ -269,16 +269,17 @@ pub fn parse_html(url: Url,
     // Build the root node.
     let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
     let root = unsafe { Node::as_abstract_node(root) };
     debug!("created new node");
     let mut parser = hubbub::Parser("UTF-8", false);
     debug!("created parser");
     parser.set_document_node(unsafe { root.to_hubbub_node() });
     parser.enable_scripting(true);
+    parser.enable_styling(true);
 
     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");
             unsafe {
                 Node::as_abstract_node(~Comment::new(data)).to_hubbub_node()
             }
@@ -371,36 +372,18 @@ pub fn parse_html(url: Url,
             unsafe { node.to_hubbub_node() }
         },
         create_text: |data: ~str| {
             debug!("create text");
             unsafe {
                 Node::as_abstract_node(~Text::new(data)).to_hubbub_node()
             }
         },
-        ref_node: |_| { debug!("ref node"); },
-        unref_node: |node| {
-            // check for the end of a <style> so we can submit all the text to the parser.
-            unsafe {
-                let node: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(node);
-                if node.is_style_element() {
-                    let url = url::from_str("http://example.com/"); // FIXME
-                    let url_cell = Cell::new(url);
-
-                    let mut data = ~[];
-                    for node.children().advance |child| {
-                        do child.with_imm_text() |text| {
-                            data.push(text.parent.data.to_str());  // FIXME: Bad copy.
-                        }
-                    }
-                    let provenance = InlineProvenance(result::unwrap(url_cell.take()), data.concat());
-                    css_chan3.send(CSSTaskNewFile(provenance));
-                }
-            }
-        },
+        ref_node: |_| {},
+        unref_node: |_| {},
         append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| {
             unsafe {
                 debug!("append child %x %x", cast::transmute(parent), cast::transmute(child));
                 let parent: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(parent);
                 let child: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(child);
                 parent.add_child(child);
             }
             child
@@ -459,17 +442,38 @@ pub fn parse_html(url: Url,
                             }
                             None => {}
                         }
                     }
                 }
             }
             complete_script(script, url3.clone(), js_chan2.clone());
             debug!("complete script");
-        }
+        },
+        complete_style: |style| {
+            // We've reached the end of a <style> so we can submit all the text to the parser.
+            unsafe {
+                let style: AbstractNode<ScriptView> = NodeWrapping::from_hubbub_node(style);
+                let url = url::from_str("http://example.com/"); // FIXME
+                let url_cell = Cell::new(url);
+
+                let mut data = ~[];
+                debug!("iterating over children %?", style.first_child());
+                for style.children().advance |child| {
+                    debug!("child = %?", child);
+                    do child.with_imm_text() |text| {
+                        data.push(text.parent.data.to_str());  // FIXME: Bad copy.
+                    }
+                }
+
+                debug!("data = %?", data);
+                let provenance = InlineProvenance(result::unwrap(url_cell.take()), data.concat());
+                css_chan3.send(CSSTaskNewFile(provenance));
+            }
+        },
     });
     debug!("set tree handler");
 
     let (input_port, input_chan) = comm::stream();
     resource_task.send(Load(url.clone(), input_chan));
     debug!("loaded page");
     loop {
         match input_port.recv() {