mirror of
https://github.com/flectar/mail.git
synced 2026-11-12 02:05:59 +00:00
95 lines
4.0 KiB
Rust
95 lines
4.0 KiB
Rust
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 {
|
|
/// Optional bounded raster decoding for untrusted email content.
|
|
pub image_decode_limits: Option<crate::net::ImageDecodeLimits>,
|
|
/// 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 {
|
|
image_decode_limits: None,
|
|
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,
|
|
}
|
|
}
|
|
}
|