Skip to main content

NodeData

Struct NodeData 

Source
pub struct NodeData {
    pub node_type: NodeType,
    pub callbacks: CoreCallbackDataVec,
    pub style: Css,
    pub flags: NodeFlags,
    pub accessibility: Option<Box<AccessibilityInfo>>,
    /* private fields */
}
Expand description

Represents all data associated with a single DOM node, such as its type, classes, IDs, callbacks, and inline styles.

Fields§

§node_type: NodeType

div, p, img, etc.

§callbacks: CoreCallbackDataVec

Callbacks attached to this node:

On::MouseUp -> Callback(my_button_click_handler)

§style: Css

Inline style: a Css value that applies only to this node (implicit :scope). Each rule carries conditions (@media/@os/:hover/…) and declarations; rules produced by parsing inline strings are tagged rule_priority::INLINE, while widget defaults pushed via with_css_props keep the same INLINE priority so they override author CSS — preserving the cascade priority that the previous per-property css_props field had.

§flags: NodeFlags

Packed flags: tab_index + contenteditable + is_anonymous.

§accessibility: Option<Box<AccessibilityInfo>>

Optional extra accessibility information about this DOM node (MSAA, AT-SPI, UA). 8 bytes (Option<Box> is pointer-sized).

Implementations§

Source§

impl NodeData

Source

pub const fn create_node(node_type: NodeType) -> Self

Creates a new NodeData instance from a given NodeType.

Source

pub fn attributes(&self) -> &AttributeTypeVec

Returns a reference to the node’s attributes (from NodeDataExt). Returns an empty slice if no attributes have been set.

Source

pub fn attributes_mut(&mut self) -> &mut AttributeTypeVec

Returns a mutable reference to the node’s attributes, lazily allocating NodeDataExt if needed.

Source

pub fn set_attributes(&mut self, attrs: AttributeTypeVec)

Sets the node’s attributes, replacing any existing ones.

Source

pub const fn create_body() -> Self

Shorthand for NodeData::create_node(NodeType::Body).

Source

pub const fn create_div() -> Self

Shorthand for NodeData::create_node(NodeType::Div).

Source

pub const fn create_br() -> Self

Shorthand for NodeData::create_node(NodeType::Br).

Source

pub fn create_text<S: Into<AzString>>(value: S) -> Self

Shorthand for NodeData::create_node(NodeType::Text(value.into())).

Source

pub fn create_image(image: ImageRef) -> Self

Shorthand for NodeData::create_node(NodeType::Image(image_id)).

Source

pub fn create_virtual_view( data: RefAny, callback: impl Into<VirtualViewCallback>, ) -> Self

Source

pub fn create_button(aria: SmallAriaInfo) -> Self

Creates a button NodeData with accessibility information.

Source

pub fn create_button_no_a11y() -> Self

Creates a button NodeData without accessibility information.

Source

pub fn create_a(href: AzString, aria: SmallAriaInfo) -> Self

Creates an anchor NodeData with an href and accessibility information.

Source

pub fn create_a_no_a11y(href: AzString) -> Self

Creates an anchor NodeData with an href but no accessibility information.

Source

