Skip to main content

StyledDom

Struct StyledDom 

Source
#[repr(C)]
pub struct StyledDom { pub root: NodeHierarchyItemId, pub node_hierarchy: NodeHierarchyItemVec, pub node_data: NodeDataVec, pub styled_nodes: StyledNodeVec, pub cascade_info: CascadeInfoVec, pub nodes_with_window_callbacks: NodeHierarchyItemIdVec, pub nodes_with_datasets: NodeHierarchyItemIdVec, pub tag_ids_to_node_ids: TagIdToNodeIdMappingVec, pub non_leaf_nodes: ParentWithNodeDepthVec, pub css_property_cache: CssPropertyCachePtr, pub dom_id: DomId, }

Fields§

§root: NodeHierarchyItemId§node_hierarchy: NodeHierarchyItemVec§node_data: NodeDataVec§styled_nodes: StyledNodeVec§cascade_info: CascadeInfoVec§nodes_with_window_callbacks: NodeHierarchyItemIdVec§nodes_with_datasets: NodeHierarchyItemIdVec§tag_ids_to_node_ids: TagIdToNodeIdMappingVec§non_leaf_nodes: ParentWithNodeDepthVec§css_property_cache: CssPropertyCachePtr§dom_id: DomId

The ID of this DOM in the layout tree (for multi-DOM support with VirtualViews)

Implementations§

Source§

impl StyledDom

Source

pub fn memory_report(&self) -> StyledDomMemoryReport

Approximate heap bytes retained by this StyledDom, broken out by field.

Source

pub fn create(dom: &mut Dom, css: Css) -> Self

Creates a new StyledDom by applying CSS styles to a DOM tree.

NOTE: After calling this function, the DOM will be reset to an empty DOM.

Source

pub fn create_from_fast_dom(fast_dom: FastDom) -> Self

Creates a StyledDom from a FastDom (arena-based DOM).

This skips the convert_dom_into_compact_dom tree→arena conversion entirely since FastDom already has flat NodeHierarchyItemVec and NodeDataVec. CSS is collected from CssWithNodeIdVec.

Source

pub fn create_from_dom(dom: Dom) -> Self

Creates a StyledDom from a recursive Dom tree with deferred CSS.

This is the Phase 7.2 entry point: the layout callback returns a recursive Dom with css: Vec<Css> on each node. This function:

  1. Collects all CSS objects from the recursive tree
  2. Flattens the Dom into contiguous arrays (CompactDom)
  3. Merges all CSS objects and runs a single cascade pass
  4. Runs apply_ua_css → compute_inherited_values → build_compact_cache
  5. Generates anonymous table elements
Source

pub fn append_child(&mut self, other: Self)

Appends another StyledDom as a child to the self.root without re-styling the DOM itself

Source

pub fn append_child_with_index(&mut self, other: Self, child_index: usize)

Optimized version of append_child that takes the child index directly instead of counting existing children (O(1) instead of O(n))

Source

pub fn finalize_non_leaf_nodes(&mut self)

Call this after all append_child_with_index operations are complete to sort non_leaf_nodes by depth (required for correct rendering)

Source

pub fn with_child(self, other: Self) -> Self

Same as append_child(), but as a builder method

Source

pub fn set_context_menu(&mut self, context_menu: Menu)

Sets the context menu for the root node

Source

pub fn with_context_menu(self, context_menu: Menu) -> Self

Builder method for setting the context menu

Source

pub fn set_menu_bar(&mut self, menu_bar: Menu)

Sets the menu bar for the root node

Source

pub fn with_menu_bar(self, menu_bar: Menu) -> Self

Builder method for setting the menu bar

Source

pub fn recompute_inheritance_and_compact_cache(&mut self)

Re-compute inherited CSS values and rebuild the compact layout cache.

This MUST be called after append_child() merges multiple StyledDoms. append_child() concatenates the CSS property caches but does NOT re-run inheritance or rebuild the compact cache. This means:

  1. Broken inheritance: Inherited properties (color, font-size, direction) from the parent DOM do not flow into appended subtrees.
  2. Stale compact cache: The child’s tier 1/2/2b entries still reflect the child’s isolated cascade, not the composed tree.

Calling this method after all append_child() calls fixes both issues by re-running a full depth-first inheritance pass and rebuilding the compact cache from scratch on the composed tree.

Source

pub fn restyle(&mut self, css: Css)

Re-applies CSS styles to the existing DOM structure.

Source

pub fn node_count(&self) -> usize

Returns the total number of nodes in this StyledDom.

Source

pub fn get_css_property_cache<'a>(&'a self) -> &'a CssPropertyCache

Returns an immutable reference to the CSS property cache.

Source

pub fn get_css_property_cache_mut<'a>(&'a mut self) -> &'a mut CssPropertyCache

Returns a mutable reference to the CSS property cache.

Source

pub fn get_styled_node_state(&self, node_id: &NodeId) -> StyledNodeState

Returns the current state (hover, active, focus) of a styled node.

Source

pub fn restyle_nodes_hover( &mut self, nodes: &[NodeId], new_hover_state: bool, ) -> RestyleNodes

Updates hover state for nodes and returns changed CSS properties.

Source

pub fn restyle_nodes_active( &mut self, nodes: &[NodeId], new_active_state: bool, ) -> RestyleNodes

Updates active state for nodes and returns changed CSS properties.

Source

pub fn restyle_nodes_focus( &mut self, nodes: &[NodeId], new_focus_state: bool, ) -> RestyleNodes

Updates focus state for nodes and returns changed CSS properties.

Source

pub fn restyle_on_state_change( &mut self, focus_changes: Option<FocusChange>, hover_changes: Option<HoverChange>, active_changes: Option<ActiveChange>, ) -> RestyleResult

Unified entry point for all CSS restyle operations.

This function synchronizes the StyledNodeState with runtime state and computes which CSS properties have changed. It determines whether layout, display list, or GPU-only updates are needed.

§Arguments
  • focus_changes - Nodes gaining/losing focus
  • hover_changes - Nodes gaining/losing hover
  • active_changes - Nodes gaining/losing active (mouse down)
§Returns
  • RestyleResult containing changed nodes and what needs updating
Source

pub fn restyle_user_property( &mut self, node_id: &NodeId, new_properties: &[CssProperty], ) -> RestyleNodes

Overrides CSS properties for a single node from user code (typically a callback). Writes into CssPropertyCache::user_overridden_properties, which get_property_slow / get_property_fast / get_computed_value consult at higher priority than the static CSS cascade — making this the fast path for animating a handful of properties per frame.

Passing CssProperty::Initial for a property removes any override for that type, restoring the cascaded value. Returns the set of ChangedCssProperty entries the caller can feed into the incremental restyle pipeline.

Source

pub fn get_html_string( &self, custom_head: &str, custom_body: &str, test_mode: bool, ) -> String

Returns a HTML-formatted version of the DOM for easier debugging.

For example, a DOM with a parent div containing a child div would return:

<div id="hello">
     <div id="test" />
</div>
Source

pub fn get_rects_in_rendering_order(&self) -> ContentGroup

Returns nodes grouped by their rendering order (respects z-index and position).

Source

pub fn swap_with_default(&mut self) -> Self

Replaces this StyledDom with default and returns the old value.

Trait Implementations§

Source§

impl Clone for StyledDom

Source§

fn clone(&self) -> StyledDom

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StyledDom

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StyledDom

Source§

fn default() -> Self

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

impl From<DomXml> for StyledDom

Source§

fn from(val: DomXml) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for StyledDom

Source§

fn eq(&self, other: &StyledDom) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for StyledDom

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.