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: NodeTypediv, p, img, etc.
callbacks: CoreCallbackDataVecCallbacks attached to this node:
On::MouseUp -> Callback(my_button_click_handler)
style: CssInline 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: NodeFlagsPacked 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
Implementations§
Source§impl NodeData
impl NodeData
Sourcepub const fn create_node(node_type: NodeType) -> Self
pub const fn create_node(node_type: NodeType) -> Self
Creates a new NodeData instance from a given NodeType.
Sourcepub fn attributes(&self) -> &AttributeTypeVec
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.
Sourcepub fn attributes_mut(&mut self) -> &mut AttributeTypeVec
pub fn attributes_mut(&mut self) -> &mut AttributeTypeVec
Returns a mutable reference to the node’s attributes, lazily allocating NodeDataExt if needed.
Sourcepub fn set_attributes(&mut self, attrs: AttributeTypeVec)
pub fn set_attributes(&mut self, attrs: AttributeTypeVec)
Sets the node’s attributes, replacing any existing ones.
Sourcepub const fn create_body() -> Self
pub const fn create_body() -> Self
Shorthand for NodeData::create_node(NodeType::Body).
Sourcepub const fn create_div() -> Self
pub const fn create_div() -> Self
Shorthand for NodeData::create_node(NodeType::Div).
Sourcepub fn create_text<S: Into<AzString>>(value: S) -> Self
pub fn create_text<S: Into<AzString>>(value: S) -> Self
Shorthand for NodeData::create_node(NodeType::Text(value.into())).
Sourcepub fn create_image(image: ImageRef) -> Self
pub fn create_image(image: ImageRef) -> Self
Shorthand for NodeData::create_node(NodeType::Image(image_id)).
pub fn create_virtual_view( data: RefAny, callback: impl Into<VirtualViewCallback>, ) -> Self
Creates a button NodeData with accessibility information.
Creates a button NodeData without accessibility information.
Sourcepub fn create_a(href: AzString, aria: SmallAriaInfo) -> Self
pub fn create_a(href: AzString, aria: SmallAriaInfo) -> Self
Creates an anchor NodeData with an href and accessibility information.
Sourcepub fn create_a_no_a11y(href: AzString) -> Self
pub fn create_a_no_a11y(href: AzString) -> Self
Creates an anchor NodeData with an href but no accessibility information.
Sourcepub fn create_input(
input_type: AzString,
name: AzString,
label: AzString,
aria: SmallAriaInfo,
) -> Self
pub fn create_input( input_type: AzString, name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self
Creates an input NodeData with accessibility information.
Sourcepub fn create_input_no_a11y(
input_type: AzString,
name: AzString,
label: AzString,
) -> Self
pub fn create_input_no_a11y( input_type: AzString, name: AzString, label: AzString, ) -> Self
Creates an input NodeData without accessibility information.
Sourcepub fn create_textarea(
name: AzString,
label: AzString,
aria: SmallAriaInfo,
) -> Self
pub fn create_textarea( name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self
Creates a textarea NodeData with accessibility information.
Sourcepub fn create_textarea_no_a11y(name: AzString, label: AzString) -> Self
pub fn create_textarea_no_a11y(name: AzString, label: AzString) -> Self
Creates a textarea NodeData without accessibility information.
Sourcepub fn create_select(
name: AzString,
label: AzString,
aria: SmallAriaInfo,
) -> Self
pub fn create_select( name: AzString, label: AzString, aria: SmallAriaInfo, ) -> Self
Creates a select NodeData with accessibility information.
Sourcepub fn create_select_no_a11y(name: AzString, label: AzString) -> Self
pub fn create_select_no_a11y(name: AzString, label: AzString) -> Self
Creates a select NodeData without accessibility information.
Sourcepub fn create_table(aria: SmallAriaInfo) -> Self
pub fn create_table(aria: SmallAriaInfo) -> Self
Creates a table NodeData with accessibility information.
Sourcepub fn create_table_no_a11y() -> Self
pub fn create_table_no_a11y() -> Self
Creates a table NodeData without accessibility information.
Sourcepub fn create_label(for_id: AzString, aria: SmallAriaInfo) -> Self
pub fn create_label(for_id: AzString, aria: SmallAriaInfo) -> Self
Creates a label NodeData with an associated control ID and accessibility
information.
Sourcepub fn create_label_no_a11y(for_id: AzString) -> Self
pub fn create_label_no_a11y(for_id: AzString) -> Self
Creates a label NodeData with an associated control ID but no
accessibility information.
Sourcepub fn is_node_type(&self, searched_type: NodeType) -> bool
pub fn is_node_type(&self, searched_type: NodeType) -> bool
Checks whether this node is of the given node type (div, image, text).
Sourcepub fn has_class(&self, class: &str) -> bool
pub fn has_class(&self, class: &str) -> bool
Checks whether this node has the searched class attached.
pub fn is_text_node(&self) -> bool
pub fn is_virtual_view_node(&self) -> bool
pub const fn get_node_type(&self) -> &NodeType
pub fn get_dataset_mut(&mut self) -> Option<&mut RefAny>
pub fn get_dataset(&self) -> Option<&RefAny>
Sourcepub fn take_dataset(&mut self) -> Option<RefAny>
pub fn take_dataset(&mut self) -> Option<RefAny>
Take the dataset out of the node, replacing it with None.
Sourcepub fn get_ids_and_classes(&self) -> IdOrClassVec
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.
pub const fn get_callbacks(&self) -> &CoreCallbackDataVec
pub const fn get_style(&self) -> &Css
pub fn get_svg_data(&self) -> Option<&SvgNodeData>
Sourcepub fn get_image_clip_mask(&self) -> Option<&ImageMask>
pub fn get_image_clip_mask(&self) -> Option<&ImageMask>
Legacy accessor for raster clip mask. Returns Some only for SvgNodeData::ImageClipMask.
pub fn get_tab_index(&self) -> Option<TabIndex>
pub fn get_accessibility_info(&self) -> Option<&Box<AccessibilityInfo>>
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Returns whether this node is an anonymous box generated for table layout.
pub fn set_node_type(&mut self, node_type: NodeType)
pub fn set_dataset(&mut self, data: OptionRefAny)
Sourcepub fn set_ids_and_classes(&mut self, ids_and_classes: IdOrClassVec)
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.
pub fn set_callbacks(&mut self, callbacks: CoreCallbackDataVec)
Sourcepub fn set_css_props(&mut self, css_props: CssPropertyWithConditionsVec)
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.
Sourcepub fn set_style(&mut self, style: Css)
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).
pub fn set_clip_mask(&mut self, clip_mask: ImageMask)
pub fn set_svg_data(&mut self, data: SvgNodeData)
pub fn set_tab_index(&mut self, tab_index: TabIndex)
pub fn set_contenteditable(&mut self, contenteditable: bool)
pub fn is_contenteditable(&self) -> bool
pub fn set_accessibility_info(&mut self, accessibility_info: AccessibilityInfo)
Sourcepub fn set_anonymous(&mut self, is_anonymous: bool)
pub fn set_anonymous(&mut self, is_anonymous: bool)
Marks this node as an anonymous box (generated for table layout).
Sourcepub fn set_key<K: Hash>(&mut self, key: K)
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");Sourcepub fn set_merge_callback<C: Into<DatasetMergeCallback>>(&mut self, callback: C)
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);Sourcepub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>
pub fn get_merge_callback(&self) -> Option<DatasetMergeCallback>
Gets the merge callback for this node, if set.
Sourcepub fn set_component_origin(&mut self, origin: ComponentOrigin)
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.
Sourcepub fn get_component_origin(&self) -> Option<&ComponentOrigin>
pub fn get_component_origin(&self) -> Option<&ComponentOrigin>
Gets the component origin for this node, if set.
pub fn add_callback<C: Into<CoreCallback>>( &mut self, event: EventFilter, data: RefAny, callback: C, )
pub fn add_id(&mut self, s: AzString)
pub fn add_class(&mut self, s: AzString)
Sourcepub fn add_css_property(&mut self, p: CssPropertyWithConditions)
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.
Sourcepub fn calculate_node_data_hash(&self) -> DomNodeHash
pub fn calculate_node_data_hash(&self) -> DomNodeHash
Calculates a deterministic node hash for this node.
Sourcepub fn calculate_structural_hash(&self) -> DomNodeHash
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.
pub fn with_tab_index(self, tab_index: TabIndex) -> Self
pub fn with_contenteditable(self, contenteditable: bool) -> Self
pub fn with_node_type(self, node_type: NodeType) -> Self
pub fn with_callback<C: Into<CoreCallback>>( self, event: EventFilter, data: RefAny, callback: C, ) -> Self
pub fn with_dataset(self, data: OptionRefAny) -> Self
pub fn with_ids_and_classes(self, ids_and_classes: IdOrClassVec) -> Self
pub fn with_callbacks(self, callbacks: CoreCallbackDataVec) -> Self
Sourcepub fn with_css_props(self, css_props: CssPropertyWithConditionsVec) -> Self
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.
Sourcepub fn with_style(self, style: Css) -> Self
pub fn with_style(self, style: Css) -> Self
Builder-form of set_style.
Sourcepub fn with_key<K: Hash>(self, key: K) -> Self
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");Sourcepub fn with_merge_callback<C: Into<DatasetMergeCallback>>(
self,
callback: C,
) -> Self
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)Sourcepub fn set_css(&mut self, style: &str)
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; }
");pub fn swap_with_default(&mut self) -> Self
pub fn copy_special(&self) -> Self
pub fn is_focusable(&self) -> bool
Sourcepub fn has_activation_behavior(&self) -> bool
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
Sourcepub fn is_activatable(&self) -> bool
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).
Sourcepub fn get_effective_tabindex(&self) -> Option<i32>
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 TabSome(0): In natural tab orderSome(n > 0): In tab order with priority n (higher = later)
Sourcepub fn get_accessible_label(&self) -> Option<&str>
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.
Sourcepub fn get_accessible_value(&self) -> Option<&str>
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.
Sourcepub fn get_placeholder(&self) -> Option<&str>
pub fn get_placeholder(&self) -> Option<&str>
Returns the placeholder text for this node.
pub fn get_virtual_view_node(&mut self) -> Option<&mut VirtualViewNode>
pub fn get_virtual_view_node_ref(&self) -> Option<&VirtualViewNode>
pub fn get_render_image_callback_node<'a>( &'a mut self, ) -> Option<(&'a mut CoreImageCallback, ImageRefHash)>
pub fn debug_print_start( &self, css_cache: &CssPropertyCache, node_id: &NodeId, node_state: &StyledNodeState, ) -> String
pub fn debug_print_end(&self) -> String
Trait Implementations§
Source§impl ActivationBehavior for NodeData
impl ActivationBehavior for NodeData
Source§fn has_activation_behavior(&self) -> bool
fn has_activation_behavior(&self) -> bool
Source§fn is_activatable(&self) -> bool
fn is_activatable(&self) -> bool
Source§impl Extend<NodeData> for NodeDataVec
impl Extend<NodeData> for NodeDataVec
Source§fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = NodeData>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)