pub fn create_input( input_type: AzString, name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self

Creates an input NodeData with accessibility information.

Source

pub fn create_input_no_a11y( input_type: AzString, name: AzString, label: AzString, ) -> Self

Creates an input NodeData without accessibility information.

Source

pub fn create_textarea( name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self

Creates a textarea NodeData with accessibility information.

Source

pub fn create_textarea_no_a11y(name: AzString, label: AzString) -> Self

Creates a textarea NodeData without accessibility information.

Source

pub fn create_select( name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self

Creates a select NodeData with accessibility information.

Source

pub fn create_select_no_a11y(name: AzString, label: AzString) -> Self

Creates a select NodeData without accessibility information.

Source

pub fn create_table(aria: SmallAriaInfo) -> Self

Creates a table NodeData with accessibility information.

Source

pub fn create_table_no_a11y() -> Self

Creates a table NodeData without accessibility information.

Source

pub fn create_label(for_id: AzString, aria: SmallAriaInfo) -> Self

Creates a label NodeData with an associated control ID and accessibility information.

Source

pub fn create_label_no_a11y(for_id: AzString) -> Self

Creates a label NodeData with an associated control ID but no accessibility information.

Source

pub fn is_node_type(&self, searched_type: NodeType) -> bool

Checks whether this node is of the given node type (div, image, text).

Source

pub fn has_id(&self, id: &str) -> bool

Checks whether this node has the searched ID attached.

Source

pub fn has_class(&self, class: &str) -> bool

Checks whether this node has the searched class attached.

Source

pub fn has_context_menu(&self) -> bool

Source

pub fn is_text_node(&self) -> bool

Source

pub fn is_virtual_view_node(&self) -> bool

Source

pub const fn get_node_type(&self) -> &NodeType

Source

pub fn get_dataset_mut(&mut self) -> Option<&mut RefAny>

Source

pub fn get_dataset(&self) -> Option<&RefAny>

Source

pub fn take_dataset(&mut self) -> Option<RefAny>

Take the dataset out of the node, replacing it with None.

Source

pub fn get_ids_and_classes(&self) -> IdOrClassVec

Returns IDs and classes as a computed IdOrClassVec. Note: this allocates a new vec each time, prefer has_id()/has_class() for checks.

Source

pub const fn get_callbacks(&self) -> &CoreCallbackDataVec

Source

pub const fn get_style(&self) -> &Css

Source

pub fn get_svg_data(&self) -> Option<&SvgNodeData>

Source

pub fn get_image_clip_mask(&self) -> Option<&ImageMask>

Legacy accessor for raster clip mask. Returns Some only for SvgNodeData::ImageClipMask.

Source

pub fn get_tab_index(&self) -> Option<TabIndex>

Source

pub fn get_accessibility_info(&self) -> Option<&Box<AccessibilityInfo>>

Source

pub fn get_menu_bar(&self) -> Option<&Box<Menu>>

Source

pub fn get_context_menu(&self) -> Option<&Box<Menu>>

Source

pub fn is_anonymous(&self) -> bool

Returns whether this node is an anonymous box generated for table layout.

Source

pub fn set_node_type(&mut self, node_type: NodeType)

Source

pub fn set_dataset(&mut self, data: OptionRefAny)

Source

pub fn set_ids_and_classes(&mut self, ids_and_classes: IdOrClassVec)

Sets the IDs and classes by converting IdOrClassVec entries into AttributeType::Id/AttributeType::Class and merging them into self.attributes. Any existing Id/Class attributes are removed first.

Source

pub fn set_callbacks(&mut self, callbacks: CoreCallbackDataVec)

Source

pub fn set_css_props(&mut self, css_props: CssPropertyWithConditionsVec)

Legacy: replace this node’s inline style with a flat list of property+conditions. Each entry becomes a single-declaration rule at rule_priority::INLINE. Prefer set_style (or with_style / with_css(&str)) for new code.

Source

pub fn set_style(&mut self, style: Css)

Replace this node’s inline style with a Css value. The Css’s rules apply only to this node (implicit :scope).

Source

pub fn set_clip_mask(&mut self, clip_mask: ImageMask)

Source

pub fn set_svg_data(&mut self, data: SvgNodeData)

Source

pub fn set_tab_index(&mut self, tab_index: TabIndex)

Source

pub fn set_contenteditable(&mut self, contenteditable: bool)

Source

pub fn is_contenteditable(&self) -> bool

Source

pub fn set_accessibility_info(&mut self, accessibility_info: AccessibilityInfo)

Source

pub fn set_anonymous(&mut self, is_anonymous: bool)

Marks this node as an anonymous box (generated for table layout).

Source

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

Source

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

Source

pub fn set_key<K: Hash>(&mut self, key: K)

Sets a stable key for this node used in reconciliation.

This key is used to track node identity across DOM updates, enabling the framework to distinguish between “moving” a node and “destroying/creating” one. This is crucial for correct lifecycle events when lists are reordered.

§Example
node_data.set_key("user-123");
Source

pub fn get_key(&self) -> Option<u64>

Gets the key for this node, if set.

Source

pub fn set_merge_callback<C: Into<DatasetMergeCallback>>(&mut self, callback: C)

Sets a dataset merge callback for this node.

The merge callback is invoked during reconciliation when a node from the previous frame is matched with a node in the new frame. It allows heavy resources (video decoders, GL textures, network connections) to be transferred from the old node to the new node instead of being destroyed.

§Type Safety

The callback stores the TypeId of T. During execution, both the old and new datasets must match this type, otherwise the merge is skipped.

§Example
struct VideoPlayer {
    url: String,
    decoder: Option<DecoderHandle>,
}

extern "C" fn merge_video(new_data: RefAny, old_data: RefAny) -> RefAny {
    // Transfer the heavy decoder handle from old to new
    if let (Some(mut new), Some(old)) = (
        new_data.downcast_mut::<VideoPlayer>(),
        old_data.downcast_ref::<VideoPlayer>()
    ) {
        new.decoder = old.decoder.take();
    }
    new_data
}

node_data.set_merge_callback(merge_video);
Source

pub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>

Gets the merge callback for this node, if set.

Source

pub fn set_component_origin(&mut self, origin: ComponentOrigin)

Sets the component origin for this node.

This stamps the node with information about which component rendered it, enabling the debugger to reconstruct the component invocation tree.

Source

pub fn get_component_origin(&self) -> Option<&ComponentOrigin>

Gets the component origin for this node, if set.

Source

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

Source

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

Source

pub fn add_callback<C: Into<CoreCallback>>( &mut self, event: EventFilter, data: RefAny, callback: C, )

Source

pub fn add_id(&mut self, s: AzString)

Source

pub fn add_class(&mut self, s: AzString)

Source

pub fn add_css_property(&mut self, p: CssPropertyWithConditions)

Add a CSS property with optional conditions (hover, focus, active, etc.).

Wraps the property in a single-declaration rule at rule_priority::INLINE and appends it to this node’s inline style.

Source

pub fn calculate_node_data_hash(&self) -> DomNodeHash

Calculates a deterministic node hash for this node.

Source

pub fn calculate_structural_hash(&self) -> DomNodeHash

Calculates a structural hash for DOM reconciliation that ignores text content.

This hash is used for matching nodes across DOM frames where the text content may have changed (e.g., contenteditable text being edited). It hashes:

  • Node type discriminant (but NOT the text content for Text nodes)
  • IDs and classes
  • Attributes (but NOT contenteditable state which may change with focus)
  • Callback events and types

This allows a Text(“Hello”) node to match Text(“Hello World”) during reconciliation, preserving cursor position and selection state.

Source

pub fn with_tab_index(self, tab_index: TabIndex) -> Self

Source

pub fn with_contenteditable(self, contenteditable: bool) -> Self

Source

pub fn with_node_type(self, node_type: NodeType) -> Self

Source

pub fn with_callback<C: Into<CoreCallback>>( self, event: EventFilter, data: RefAny, callback: C, ) -> Self

Source

pub fn with_dataset(self, data: OptionRefAny) -> Self

Source

pub fn with_ids_and_classes(self, ids_and_classes: IdOrClassVec) -> Self

Source

pub fn with_callbacks(self, callbacks: CoreCallbackDataVec) -> Self

Source

pub fn with_css_props(self, css_props: CssPropertyWithConditionsVec) -> Self

Legacy: builder-form of set_css_props. Each CssPropertyWithConditions becomes a single-declaration rule at rule_priority::INLINE. Prefer with_style(Css) for new code.

Source

pub fn with_style(self, style: Css) -> Self

Builder-form of set_style.

Source

pub fn with_key<K: Hash>(self, key: K) -> Self

Assigns a stable key to this node for reconciliation.

This is crucial for performance and correct state preservation when lists of items change order or items are inserted/removed. Without keys, the reconciliation algorithm falls back to hash-based matching.

§Example
NodeData::create_div()
    .with_key("user-avatar-123");
Source

pub fn with_merge_callback<C: Into<DatasetMergeCallback>>( self, callback: C, ) -> Self

Registers a callback to merge dataset state from the previous frame.

This is used for components that maintain heavy internal state (video players, WebGL contexts, network connections) that should not be destroyed and recreated on every render frame.

The callback receives both datasets as RefAny (cheap shallow clones) and returns the RefAny that should be used for the new node.

§Example
struct VideoPlayer {
    url: String,
    decoder_handle: Option<DecoderHandle>,
}

extern "C" fn merge_video(new_data: RefAny, old_data: RefAny) -> RefAny {
    if let (Some(mut new), Some(old)) = (
        new_data.downcast_mut::<VideoPlayer>(),
        old_data.downcast_ref::<VideoPlayer>()
    ) {
        new.decoder_handle = old.decoder_handle.take();
    }
    new_data
}

NodeData::create_div()
    .with_dataset(RefAny::new(VideoPlayer::new("movie.mp4")).into())
    .with_merge_callback(merge_video)
Source

pub fn set_css(&mut self, style: &str)

Parse and set CSS styles with full selector support.

This is the unified API for setting inline CSS on a node. It supports:

  • Simple properties: color: red; font-size: 14px;
  • Pseudo-selectors: :hover { background: blue; }
  • @-rules: @os linux { font-size: 14px; }
  • Nesting: @os linux { font-size: 14px; :hover { color: red; }}
§Examples
NodeData::create_div().with_css("
    color: blue;
    :hover { color: red; }
    @os linux { font-size: 14px; }
");
Source

pub fn with_css(self, style: &str) -> Self

Builder method for set_css

Source

pub fn swap_with_default(&mut self) -> Self

Source

pub fn copy_special(&self) -> Self

Source

pub fn is_focusable(&self) -> bool

Source

pub fn has_activation_behavior(&self) -> bool

Returns true if this element has “activation behavior” per HTML5 spec.

Elements with activation behavior can be activated via Enter or Space key when focused, which generates a synthetic click event.

Per HTML5 spec, elements with activation behavior include:

  • Button elements
  • Input elements (submit, button, reset, checkbox, radio)
  • Anchor elements with href
  • Any element with a click callback (implicit activation)

See: https://html.spec.whatwg.org/multipage/interaction.html#activation-behavior

Source

pub fn is_activatable(&self) -> bool

Returns true if this element is currently activatable.

An element is activatable if it has activation behavior AND is not disabled. This checks for common disability patterns (aria-disabled, disabled attribute).

Source

pub fn get_effective_tabindex(&self) -> Option<i32>

Returns the tab index for this element.

Tab index determines keyboard navigation order:

  • None: Not in tab order (unless naturally focusable)
  • Some(-1): Focusable programmatically but not via Tab
  • Some(0): In natural tab order
  • Some(n > 0): In tab order with priority n (higher = later)
Source

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

Returns the accessible label for this node.

Priority: aria-label attribute > alt attribute > title attribute > None. Does NOT include child text — the caller should collect that separately using the DOM hierarchy.

Source

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

Returns the accessible value for this node.

Priority: value attribute > None. For text inputs, this is the input’s current value.

Source

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

Returns the placeholder text for this node.

Source

pub fn get_virtual_view_node(&mut self) -> Option<&mut VirtualViewNode>

Source

pub fn get_virtual_view_node_ref(&self) -> Option<&VirtualViewNode>

Source

pub fn get_render_image_callback_node<'a>( &'a mut self, ) -> Option<(&'a mut CoreImageCallback, ImageRefHash)>

Source

pub fn debug_print_start( &self, css_cache: &CssPropertyCache, node_id: &NodeId, node_state: &StyledNodeState, ) -> String

Source

pub fn debug_print_end(&self) -> String

Trait Implementations§

Source§

impl ActivationBehavior for NodeData

Source§

fn has_activation_behavior(&self) -> bool

Returns true if this element can be activated via keyboard (Enter/Space)
Source§

fn is_activatable(&self) -> bool

Returns true if this element is currently activatable (e.g., not disabled, not aria-disabled=“true”)
Source§

impl Clone for NodeData

Source§

fn clone(&self) -> Self

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 NodeData

Source§

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

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

impl Default for NodeData

Source§

fn default() -> Self

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

impl Display for NodeData

Source§

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

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

impl Extend<NodeData> for NodeDataVec

Source§

fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Focusable for NodeData

Source§

fn get_tabindex(&self) -> Option<i32>

Returns the tabindex value for this element (-1, 0, or positive)
Source§

fn is_focusable(&self) -> bool

Returns true if this element can receive focus
Source§

fn is_naturally_focusable(&self) -> bool

Returns true if this element type is naturally focusable (button, input, select, textarea, a[href])
Source§

fn is_in_tab_order(&self) -> bool

Returns true if this element should be in the tab order
Source§

impl FromIterator<NodeData> for NodeDataVec

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = NodeData>,

Creates a value from an iterator. Read more
Source§

impl Hash for NodeData

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for NodeData

Source§

fn cmp(&self, other: &NodeData) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for NodeData

Source§

fn eq(&self, other: &NodeData) -> 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 PartialOrd for NodeData

Source§

fn partial_cmp(&self, other: &NodeData) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for NodeData

Source§

impl Send for NodeData

Source§

impl StructuralPartialEq for NodeData

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> GetHash for T
where T: Hash,

Source§

fn get_hash(&self) -> u64

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.