1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::{HtmlParserProvider, UserAgentStylesheet};
use blitz_traits::{
navigation::NavigationProvider,
net::{AbortSignal, NetProvider},
shell::{ShellProvider, Viewport},
};
use parley::FontContext;
use std::sync::Arc;
use style::media_queries::MediaType;
/// Strategy for Stylo's style traversal during `resolve`.
///
/// Two `Document`s resolving on [`StyleThreading::Parallel`] concurrently
/// share Stylo's global thread pool and can panic with
/// `already mutably borrowed` — see
/// <https://github.com/DioxusLabs/blitz/issues/430>. Set
/// [`StyleThreading::Sequential`] on documents that may resolve from a
/// user thread while another `Parallel` resolve is in flight.
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
pub enum StyleThreading {
/// Use Stylo's parallel traversal via its global rayon thread pool.
/// Fastest for a single document; panics if another `Parallel` resolve
/// is in flight on a different thread.
Parallel,
/// Run style traversal sequentially on the calling thread, bypassing
/// the global pool. Safe to use from many user threads concurrently.
#[default]
Sequential,
}
/// Options used when constructing a [`BaseDocument`](crate::BaseDocument)
pub struct DocumentConfig {
/// The initial `Viewport`
pub viewport: Option<Viewport>,
/// The base url which relative URLs are resolved against
pub base_url: Option<String>,
/// User Agent stylesheets, in cascade order. Defaults to `vec![UserAgentStylesheet::default_sheet()]`.
///
/// The list is used as given, so replacing it removes the default sheet unless it is
/// included, e.g. `vec![UserAgentStylesheet::default_sheet(), custom]`.
pub ua_stylesheets: Vec<UserAgentStylesheet>,
/// Net provider to handle network requests for resources
pub net_provider: Option<Arc<dyn NetProvider>>,
/// Navigation provider to handle link clicks and form submissions
pub navigation_provider: Option<Arc<dyn NavigationProvider>>,
/// Shell provider to redraw requests, clipboard, etc
pub shell_provider: Option<Arc<dyn ShellProvider>>,
/// HTML parser provider. Used to parse HTML for setInnerHTML
pub html_parser_provider: Option<Arc<dyn HtmlParserProvider>>,
/// Parley `FontContext`
pub font_ctx: Option<FontContext>,
/// The CSS media type used to evaluate `@media` rules.
/// Defaults to [`MediaType::screen`].
pub media_type: Option<MediaType>,
/// Strategy for Stylo's style traversal.
/// Defaults to [`StyleThreading::Parallel`].
pub style_threading: StyleThreading,
/// Whether incremental layout is enabled. Defaults to `true`.
///
/// When disabled, every node is treated as damaged on each `resolve` and the
/// whole tree is reconstructed and laid out from scratch through the same
/// damage-driven pipeline used by incremental mode.
pub incremental: Option<bool>,
/// If set, every sub-resource `Request` blitz-dom creates for this
/// document will carry this signal. Aborting it cancels every in-flight
/// fetch tied to this document.
pub abort_signal: Option<AbortSignal>,
/// How deeply this document is nested within other documents
/// (0 for a root document). Used to limit `<iframe>` nesting depth.
pub subdocument_depth: usize,
}
impl Default for DocumentConfig {
fn default() -> Self {
Self {
viewport: None,
base_url: None,
ua_stylesheets: vec![UserAgentStylesheet::default_sheet()],
net_provider: None,
navigation_provider: None,
shell_provider: None,
html_parser_provider: None,
font_ctx: None,
media_type: None,
style_threading: StyleThreading::default(),
incremental: None,
abort_signal: None,
subdocument_depth: 0,
}
}
}