diff --git a/packages/blitz-dom/src/document.rs b/packages/blitz-dom/src/document.rs index 066f1f7f..d8c349f9 100644 --- a/packages/blitz-dom/src/document.rs +++ b/packages/blitz-dom/src/document.rs @@ -1,6 +1,5 @@ use crate::events::{EventData, HitResult, RendererEvent}; use crate::node::{ImageData, NodeSpecificData, TextBrush}; -use crate::util::parse_svg; use crate::{ElementNodeData, Node, NodeData, TextNodeData, Viewport}; use app_units::Au; use html5ever::local_name; @@ -676,23 +675,6 @@ impl Document { self.add_stylesheet_for_node(sheet, target_id); } - pub fn process_svg_element(&mut self, target_id: usize) { - let outer_html = self.nodes[target_id].outer_html(); - println!("{}", outer_html); - match parse_svg(outer_html.as_bytes()) { - Ok(svg) => { - println!("SVG parsed successfully"); - self.nodes[target_id] - .element_data_mut() - .unwrap() - .node_specific_data = NodeSpecificData::Svg(svg); - } - Err(err) => { - dbg!(err); - } - }; - } - pub fn remove_user_agent_stylesheet(&mut self, contents: &str) { if let Some(sheet) = self.ua_stylesheets.remove(contents) { self.stylist.remove_stylesheet(sheet, &self.guard.read()); diff --git a/packages/blitz-dom/src/htmlsink.rs b/packages/blitz-dom/src/htmlsink.rs index 0baa9a04..507f787a 100644 --- a/packages/blitz-dom/src/htmlsink.rs +++ b/packages/blitz-dom/src/htmlsink.rs @@ -25,7 +25,6 @@ fn html5ever_to_blitz_attr(attr: html5ever::Attribute) -> Attribute { pub struct DocumentHtmlParser<'a> { doc: RefCell<&'a mut Document>, style_nodes: RefCell>, - svg_nodes: RefCell>, /// Errors that occurred during parsing. pub errors: RefCell>>, @@ -41,7 +40,6 @@ impl DocumentHtmlParser<'_> { DocumentHtmlParser { doc: RefCell::new(doc), style_nodes: RefCell::new(Vec::new()), - svg_nodes: RefCell::new(Vec::new()), errors: RefCell::new(Vec::new()), quirks_mode: Cell::new(QuirksMode::NoQuirks), net_provider, @@ -181,11 +179,6 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> { doc.process_style_element(*id); } - // Parse inline SVGs ( elements) - for id in self.svg_nodes.borrow().iter() { - doc.process_svg_element(*id); - } - for error in self.errors.borrow().iter() { println!("ERROR: {}", error); } @@ -240,7 +233,6 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> { "img" => self.load_image(id), "input" => self.process_button_input(id), "style" => self.style_nodes.borrow_mut().push(id), - "svg" => self.svg_nodes.borrow_mut().push(id), _ => {} } diff --git a/packages/blitz-dom/src/layout/construct.rs b/packages/blitz-dom/src/layout/construct.rs index cab14e0d..740e8847 100644 --- a/packages/blitz-dom/src/layout/construct.rs +++ b/packages/blitz-dom/src/layout/construct.rs @@ -22,7 +22,9 @@ use crate::{ ListItemLayout, ListItemLayoutPosition, Marker, NodeKind, NodeSpecificData, TextBrush, TextInputData, TextLayout, }, - stylo_to_parley, Document, ElementNodeData, Node, NodeData, + stylo_to_parley, + util::parse_svg, + Document, ElementNodeData, Node, NodeData, }; use super::table::build_table_context; @@ -64,6 +66,23 @@ pub(crate) fn collect_layout_children( } } + if matches!(tag_name, "svg") { + let outer_html = doc.get_node(container_node_id).unwrap().outer_html(); + match parse_svg(outer_html.as_bytes()) { + Ok(svg) => { + doc.get_node_mut(container_node_id) + .unwrap() + .element_data_mut() + .unwrap() + .node_specific_data = NodeSpecificData::Svg(svg); + } + Err(err) => { + dbg!(err); + } + }; + return; + } + //Only ol tags have start and reversed attributes let (mut index, reversed) = if tag_name == "ol" { ( @@ -759,7 +778,10 @@ pub(crate) fn build_inline_layout( (DisplayOutside::Inline, DisplayInside::Flow) => { let tag_name = &element_data.name.local; - if *tag_name == local_name!("img") || *tag_name == local_name!("input") { + if *tag_name == local_name!("img") + || *tag_name == local_name!("svg") + || *tag_name == local_name!("input") + { builder.push_inline_box(InlineBox { id: node_id as u64, // Overridden by push_inline_box method