Skip to main content

LayoutDomMut

Trait LayoutDomMut 

Source
pub trait LayoutDomMut: LayoutDom {
    // Required methods
    fn create_element(&mut self, name: QualName) -> Self::NodeId;
    fn create_text(&mut self, data: &str) -> Self::NodeId;
    fn append_child(&mut self, parent: Self::NodeId, child: Self::NodeId);
    fn insert_before(
        &mut self,
        parent: Self::NodeId,
        child: Self::NodeId,
        reference: Option<Self::NodeId>,
    );
    fn move_before(
        &mut self,
        parent: Self::NodeId,
        child: Self::NodeId,
        reference: Option<Self::NodeId>,
    );
    fn remove(&mut self, node: Self::NodeId);
    fn set_attribute(&mut self, node: Self::NodeId, name: QualName, value: &str);
    fn remove_attribute(&mut self, node: Self::NodeId, name: QualName);
    fn set_text(&mut self, node: Self::NodeId, data: &str);
    fn set_inner_html(&mut self, node: Self::NodeId, html: &str);
    fn drain_mutations(&mut self, out: &mut Vec<DomMutation<Self::NodeId>>);
}
Expand description

Mutation extension for scripted DOMs (plan Part 3 / the layout_dom_api design’s open question #1). Read-only consumers (reader-mode, serialization, static layout) implement only LayoutDom; serval-scripted-dom implements both.

Mutators record structural change as DomMutation records — they carry no notion of dirty bits, style, or layout. serval-layout’s scheduler drains the stream (Self::drain_mutations) and translates it into StylePlane/LayoutPlane invalidation; the DOM provider itself stays render-state-free.

Required Methods§

Source

fn create_element(&mut self, name: QualName) -> Self::NodeId

Create a detached element node (no parent until appended).

Source

fn create_text(&mut self, data: &str) -> Self::NodeId

Create a detached text node.

Source

fn append_child(&mut self, parent: Self::NodeId, child: Self::NodeId)

Append child as the last child of parent, detaching it from any previous parent first.

Source

fn insert_before( &mut self, parent: Self::NodeId, child: Self::NodeId, reference: Option<Self::NodeId>, )

Insert child immediately before reference among parent’s children, detaching child from any previous parent first. Appends if reference is None, or if reference is not a child of parent (defensive: the DOM insertBefore throws in that case, but the layout-side contract stays total). The ordered-insertion primitive a reactive differ needs; append_child is the reference == None tail case.

Source

fn move_before( &mut self, parent: Self::NodeId, child: Self::NodeId, reference: Option<Self::NodeId>, )

Atomically move an in-tree child under parent before reference (append when None), preserving subtree state — the Node.moveBefore() contract (WHATWG DOM; docs/2026-07-05_movebefore_dom_standard_plan.md). Records one DomMutation::Moved instead of the Removed + Inserted pair insert_before produces for an in-tree node, so consumers may keep the subtree’s retained state. A move resolving to the current position records nothing; a disconnected child degrades to a plain insert (the DOM-level moveBefore throws there; this layout-side contract stays total, like insert_before’s bad-reference fallback).

Source

fn remove(&mut self, node: Self::NodeId)

Detach node from its parent and drop its subtree.

Source

fn set_attribute(&mut self, node: Self::NodeId, name: QualName, value: &str)

Set (or replace) an attribute on an element.

Source

fn remove_attribute(&mut self, node: Self::NodeId, name: QualName)

Remove the attribute named name from node (no-op if absent). Records an DomMutation::AttributeChanged carrying the removed value as old_value (the live DOM then reads as absent), so serval-layout builds the Stylo snapshot the same way it does for a value change.

Source

fn set_text(&mut self, node: Self::NodeId, data: &str)

Replace a text/comment node’s character data.

Source

fn set_inner_html(&mut self, node: Self::NodeId, html: &str)

Replace node’s children with the subtree parsed from an HTML fragment (the innerHTML setter). Records a single DomMutation::SubtreeReplaced.

Source

fn drain_mutations(&mut self, out: &mut Vec<DomMutation<Self::NodeId>>)

Drain the structural mutations recorded since the last call into out. The provider records WHAT changed; serval-layout decides what to invalidate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§