blitz_dom/config.rs
1use crate::HtmlParserProvider;
2use blitz_traits::{
3 navigation::NavigationProvider,
4 net::{AbortSignal, NetProvider},
5 shell::{ShellProvider, Viewport},
6};
7use parley::FontContext;
8use std::sync::Arc;
9use style::media_queries::MediaType;
10
11/// Strategy for Stylo's style traversal during `resolve`.
12///
13/// Two `Document`s resolving on [`StyleThreading::Parallel`] concurrently
14/// share Stylo's global thread pool and can panic with
15/// `already mutably borrowed` — see
16/// <https://github.com/DioxusLabs/blitz/issues/430>. Set
17/// [`StyleThreading::Sequential`] on documents that may resolve from a
18/// user thread while another `Parallel` resolve is in flight.
19#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
20pub enum StyleThreading {
21 /// Use Stylo's parallel traversal via its global rayon thread pool.
22 /// Fastest for a single document; panics if another `Parallel` resolve
23 /// is in flight on a different thread.
24 #[default]
25 Parallel,
26 /// Run style traversal sequentially on the calling thread, bypassing
27 /// the global pool. Safe to use from many user threads concurrently.
28 Sequential,
29}
30
31/// Options used when constructing a [`BaseDocument`](crate::BaseDocument)
32#[derive(Default)]
33pub struct DocumentConfig {
34 /// The initial `Viewport`
35 pub viewport: Option<Viewport>,
36 /// The base url which relative URLs are resolved against
37 pub base_url: Option<String>,
38 /// User Agent stylesheets
39 pub ua_stylesheets: Option<Vec<String>>,
40 /// Net provider to handle network requests for resources
41 pub net_provider: Option<Arc<dyn NetProvider>>,
42 /// Navigation provider to handle link clicks and form submissions
43 pub navigation_provider: Option<Arc<dyn NavigationProvider>>,
44 /// Shell provider to redraw requests, clipboard, etc
45 pub shell_provider: Option<Arc<dyn ShellProvider>>,
46 /// HTML parser provider. Used to parse HTML for setInnerHTML
47 pub html_parser_provider: Option<Arc<dyn HtmlParserProvider>>,
48 /// Parley `FontContext`
49 pub font_ctx: Option<FontContext>,
50 /// The CSS media type used to evaluate `@media` rules.
51 /// Defaults to [`MediaType::screen`].
52 pub media_type: Option<MediaType>,
53 /// Strategy for Stylo's style traversal.
54 /// Defaults to [`StyleThreading::Parallel`].
55 pub style_threading: StyleThreading,
56 /// If set, every sub-resource `Request` blitz-dom creates for this
57 /// document will carry this signal. Aborting it cancels every in-flight
58 /// fetch tied to this document.
59 pub abort_signal: Option<AbortSignal>,
60}