From 54a916740aa5c0b1d9539721e5dd5fe5fe13a049 Mon Sep 17 00:00:00 2001 From: koko Date: Sat, 14 Sep 2024 01:06:21 +0200 Subject: [PATCH] fmt, clippy and some git weirdness --- Cargo.toml | 12 +-- packages/dom/src/htmlsink.rs | 144 ++++++++++++++++++----------------- packages/dom/src/stylo.rs | 13 ++++ packages/net/Cargo.toml | 11 --- packages/net/src/lib.rs | 94 ----------------------- packages/traits/Cargo.toml | 7 -- packages/traits/src/lib.rs | 1 - packages/traits/src/net.rs | 42 ---------- 8 files changed, 93 insertions(+), 231 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 92435c1a..e88517aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,12 @@ members = ["packages/blitz", "packages/dom", "packages/dioxus-blitz", "packages/ resolver = "2" [workspace.dependencies] -style = { git = "https://github.com/dioxuslabs/stylo", branch = "enable-table-moz-center-style-adjust" } -style_config = { git = "https://github.com/dioxuslabs/stylo", branch = "enable-table-moz-center-style-adjust" } -style_traits = { git = "https://github.com/dioxuslabs/stylo", branch = "enable-table-moz-center-style-adjust" } -style_dom = { git = "https://github.com/dioxuslabs/stylo", package = "dom", branch = "enable-table-moz-center-style-adjust" } -selectors = { git = "https://github.com/dioxuslabs/stylo", branch = "enable-table-moz-center-style-adjust" } -html5ever = "0.27" # needs to match stylo markup5ever version +style = { git = "https://github.com/dioxuslabs/stylo", branch = "blitz" } +style_config = { git = "https://github.com/dioxuslabs/stylo", branch = "blitz" } +style_traits = { git = "https://github.com/dioxuslabs/stylo", branch = "blitz" } +style_dom = { git = "https://github.com/dioxuslabs/stylo", package = "dom", branch = "blitz" } +selectors = { git = "https://github.com/dioxuslabs/stylo", branch = "blitz" } +html5ever = "0.29" # needs to match stylo markup5ever version taffy = { git = "https://github.com/dioxuslabs/taffy", rev = "950a0eb1322f15e5d1083f4793b55d52061718de" } parley = { git = "https://github.com/nicoburns/parley", rev = "029bf1df3e1829935fa6d25b875d3138f79a62c1" } dioxus = { git = "https://github.com/dioxuslabs/dioxus", rev = "a3aa6ae771a2d0a4d8cb6055c41efc0193b817ef" } diff --git a/packages/dom/src/htmlsink.rs b/packages/dom/src/htmlsink.rs index 2c9b7327..d5466236 100644 --- a/packages/dom/src/htmlsink.rs +++ b/packages/dom/src/htmlsink.rs @@ -1,15 +1,17 @@ -use crate::node::{Attribute, ElementNodeData, Node, NodeData}; use crate::util::{CssHandler, ImageHandler, Resource}; +use std::borrow::Cow; +use std::cell::{Cell, Ref, RefCell, RefMut}; +use std::collections::HashSet; + +use crate::node::{Attribute, ElementNodeData, Node, NodeData}; use crate::Document; use blitz_traits::net::SharedProvider; use html5ever::local_name; use html5ever::{ tendril::{StrTendril, TendrilSink}, tree_builder::{ElementFlags, NodeOrText, QuirksMode, TreeSink}, - ExpandedName, QualName, + QualName, }; -use std::borrow::Cow; -use std::collections::HashSet; /// Convert an html5ever Attribute which uses tendril for its value to a blitz Attribute /// which uses String. @@ -21,15 +23,15 @@ fn html5ever_to_blitz_attr(attr: html5ever::Attribute) -> Attribute { } pub struct DocumentHtmlParser<'a> { - doc: &'a mut Document, + doc: RefCell<&'a mut Document>, - style_nodes: Vec, + style_nodes: RefCell>, /// Errors that occurred during parsing. - pub errors: Vec>, + pub errors: RefCell>>, /// The document's quirks mode. - pub quirks_mode: QuirksMode, + pub quirks_mode: Cell, net_provider: SharedProvider, } @@ -37,10 +39,10 @@ pub struct DocumentHtmlParser<'a> { impl<'a> DocumentHtmlParser<'a> { pub fn new(doc: &mut Document, net_provider: SharedProvider) -> DocumentHtmlParser { DocumentHtmlParser { - doc, - style_nodes: Vec::new(), - errors: Vec::new(), - quirks_mode: QuirksMode::NoQuirks, + doc: RefCell::new(doc), + style_nodes: RefCell::new(Vec::new()), + errors: RefCell::new(Vec::new()), + quirks_mode: Cell::new(QuirksMode::NoQuirks), net_provider, } } @@ -57,27 +59,27 @@ impl<'a> DocumentHtmlParser<'a> { .unwrap() } - fn create_node(&mut self, node_data: NodeData) -> usize { - self.doc.create_node(node_data) + fn create_node(&self, node_data: NodeData) -> usize { + self.doc.borrow_mut().create_node(node_data) } - fn create_text_node(&mut self, text: &str) -> usize { - self.doc.create_text_node(text) + fn create_text_node(&self, text: &str) -> usize { + self.doc.borrow_mut().create_text_node(text) } - fn node(&self, id: usize) -> &Node { - &self.doc.nodes[id] + fn node(&self, id: usize) -> Ref { + Ref::map(self.doc.borrow(), |doc| &doc.nodes[id]) } - fn node_mut(&mut self, id: usize) -> &mut Node { - &mut self.doc.nodes[id] + fn node_mut(&self, id: usize) -> RefMut { + RefMut::map(self.doc.borrow_mut(), |doc| &mut doc.nodes[id]) } - fn try_append_text_to_text_node(&mut self, node_id: Option, text: &str) -> bool { + fn try_append_text_to_text_node(&self, node_id: Option, text: &str) -> bool { let Some(node_id) = node_id else { return false; }; - let node = self.node_mut(node_id); + let mut node = self.node_mut(node_id); match node.text_data_mut() { Some(data) => { @@ -88,41 +90,42 @@ impl<'a> DocumentHtmlParser<'a> { } } - fn last_child(&mut self, parent_id: usize) -> Option { + fn last_child(&self, parent_id: usize) -> Option { self.node(parent_id).children.last().copied() } - fn load_linked_stylesheet(&mut self, target_id: usize) { + fn load_linked_stylesheet(&self, target_id: usize) { let node = self.node(target_id); let rel_attr = node.attr(local_name!("rel")); let href_attr = node.attr(local_name!("href")); if let (Some("stylesheet"), Some(href)) = (rel_attr, href_attr) { - let url = self.doc.resolve_url(href); + let url = self.doc.borrow().resolve_url(href); + let guard = self.doc.borrow().guard.clone(); self.net_provider.fetch( url.clone(), Box::new(CssHandler { node: target_id, source_url: url, - guard: self.doc.guard.clone(), + guard, }), ); } } - fn load_image(&mut self, target_id: usize) { + fn load_image(&self, target_id: usize) { let node = self.node(target_id); if let Some(raw_src) = node.attr(local_name!("src")) { if !raw_src.is_empty() { - let src = self.doc.resolve_url(raw_src); + let src = self.doc.borrow().resolve_url(raw_src); self.net_provider .fetch(src, Box::new(ImageHandler::new(target_id))); } } } - fn process_button_input(&mut self, target_id: usize) { + fn process_button_input(&self, target_id: usize) { let node = self.node(target_id); let Some(data) = node.element_data() else { return; @@ -150,47 +153,52 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> { // we use the ID of the nodes in the tree as the handle type Handle = usize; + type ElemName<'a> = Ref<'a, QualName> where Self: 'a; + fn finish(self) -> Self::Output { + let doc = self.doc.into_inner(); + // Add inline stylesheets (