Skip to main content

Document

Struct Document 

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

A document — the top-level owner of a node tree.

Owns all node data through parallel arenas. Internal subsystems (layout, style, events) access data through DocumentCell.

The owner must keep Document at a stable address. Handles store raw pointers back to this Document through DocumentCell.

Implementations§

Source§

impl Document

Source

pub fn new() -> Self

Create a new empty document with a root node.

Source

pub fn init_body(&mut self)

Initialize the <body> element. Called after Document is pinned in memory (needs stable address for Handle operations).

Creates a real <body> element — UA stylesheet provides: body { display: block; margin: 8px; }

Source

pub fn computed_style(&self, index: u32) -> Option<Arc<ComputedValues>>

Get the computed style for a node (from Stylo’s ElementData).

Returns None if styles haven’t been computed yet or for non-element nodes.

Source

pub fn div(&self) -> HtmlDivElement

Source

pub fn span(&self) -> HtmlSpanElement

Source

pub fn p(&self) -> HtmlParagraphElement

Source

pub fn button(&self) -> HtmlButtonElement

Source

pub fn img(&self) -> HtmlImageElement

Source

pub fn input(&self) -> HtmlInputElement

Source

pub fn label(&self) -> HtmlLabelElement

Source

pub fn h1(&self) -> HtmlHeadingElement

Source

pub fn h2(&self) -> HtmlHeadingElement

Source

pub fn h3(&self) -> HtmlHeadingElement

Source

pub fn text_node(&self, content: &str) -> Text

Source

pub fn div_in(&self, parent: impl Into<Handle>) -> HtmlDivElement

Source

pub fn span_in(&self, parent: impl Into<Handle>) -> HtmlSpanElement

Source

pub fn text_in(&self, parent: impl Into<Handle>, content: &str) -> Text

Source

pub fn create<T: Element>(&self) -> T

Source

pub fn create_with_tag<T: Element>(&self, tag: &'static str) -> T

Source

pub fn create_heading(&self, level: u8) -> HtmlHeadingElement

Source

pub fn create_text(&self, content: &str) -> Text

Source

pub fn root(&self) -> Handle

Source

pub fn body(&self) -> Handle

The <body> element — main content container.

Like Chrome’s document.body. Created by init_body() after the Document is pinned in memory. Styles come from the UA stylesheet: body { display: block; margin: 8px; }.

All user content goes in body(), not root().

Source

pub fn resolve(&self, raw: RawId) -> Option<Handle>

Source

pub fn node_count(&self) -> u32

Source

pub fn root_index(&self) -> u32

Source

pub fn needs_visual_update(&self) -> bool

Whether any pending changes need a visual update.

Chrome equivalent: Document::NeedsStyleRecalc() + layout dirty checks. Used by the scheduler to request a frame after spawned tasks mutate the DOM.

Source

pub fn handle_for_index(&self, index: u32) -> Option<Handle>

Get a Handle for a node by its arena index.

Used by hit testing and event dispatch: the fragment tree stores only the node index (u32), this recovers the full Handle needed for event dispatch. Returns None if the index is dead or out of bounds.

Chrome equivalent: resolving a LayoutObject’s GetNode() pointer.

Source

pub fn recalc_styles(&mut self)

Source

pub fn add_stylesheet(&self, css: &str)

Add a CSS stylesheet with full selector support.

Chrome equivalent: <style> element or document.adoptedStyleSheets. Supports all CSS selectors: .class, #id, tag, [attr], descendant, child, pseudo-classes — everything Stylo/Chrome supports.

doc.add_stylesheet(".card { background: red; border-radius: 8px; }");
doc.add_stylesheet(include_str!("../assets/dashboard.css"));
Source§

impl Document

Source

pub fn resolve_layout( &mut self, root: u32, available_width: Option<f32>, available_height: Option<f32>, ctx: &LayoutContext<'_>, ) -> LayoutResult

Full layout resolve: flush styles → build children → compute → fragments.

Single entry point that replaces the old 4-step pipeline:

  1. build_layout_tree_from_doc()resolve_layout_children()
  2. sync_all_styles()flush_styles_to_layout()
  3. compute_layout() → Taffy runs against Document directly
  4. build_fragment_recursive() → reads from Document

Convenience wrapper — always force-clears caches.

Source

pub fn resolve_layout_dirty( &mut self, root: u32, available_width: Option<f32>, available_height: Option<f32>, ctx: &LayoutContext<'_>, layout_dirty: bool, ) -> LayoutResult

Full layout resolve with dirty flag control.

layout_dirty: true = something changed, clear all Taffy caches. false = nothing changed, Taffy hits cache → ~0ms layout.

Trait Implementations§

Source§

impl Default for Document

Source§

fn default() -> Self

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

impl Drop for Document

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,