Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

A page: a DOM document, its stylesheets, and (later) its resolved layout.

Implementations§

Source§

impl Engine

Source

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

pub fn set_local_fonts( &mut self, has: impl Fn(&str) -> bool + Send + Sync + 'static, )

How the engine asks the host whether a local() name is a face it has (for instance, FontSet::select(name, ..).is_some()). Without one, local() sources are skipped.

Source§

impl Engine

Source

pub fn set_base_url(&mut self, url: impl Into<String>)

The URL the document’s references resolve against (its own URL).

Source

pub fn base_url(&self) -> Option<&str>

The URL references resolve against, if one was set.

Source

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.

Source

pub fn completions(&self) -> &Completions

The queue loads finish into: set a waker on it to hear when to call Engine::poll_resources.

Source

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.

Source

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

pub fn images(&self) -> &Images

The images loaded so far, by src as written.

Source§

impl Engine

Source

pub fn new() -> Self

Create an empty engine with a fresh document.

Source

pub fn from_html(html: &str) -> Self

Parse html into a fresh engine, collecting its stylesheets.

Source

pub fn dom(&self) -> &Document

Borrow the underlying DOM document.

Source

pub fn dom_mut(&mut self) -> &mut Document

Mutably borrow the underlying DOM document.

Source

pub fn stylesheets(&self) -> &[Stylesheet]

The stylesheets collected from the document’s <style> elements.

Source

pub fn refresh_stylesheets(&mut self)

Re-scan the document’s <style> elements for stylesheets.

Source

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().

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn layout(&self, viewport: Size, shaper: &dyn Shaper) -> LayoutTree

Lay the document out for a viewport, using the given text shaper.

Source

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.

Source

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.

Source

pub fn paint(&self, viewport: Size, shaper: &dyn Shaper) -> CommandList

Lay out and paint the document, returning the render command stream.

Source

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).

Source

pub fn into_dom(self) -> Document

Consume the engine and return its document.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Engine

§

impl !UnwindSafe for Engine

§

impl Forget for Engine

§

impl Freeze for Engine

§

impl Move for Engine

§

impl Send for Engine
where RawVecInner: Send, BoxRaw<SelectorList>: Send, RawTable<(String, Vec<usize>)>: Send, BoxRaw<dyn Loader + Sync + Send>: Send, Arc<Shared>: Send, RawTable<(NodeId, usize)>: Send, RawTable<(RequestId, usize)>: Send, Arc<[u8]>: Send, BoxRaw<dyn Fn(&str) -> bool + Sync + Send>: Send, RawTable<(String, ())>: Send, RawTable<(RequestId, String)>: Send, RawTable<(String, Image)>: Send,

§

impl Sync for Engine
where RawVecInner: Sync, BoxRaw<SelectorList>: Sync, RawTable<(String, Vec<usize>)>: Sync, BoxRaw<dyn Loader + Sync + Send>: Sync, Arc<Shared>: Sync, RawTable<(NodeId, usize)>: Sync, RawTable<(RequestId, usize)>: Sync, Arc<[u8]>: Sync, BoxRaw<dyn Fn(&str) -> bool + Sync + Send>: Sync, RawTable<(String, ())>: Sync, RawTable<(RequestId, String)>: Sync, RawTable<(String, Image)>: Sync,

§

impl Unpin for Engine
where *const u8 is !null: Unpin, Box<SelectorList>: Unpin, Box<dyn Loader + Sync + Send>: Unpin, Arc<Shared>: Unpin, Arc<[u8]>: Unpin, Box<dyn Fn(&str) -> bool + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Engine

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.