From b713ff7125fc422d266a865a0278931cca65faa5 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 10:27:29 +1200 Subject: [PATCH 1/9] Add basic CI checks --- .github/workflows/ci.yml | 80 ++++++++++++++++++++++++++++++++++++++++ examples/dom_only.rs | 5 --- examples/font.rs | 1 - 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 examples/dom_only.rs delete mode 100644 examples/font.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..5d1b328b0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +on: + pull_request: + push: + branches: + - main + +name: CI + +env: + RUSTDOCFLAGS: "-D warnings" + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: "sparse" + +jobs: + + # MSRV check. + # Blitz only guarantees "latest stable". However we have this check here to ensure that we advertise + # our MSRV. We also make an effort not to increase MSRV in patch versions of Blitz. + # + # We only run `cargo build` (not `cargo test`) so as to avoid requiring dev-dependencies to build with the MSRV + # version. Building is likely sufficient as runtime errors varying between rust versions is very unlikely. + build-msrv: + name: "MSRV Build [Rust 1.79]" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.79 + - run: sudo apt install libgtk-3-dev + - run: cargo build --workspace + + + build-features-default: + name: "Build [default features]" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: sudo apt install libgtk-3-dev + - run: cargo build --workspace + # - run: cargo test + + test-features-default: + name: "Test [default features]" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo test + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt + - run: cargo fmt --all --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: clippy + - run: sudo apt install libgtk-3-dev + - run: cargo clippy --workspace -- -D warnings + + doc: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo doc diff --git a/examples/dom_only.rs b/examples/dom_only.rs deleted file mode 100644 index 71265007b..000000000 --- a/examples/dom_only.rs +++ /dev/null @@ -1,5 +0,0 @@ -use blitz_dom::Document; - -fn main() { - let document = Document::new(); -} diff --git a/examples/font.rs b/examples/font.rs deleted file mode 100644 index 8b1378917..000000000 --- a/examples/font.rs +++ /dev/null @@ -1 +0,0 @@ - From e150874e046605c242ace17a5dbbe4579c527055 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 11:56:39 +1200 Subject: [PATCH 2/9] Fix most clippy lints --- .../src/documents/dioxus_document.rs | 6 +++--- .../src/documents/html_document.rs | 6 +++--- packages/dom/src/htmlsink.rs | 3 +-- packages/dom/src/stylo.rs | 3 +-- packages/dom/src/util.rs | 18 +++++++++++------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/dioxus-blitz/src/documents/dioxus_document.rs b/packages/dioxus-blitz/src/documents/dioxus_document.rs index 82655f28b..f40d6ee03 100644 --- a/packages/dioxus-blitz/src/documents/dioxus_document.rs +++ b/packages/dioxus-blitz/src/documents/dioxus_document.rs @@ -48,9 +48,9 @@ impl AsMut for DioxusDocument { &mut self.inner } } -impl Into for DioxusDocument { - fn into(self) -> Document { - self.inner +impl From for Document { + fn from(doc: DioxusDocument) -> Document { + doc.inner } } impl DocumentLike for DioxusDocument { diff --git a/packages/dioxus-blitz/src/documents/html_document.rs b/packages/dioxus-blitz/src/documents/html_document.rs index 22922d1a9..aa520f6ff 100644 --- a/packages/dioxus-blitz/src/documents/html_document.rs +++ b/packages/dioxus-blitz/src/documents/html_document.rs @@ -19,9 +19,9 @@ impl AsMut for HtmlDocument { &mut self.inner } } -impl Into for HtmlDocument { - fn into(self) -> Document { - self.inner +impl From for Document { + fn from(doc: HtmlDocument) -> Document { + doc.inner } } impl DocumentLike for HtmlDocument {} diff --git a/packages/dom/src/htmlsink.rs b/packages/dom/src/htmlsink.rs index 98e4fba20..c2b205073 100644 --- a/packages/dom/src/htmlsink.rs +++ b/packages/dom/src/htmlsink.rs @@ -270,8 +270,7 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> { if has_appended { return; } else { - let id = self.create_text_node(&text); - id + self.create_text_node(&text) } } NodeOrText::AppendNode(id) => id, diff --git a/packages/dom/src/stylo.rs b/packages/dom/src/stylo.rs index 0334f01d1..10e99f6ef 100644 --- a/packages/dom/src/stylo.rs +++ b/packages/dom/src/stylo.rs @@ -815,8 +815,7 @@ impl<'a> TElement for BlitzNode<'a> { let root_element = TDocument::as_node(&root_node) .first_element_child() .unwrap(); - let is_child_of_root_element = root_element.children.contains(&self.id); - is_child_of_root_element + root_element.children.contains(&self.id) } fn synthesize_presentational_hints_for_legacy_attributes( diff --git a/packages/dom/src/util.rs b/packages/dom/src/util.rs index 03ff0f92c..bacd07c65 100644 --- a/packages/dom/src/util.rs +++ b/packages/dom/src/util.rs @@ -6,14 +6,17 @@ use image::DynamicImage; const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"; const FILE_SIZE_LIMIT: u64 = 1_000_000_000; // 1GB -pub(crate) fn fetch_blob(url: &str) -> Result, ureq::Error> { +pub(crate) fn fetch_blob(url: &str) -> Result, Box> { if url.starts_with("data:") { let data_url = data_url::DataUrl::process(url).unwrap(); let decoded = data_url.decode_to_vec().expect("Invalid data url"); return Ok(decoded.0); } - let resp = ureq::get(url).set("User-Agent", USER_AGENT).call()?; + let resp = ureq::get(url) + .set("User-Agent", USER_AGENT) + .call() + .map_err(Box::new)?; let len: usize = resp .header("Content-Length") @@ -23,12 +26,13 @@ pub(crate) fn fetch_blob(url: &str) -> Result, ureq::Error> { resp.into_reader() .take(FILE_SIZE_LIMIT) - .read_to_end(&mut bytes)?; + .read_to_end(&mut bytes) + .unwrap(); Ok(bytes) } -pub(crate) fn fetch_string(url: &str) -> Result { +pub(crate) fn fetch_string(url: &str) -> Result> { fetch_blob(url).map(|vec| String::from_utf8(vec).expect("Invalid UTF8")) } @@ -41,11 +45,11 @@ pub(crate) fn fetch_string(url: &str) -> Result { #[allow(unused)] pub(crate) enum ImageFetchErr { - FetchErr(ureq::Error), + FetchErr(Box), ImageError(image::error::ImageError), } -impl From for ImageFetchErr { - fn from(value: ureq::Error) -> Self { +impl From> for ImageFetchErr { + fn from(value: Box) -> Self { Self::FetchErr(value) } } From 8370f062376b55590b1f2ce7a3e37b2b73bf76d3 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 12:01:14 +1200 Subject: [PATCH 3/9] Comment out stylo test --- examples/tailwind.rs | 2 +- tests/stylo_usage.rs | 315 +++++++++++++++++++++---------------------- 2 files changed, 158 insertions(+), 159 deletions(-) diff --git a/examples/tailwind.rs b/examples/tailwind.rs index 73508c870..807606d9b 100644 --- a/examples/tailwind.rs +++ b/examples/tailwind.rs @@ -13,7 +13,7 @@ fn main() { fn app() -> Element { rsx! { style { {CSS} } - for row in 0..3 { + for _row in 0..3 { div { class: "flex flex-row", div { id: "cool", "h123456789asdjkahskj\nhiiiii" } p { class: "cool", "hi" } diff --git a/tests/stylo_usage.rs b/tests/stylo_usage.rs index 7cbcc3f40..5cecdb614 100644 --- a/tests/stylo_usage.rs +++ b/tests/stylo_usage.rs @@ -1,158 +1,157 @@ -pub use blitz::style_impls::{BlitzNode, RealDom}; -use dioxus::prelude::*; -use style::{ - animation::DocumentAnimationSet, - context::{QuirksMode, SharedStyleContext}, - driver, - global_style_data::GLOBAL_STYLE_DATA, - media_queries::MediaType, - media_queries::{Device as StyleDevice, MediaList}, - selector_parser::SnapshotMap, - servo_arc::Arc, - shared_lock::{SharedRwLock, StylesheetGuards}, - stylesheets::{AllowImportRules, DocumentStyleSheet, Origin, Stylesheet}, - stylist::Stylist, - thread_state::ThreadState, - traversal::DomTraversal, - traversal_flags::TraversalFlags, -}; - -fn main() { - let css = r#" - h1 { - background-color: red; - } - - h2 { - background-color: green; - } - - h3 { - background-color: blue; - } - - h4 { - background-color: yellow; - } - - "#; - - let nodes = rsx! { - h1 { } - h2 { } - h3 { } - h4 { } - }; - - let styled_dom = style_lazy_nodes(css, nodes); - - // print_styles(&styled_dom); -} - -pub fn style_lazy_nodes(css: &str, markup: LazyNodes) -> RealDom { - const QUIRKS_MODE: QuirksMode = QuirksMode::NoQuirks; - - // Figured out a single-pass system from the servo repo itself: - // - // components/layout_thread_2020/lib.rs:795 - // handle_reflow - // tests/unit/style/custom_properties.rs - style::thread_state::enter(ThreadState::LAYOUT); - - // make the guards that we use to thread everything together - let guard = SharedRwLock::new(); - let guards = StylesheetGuards { - author: &guard.read(), - ua_or_user: &guard.read(), - }; - - // Make some CSS - let stylesheet = Stylesheet::from_str( - css, - servo_url::ServoUrl::from_url("data:text/css;charset=utf-8;base64,".parse().unwrap()), - Origin::UserAgent, - Arc::new(guard.wrap(MediaList::empty())), - guard.clone(), - None, - None, - QUIRKS_MODE, - 0, - AllowImportRules::Yes, - ); - - // Make the real domtree by converting dioxus vnodes - let markup = RealDom::from_dioxus(markup); - - // Now we need to do what handle_reflow does in servo - // Reflows should be fast due to caching in the Stylist object - // - // - // We can force reflows. Happens in the script/document section - // The browser keeps track of pending restyles itself when attributes are changed. - // When something like val.set_attribute() happens, the pending reflow is inserted into the list. - // Once ticks are finished, the ScriptReflow object is created and sent to the layout thread. - // The layout thread uses the ScriptReflow object to inform itself on what changes need to happen. - // Zooming and touching causes full reflows. - // For this demo we want to do complete reflows (have yet to figure it out) - // But eventually we'll want to queue up modifications to the ECS engine and then build the script-reflow type object. - // Unfortunately, this API assumes nodes are backed by pointers which adds some unsafe where we wouldn't want it. - // - // Reflow allows us to specify a dirty root node and a list of nodes to reflow. - // - // Notes: - // - https://developers.google.com/speed/docs/insights/browser-reflow - // - components/script/dom/window.rs:force_reflow - // - // Create a styling context for use throughout the following passes. - // In servo we'd also create a layout context, but since servo isn't updated with the new layout code, we're just using the styling context - // In a different world we'd use both - // Build the stylist object from our screen requirements - // Todo: pull this in from wgpu - let mut stylist = Stylist::new( - StyleDevice::new( - MediaType::screen(), - QUIRKS_MODE, - euclid::Size2D::new(800., 600.), - euclid::Scale::new(1.0), - ), - QUIRKS_MODE, - ); - - // We have no snapshots on initial render, but we will need them for future renders - let snapshots = SnapshotMap::new(); - - // Add the stylesheets to the stylist - stylist.append_stylesheet(DocumentStyleSheet(Arc::new(stylesheet)), &guard.read()); - - // We don't really need to do this, but it's worth keeping it here anyways - stylist.force_stylesheet_origins_dirty(Origin::Author.into()); - - // Note that html5ever parses the first node as the document, so we need to unwrap it and get the first child - // For the sake of this demo, it's always just a single body node, but eventually we will want to construct something like the - // BoxTree struct that servo uses. - stylist.flush(&guards, Some(markup.root_element()), Some(&snapshots)); - - // Build the style context used by the style traversal - let context = SharedStyleContext { - traversal_flags: TraversalFlags::empty(), - stylist: &stylist, - options: GLOBAL_STYLE_DATA.options.clone(), - guards, - visited_styles_enabled: false, - animations: (&DocumentAnimationSet::default()).clone(), - current_time_for_animations: 0.0, - snapshot_map: &snapshots, - registered_speculative_painters: &style_impls::RegisteredPaintersImpl, - }; - - // components/layout_2020/lib.rs:983 - println!("------Pre-traversing the DOM tree -----"); - let token = style_traverser::RecalcStyle::pre_traverse(markup.root_element(), &context); - - // Style the elements, resolving their data - println!("------ Traversing domtree ------",); - let traverser = style_traverser::RecalcStyle::new(context); - driver::traverse_dom(&traverser, token, None); - - markup -} +// pub use blitz::style_impls::{BlitzNode, RealDom}; +// use dioxus::prelude::*; +// use style::{ +// animation::DocumentAnimationSet, +// context::{QuirksMode, SharedStyleContext}, +// driver, +// global_style_data::GLOBAL_STYLE_DATA, +// media_queries::MediaType, +// media_queries::{Device as StyleDevice, MediaList}, +// selector_parser::SnapshotMap, +// servo_arc::Arc, +// shared_lock::{SharedRwLock, StylesheetGuards}, +// stylesheets::{AllowImportRules, DocumentStyleSheet, Origin, Stylesheet}, +// stylist::Stylist, +// thread_state::ThreadState, +// traversal::DomTraversal, +// traversal_flags::TraversalFlags, +// }; + +// fn main() { +// let css = r#" +// h1 { +// background-color: red; +// } + +// h2 { +// background-color: green; +// } + +// h3 { +// background-color: blue; +// } + +// h4 { +// background-color: yellow; +// } + +// "#; + +// let nodes = rsx! { +// h1 { } +// h2 { } +// h3 { } +// h4 { } +// }; + +// let styled_dom = style_lazy_nodes(css, nodes); + +// // print_styles(&styled_dom); +// } + +// // pub fn style_lazy_nodes(css: &str, markup: LazyNodes) -> RealDom { +// // const QUIRKS_MODE: QuirksMode = QuirksMode::NoQuirks; + +// // // Figured out a single-pass system from the servo repo itself: +// // // +// // // components/layout_thread_2020/lib.rs:795 +// // // handle_reflow +// // // tests/unit/style/custom_properties.rs +// // style::thread_state::enter(ThreadState::LAYOUT); + +// // // make the guards that we use to thread everything together +// // let guard = SharedRwLock::new(); +// // let guards = StylesheetGuards { +// // author: &guard.read(), +// // ua_or_user: &guard.read(), +// // }; + +// // // Make some CSS +// // let stylesheet = Stylesheet::from_str( +// // css, +// // servo_url::ServoUrl::from_url("data:text/css;charset=utf-8;base64,".parse().unwrap()), +// // Origin::UserAgent, +// // Arc::new(guard.wrap(MediaList::empty())), +// // guard.clone(), +// // None, +// // None, +// // QUIRKS_MODE, +// // AllowImportRules::Yes, +// // ); + +// // // Make the real domtree by converting dioxus vnodes +// // let markup = RealDom::from_dioxus(markup); + +// // // Now we need to do what handle_reflow does in servo +// // // Reflows should be fast due to caching in the Stylist object +// // // +// // // +// // // We can force reflows. Happens in the script/document section +// // // The browser keeps track of pending restyles itself when attributes are changed. +// // // When something like val.set_attribute() happens, the pending reflow is inserted into the list. +// // // Once ticks are finished, the ScriptReflow object is created and sent to the layout thread. +// // // The layout thread uses the ScriptReflow object to inform itself on what changes need to happen. +// // // Zooming and touching causes full reflows. +// // // For this demo we want to do complete reflows (have yet to figure it out) +// // // But eventually we'll want to queue up modifications to the ECS engine and then build the script-reflow type object. +// // // Unfortunately, this API assumes nodes are backed by pointers which adds some unsafe where we wouldn't want it. +// // // +// // // Reflow allows us to specify a dirty root node and a list of nodes to reflow. +// // // +// // // Notes: +// // // - https://developers.google.com/speed/docs/insights/browser-reflow +// // // - components/script/dom/window.rs:force_reflow +// // // +// // // Create a styling context for use throughout the following passes. +// // // In servo we'd also create a layout context, but since servo isn't updated with the new layout code, we're just using the styling context +// // // In a different world we'd use both +// // // Build the stylist object from our screen requirements +// // // Todo: pull this in from wgpu +// // let mut stylist = Stylist::new( +// // StyleDevice::new( +// // MediaType::screen(), +// // QUIRKS_MODE, +// // euclid::Size2D::new(800., 600.), +// // euclid::Scale::new(1.0), +// // ), +// // QUIRKS_MODE, +// // ); + +// // // We have no snapshots on initial render, but we will need them for future renders +// // let snapshots = SnapshotMap::new(); + +// // // Add the stylesheets to the stylist +// // stylist.append_stylesheet(DocumentStyleSheet(Arc::new(stylesheet)), &guard.read()); + +// // // We don't really need to do this, but it's worth keeping it here anyways +// // stylist.force_stylesheet_origins_dirty(Origin::Author.into()); + +// // // Note that html5ever parses the first node as the document, so we need to unwrap it and get the first child +// // // For the sake of this demo, it's always just a single body node, but eventually we will want to construct something like the +// // // BoxTree struct that servo uses. +// // stylist.flush(&guards, Some(markup.root_element()), Some(&snapshots)); + +// // // Build the style context used by the style traversal +// // let context = SharedStyleContext { +// // traversal_flags: TraversalFlags::empty(), +// // stylist: &stylist, +// // options: GLOBAL_STYLE_DATA.options.clone(), +// // guards, +// // visited_styles_enabled: false, +// // animations: (&DocumentAnimationSet::default()).clone(), +// // current_time_for_animations: 0.0, +// // snapshot_map: &snapshots, +// // registered_speculative_painters: &style_impls::RegisteredPaintersImpl, +// // }; + +// // // components/layout_2020/lib.rs:983 +// // println!("------Pre-traversing the DOM tree -----"); +// // let token = style_traverser::RecalcStyle::pre_traverse(markup.root_element(), &context); + +// // // Style the elements, resolving their data +// // println!("------ Traversing domtree ------",); +// // let traverser = style_traverser::RecalcStyle::new(context); +// // driver::traverse_dom(&traverser, token, None); + +// // markup +// // } From 590df84c0ddeeef68e357fb0a52caaa4f9b18014 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 12:04:22 +1200 Subject: [PATCH 4/9] Remove useless loop --- .../src/documents/dioxus_document.rs | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/dioxus-blitz/src/documents/dioxus_document.rs b/packages/dioxus-blitz/src/documents/dioxus_document.rs index f40d6ee03..b1962b9df 100644 --- a/packages/dioxus-blitz/src/documents/dioxus_document.rs +++ b/packages/dioxus-blitz/src/documents/dioxus_document.rs @@ -55,23 +55,22 @@ impl From for Document { } impl DocumentLike for DioxusDocument { fn poll(&mut self, mut cx: std::task::Context) -> bool { - loop { - { - let fut = self.vdom.wait_for_work(); - pin_mut!(fut); - - match fut.poll_unpin(&mut cx) { - std::task::Poll::Ready(_) => {} - std::task::Poll::Pending => return false, - } - } + { + let fut = self.vdom.wait_for_work(); + pin_mut!(fut); - self.vdom.render_immediate(&mut MutationWriter { - doc: &mut self.inner, - state: &mut self.vdom_state, - }); - return true; + match fut.poll_unpin(&mut cx) { + std::task::Poll::Ready(_) => {}, + std::task::Poll::Pending => return false, + } } + + self.vdom.render_immediate(&mut MutationWriter { + doc: &mut self.inner, + state: &mut self.vdom_state, + }); + + true } fn handle_event(&mut self, event: blitz_dom::events::RendererEvent) -> bool { From ea13a1b961789969f42373db1e51d8273c443b95 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 12:08:13 +1200 Subject: [PATCH 5/9] cargo fmt --- packages/dioxus-blitz/src/documents/dioxus_document.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dioxus-blitz/src/documents/dioxus_document.rs b/packages/dioxus-blitz/src/documents/dioxus_document.rs index b1962b9df..82fff2866 100644 --- a/packages/dioxus-blitz/src/documents/dioxus_document.rs +++ b/packages/dioxus-blitz/src/documents/dioxus_document.rs @@ -60,7 +60,7 @@ impl DocumentLike for DioxusDocument { pin_mut!(fut); match fut.poll_unpin(&mut cx) { - std::task::Poll::Ready(_) => {}, + std::task::Poll::Ready(_) => {} std::task::Poll::Pending => return false, } } @@ -69,7 +69,7 @@ impl DocumentLike for DioxusDocument { doc: &mut self.inner, state: &mut self.vdom_state, }); - + true } From 1f2f6d439e988de4dd530895a55cbe88f742764e Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 12:14:18 +1200 Subject: [PATCH 6/9] Test entire workspace --- .github/workflows/ci.yml | 15 +++------------ packages/blitz/src/viewport.rs | 22 ++-------------------- packages/dom/src/document.rs | 17 +++++++++++++++++ packages/dom/src/htmlsink.rs | 2 ++ 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d1b328b0..392b0f00a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,24 +29,15 @@ jobs: - run: sudo apt install libgtk-3-dev - run: cargo build --workspace - - build-features-default: - name: "Build [default features]" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - run: sudo apt install libgtk-3-dev - - run: cargo build --workspace - # - run: cargo test - test-features-default: name: "Test [default features]" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - run: cargo test + - run: sudo apt install libgtk-3-dev + - run: cargo build --workspace + - run: cargo test --workspace fmt: name: Rustfmt diff --git a/packages/blitz/src/viewport.rs b/packages/blitz/src/viewport.rs index 55095bcf4..7dfaab971 100644 --- a/packages/blitz/src/viewport.rs +++ b/packages/blitz/src/viewport.rs @@ -1,7 +1,5 @@ -use style::{ - media_queries::{Device, MediaType}, - servo::media_queries::FontMetricsProvider, -}; +use blitz_dom::document::DummyFontMetricsProvider; +use style::media_queries::{Device, MediaType}; #[derive(Default, Debug)] pub struct Viewport { @@ -14,22 +12,6 @@ pub struct Viewport { pub font_size: f32, } -// TODO: implement a proper font metrics provider -#[derive(Debug, Clone)] -struct DummyFontMetricsProvider; -impl FontMetricsProvider for DummyFontMetricsProvider { - fn query_font_metrics( - &self, - _vertical: bool, - _font: &style::properties::style_structs::Font, - _base_size: style::values::computed::CSSPixelLength, - _in_media_query: bool, - _retrieve_math_scales: bool, - ) -> style::font_metrics::FontMetrics { - Default::default() - } -} - impl Viewport { pub fn new(window_size: (u32, u32)) -> Self { Self { diff --git a/packages/dom/src/document.rs b/packages/dom/src/document.rs index cfda135f7..7bbf9a8bb 100644 --- a/packages/dom/src/document.rs +++ b/packages/dom/src/document.rs @@ -7,6 +7,7 @@ use slab::Slab; use std::collections::HashMap; use style::invalidation::element::restyle_hints::RestyleHint; use style::selector_parser::ServoElementSnapshot; +use style::servo::media_queries::FontMetricsProvider; use style::servo_arc::Arc as ServoArc; use style::{ dom::{TDocument, TNode}, @@ -20,6 +21,22 @@ use style_traits::dom::ElementState; use taffy::AvailableSpace; use url::Url; +// TODO: implement a proper font metrics provider +#[derive(Debug, Clone)] +pub struct DummyFontMetricsProvider; +impl FontMetricsProvider for DummyFontMetricsProvider { + fn query_font_metrics( + &self, + _vertical: bool, + _font: &style::properties::style_structs::Font, + _base_size: style::values::computed::CSSPixelLength, + _in_media_query: bool, + _retrieve_math_scales: bool, + ) -> style::font_metrics::FontMetrics { + Default::default() + } +} + pub trait DocumentLike: AsRef + AsMut + Into { fn poll(&mut self, _cx: std::task::Context) -> bool { // Default implementation does nothing diff --git a/packages/dom/src/htmlsink.rs b/packages/dom/src/htmlsink.rs index c2b205073..03397648f 100644 --- a/packages/dom/src/htmlsink.rs +++ b/packages/dom/src/htmlsink.rs @@ -365,6 +365,7 @@ impl<'b> TreeSink for DocumentHtmlParser<'b> { #[test] fn parses_some_html() { + use crate::document::DummyFontMetricsProvider; use euclid::{Scale, Size2D}; use style::media_queries::{Device, MediaType}; @@ -377,6 +378,7 @@ fn parses_some_html() { selectors::matching::QuirksMode::NoQuirks, viewport_size, device_pixel_ratio, + Box::new(DummyFontMetricsProvider), ); let mut doc = Document::new(device); let sink = DocumentHtmlParser::new(&mut doc); From 43cbe6b683f93058a2001e08372fb4665d845ba0 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 13:01:33 +1200 Subject: [PATCH 7/9] Further clippy fixes --- packages/dom/src/layout/mod.rs | 14 +++++++------- packages/dom/src/stylo_to_parley.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/dom/src/layout/mod.rs b/packages/dom/src/layout/mod.rs index 4916dd5a0..94e100f3d 100644 --- a/packages/dom/src/layout/mod.rs +++ b/packages/dom/src/layout/mod.rs @@ -411,13 +411,13 @@ impl PrintTree for Document { } } -pub struct ChildIter<'a>(std::slice::Iter<'a, usize>); -impl<'a> Iterator for ChildIter<'a> { - type Item = NodeId; - fn next(&mut self) -> Option { - self.0.next().copied().map(NodeId::from) - } -} +// pub struct ChildIter<'a>(std::slice::Iter<'a, usize>); +// impl<'a> Iterator for ChildIter<'a> { +// type Item = NodeId; +// fn next(&mut self) -> Option { +// self.0.next().copied().map(NodeId::from) +// } +// } pub struct RefCellChildIter<'a> { items: Ref<'a, [usize]>, diff --git a/packages/dom/src/stylo_to_parley.rs b/packages/dom/src/stylo_to_parley.rs index f5a724db4..066eb0e42 100644 --- a/packages/dom/src/stylo_to_parley.rs +++ b/packages/dom/src/stylo_to_parley.rs @@ -72,7 +72,7 @@ pub(crate) fn style(style: &stylo::ComputedValues) -> parley::TextStyle<'static, } // TODO: fix leak! - parley::FontFamily::Named(name.to_string().leak()) + break 'ret parley::FontFamily::Named(name.to_string().leak()); } } stylo::SingleFontFamily::Generic(generic) => { From 1452b1a0e0a46adbd001434703b0a5e1d0e72edb Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 13:04:35 +1200 Subject: [PATCH 8/9] Test fixes --- .github/workflows/ci.yml | 6 +++--- packages/dioxus-blitz/src/window.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 392b0f00a..e5196cb74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: 1.79 - - run: sudo apt install libgtk-3-dev + - run: sudo apt install libgtk-3-dev libxdo-dev - run: cargo build --workspace test-features-default: @@ -35,7 +35,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - run: sudo apt install libgtk-3-dev + - run: sudo apt install libgtk-3-dev libxdo-dev - run: cargo build --workspace - run: cargo test --workspace @@ -59,7 +59,7 @@ jobs: with: toolchain: nightly components: clippy - - run: sudo apt install libgtk-3-dev + - run: sudo apt install libgtk-3-dev libxdo-dev - run: cargo clippy --workspace -- -D warnings doc: diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index 5fb5c6269..920b5580d 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -296,7 +296,9 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { } #[cfg(target_os = "linux")] { - build_menu().init_for_gtk_window(window.gtk_window(), window.default_vbox()); + build_menu() + .init_for_gtk_window(window.gtk_window(), window.default_vbox()) + .unwrap(); } // !TODO - this may not be the right way to do this, but it's a start @@ -331,10 +333,10 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { #[cfg(not(target_os = "macos"))] fn build_menu() -> Menu { - let mut menu = Menu::new(); + let menu = Menu::new(); // Build the about section - let mut about = Submenu::new("About", true); + let about = Submenu::new("About", true); about .append_items(&[ From c4fb3f0184482893fe1e2acb126a3c1b0767976f Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 19 Jun 2024 13:17:38 +1200 Subject: [PATCH 9/9] Further clippy fix --- packages/blitz/src/render.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/blitz/src/render.rs b/packages/blitz/src/render.rs index 37040a9a7..dc246236c 100644 --- a/packages/blitz/src/render.rs +++ b/packages/blitz/src/render.rs @@ -141,19 +141,22 @@ where .await .expect("Error creating surface"); - let default_threads = || -> Option { - #[cfg(target_arch = "macos")] + const DEFAULT_THREADS: Option = { + #[cfg(target_os = "macos")] { - Some(NonZeroUsize::new(1)?) + NonZeroUsize::new(1) + } + #[cfg(not(target_os = "macos"))] + { + None } - None }; let options = RendererOptions { surface_format: Some(surface.config.format), antialiasing_support: AaSupport::all(), use_cpu: false, - num_init_threads: default_threads(), + num_init_threads: DEFAULT_THREADS, }; let renderer =