pub struct Engine { /* private fields */ }Expand description
A page: a DOM document, its stylesheets, and (later) its resolved layout.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn loaded_fonts(&self) -> &[LoadedFont]
pub fn loaded_fonts(&self) -> &[LoadedFont]
The faces loaded from @font-face rules so far, for the host to
register (each under its family, weight and style).
Source§impl Engine
impl Engine
Sourcepub fn set_base_url(&mut self, url: impl Into<String>)
pub fn set_base_url(&mut self, url: impl Into<String>)
The URL the document’s references resolve against (its own URL).
Sourcepub fn set_loader(&mut self, loader: impl Loader + Send + Sync + 'static)
pub fn set_loader(&mut self, loader: impl Loader + Send + Sync + 'static)
Load subresources through loader from now on. Without one, nothing
is loaded: an engine reaches the filesystem or the network only
when its host says so.
Sourcepub fn completions(&self) -> &Completions
pub fn completions(&self) -> &Completions
The queue loads finish into: set a waker on it to hear when to call
Engine::poll_resources.
Sourcepub fn load_resources(&mut self) -> usize
pub fn load_resources(&mut self) -> usize
Start loading each <img src> and each <link rel=stylesheet> not
yet requested, resolved against the base URL; returns how many loads
started. Call it after parsing and after DOM edits that may add
either; sheets an @import brings in start as their parent arrives.
A link is skipped when it is disabled, has a type other than
text/css, an alternate rel, or only non-screen media (such as
print). Every load goes through the host’s loader, so its policy
covers sheets as it covers images.
Sourcepub fn poll_resources(&mut self) -> bool
pub fn poll_resources(&mut self) -> bool
Take in the loads that finished; true when an image arrived or the
stylesheets in force changed, so the host must restyle and lay out
again (Engine::restyle sees the new sheets). Call it when the
Engine::completions waker fires. A load that failed or isn’t an
image keeps its element’s alt text; a sheet that failed changes
nothing; neither is retried.
Source§impl Engine
impl Engine
Sourcepub fn from_html(html: &str) -> Self
pub fn from_html(html: &str) -> Self
Parse html into a fresh engine, collecting its stylesheets.
Sourcepub fn stylesheets(&self) -> &[Stylesheet]
pub fn stylesheets(&self) -> &[Stylesheet]
The stylesheets collected from the document’s <style> elements.
Sourcepub fn refresh_stylesheets(&mut self)
pub fn refresh_stylesheets(&mut self)
Re-scan the document’s <style> elements for stylesheets.
Sourcepub fn restyle(
&mut self,
styles: &mut Styles,
viewport: Size,
interaction: Interaction,
) -> usize
pub fn restyle( &mut self, styles: &mut Styles, viewport: Size, interaction: Interaction, ) -> usize
Bring styles up to date with the document, its stylesheets,
viewport and interaction, restyling only what changed since the
last call. Returns how many times an element was styled.
Start from Styles::default: the first call computes everything.
After that, edits made through Document::mutate restyle only the
subtrees they can reach, and a hover, focus or press moving restyles
the nodes it moved between. An edit to a <style> element, a new
viewport, or raw writes through Document::tree_mut restyle
everything, and so does any edit but to text while a rule uses
:has().
Sourcepub fn font_faces(&self) -> Vec<FontFace>
pub fn font_faces(&self) -> Vec<FontFace>
The @font-face descriptors collected from the stylesheets, in source
order.
A host loads each src (noonoo-net covers file: and data:),
parses the bytes with noonoo-ttf’s Font, and registers the face
with a FontSet; see the noonoo CLI’s --paint for the pattern.
Sourcepub fn compute_styles(&self) -> Styles
pub fn compute_styles(&self) -> Styles
Compute every element’s style: cascade the collected stylesheets over the
user-agent sheet and any inline style attributes.
Viewport-relative units resolve against
noonoo_style::Viewport::DEFAULT; Engine::compute_styles_for uses a
real viewport instead.
Sourcepub fn compute_styles_for(&self, viewport: Size) -> Styles
pub fn compute_styles_for(&self, viewport: Size) -> Styles
Compute every element’s style against viewport, so vw/vh and
calc(100vw - 2rem) resolve correctly.
Sourcepub fn compute_styles_in(
&self,
viewport: Size,
interaction: Interaction,
) -> Styles
pub fn compute_styles_in( &self, viewport: Size, interaction: Interaction, ) -> Styles
Compute every element’s style against viewport and the interactive
state, so :hover/:focus/:active style the elements they name.
Sourcepub fn layout(&self, viewport: Size, shaper: &dyn Shaper) -> LayoutTree
pub fn layout(&self, viewport: Size, shaper: &dyn Shaper) -> LayoutTree
Lay the document out for a viewport, using the given text shaper.
Sourcepub fn set_prefers_dark(&mut self, prefers_dark: bool)
pub fn set_prefers_dark(&mut self, prefers_dark: bool)
Whether the host prefers a dark colour scheme (default: light). It
decides light-dark() for an element whose color-scheme lists both
light and dark (a page that sets no color-scheme stays light),
and @media (prefers-color-scheme). Takes effect at the next
restyle.
Sourcepub fn canvas(&self, styles: &Styles) -> Option<Canvas>
pub fn canvas(&self, styles: &Styles) -> Option<Canvas>
The canvas background for styles: the root element’s background
colour or, when the root has neither a colour nor a background image,
the body’s (CSS Backgrounds 3, section 2.11.2). None when neither
paints.
Sourcepub fn paint(&self, viewport: Size, shaper: &dyn Shaper) -> CommandList
pub fn paint(&self, viewport: Size, shaper: &dyn Shaper) -> CommandList
Lay out and paint the document, returning the render command stream.
Sourcepub fn paint_with(
&self,
viewport: Size,
shaper: &dyn Shaper,
glyphs: &dyn Glyphs,
) -> CommandList
pub fn paint_with( &self, viewport: Size, shaper: &dyn Shaper, glyphs: &dyn Glyphs, ) -> CommandList
Lay out and paint the document, drawing text with glyphs.
Use this with a font-backed shaper and matching glyph renderer to render
vector text (see noonoo-ttf’s FontShaper + OutlineGlyphs).