pub struct Dom<Ext: 'static = ()> { /* private fields */ }Implementations§
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn node(&self, id: NodeId) -> NodeRef<'_, Ext>
pub fn node(&self, id: NodeId) -> NodeRef<'_, Ext>
Read accessor for id. Construction does not validate the id:
most NodeRef methods return None / empty for a dead id, but
the ones that have no empty value (node_type, node_name)
panic. Check Dom::contains first when the id may be stale.
Source§impl<Ext: 'static> Dom<Ext>
impl<Ext: 'static> Dom<Ext>
pub fn set_attribute( &mut self, id: NodeId, key: &str, value: &str, ) -> Result<()>
pub fn get_attribute(&self, id: NodeId, key: &str) -> Option<&str>
pub fn remove_attribute(&mut self, id: NodeId, key: &str) -> Result<bool>
pub fn has_attribute(&self, id: NodeId, key: &str) -> bool
Sourcepub fn toggle_attribute(&mut self, id: NodeId, key: &str) -> Result<bool>
pub fn toggle_attribute(&mut self, id: NodeId, key: &str) -> Result<bool>
Toggle: if absent, set to empty string; if present, remove. Returns the new presence state.
Sourcepub fn attributes(&self, id: NodeId) -> impl Iterator<Item = (&str, &str)>
pub fn attributes(&self, id: NodeId) -> impl Iterator<Item = (&str, &str)>
Iterate (name, value) pairs in deterministic (alphabetic) order.
pub fn id_attr(&self, id: NodeId) -> Option<&str>
pub fn add_class(&mut self, id: NodeId, class: &str) -> Result<()>
pub fn remove_class(&mut self, id: NodeId, class: &str) -> Result<bool>
pub fn toggle_class(&mut self, id: NodeId, class: &str) -> Result<bool>
pub fn has_class(&self, id: NodeId, class: &str) -> bool
pub fn replace_class( &mut self, id: NodeId, old: &str, new: &str, ) -> Result<bool>
Sourcepub fn class_list(&self, id: NodeId) -> impl Iterator<Item = &str>
pub fn class_list(&self, id: NodeId) -> impl Iterator<Item = &str>
Iterate class tokens in alphabetic order.
Source§impl<Ext: Clone> Dom<Ext>
impl<Ext: Clone> Dom<Ext>
Sourcepub fn clone_node(&mut self, id: NodeId, deep: bool) -> NodeId
pub fn clone_node(&mut self, id: NodeId, deep: bool) -> NodeId
Produce an orphan clone of id. If deep, recursively clone all
descendants. If not, only the node itself.
Returns the new orphan’s NodeId. The caller must attach it with
append_child / insert_before to make it live in the tree.
Source§impl<Ext: 'static> Dom<Ext>
impl<Ext: 'static> Dom<Ext>
Sourcepub fn set_validity_hook(&mut self, hook: Option<ValidityHook<Ext>>)
pub fn set_validity_hook(&mut self, hook: Option<ValidityHook<Ext>>)
Install (or remove, with None) the backend’s constraint check
behind :valid / :invalid and constraint_validity.
A Dom has no hook until one is installed, and without one
every candidate is valid. rdom-core cannot compute validity
states itself (they need values, patterns and a custom validity),
so an unhooked Dom answers “valid” for every candidate — an
<input>, <select>, <textarea> or submit button, and so a
<form> / <fieldset> holding one: :valid matches, :invalid
never does, whatever required / pattern say. The answer is
the same in debug and release builds, and nothing is logged
(rdom-core has no warning channel). rdom-tui’s App installs its
hook at construction; a bare TuiDom cascaded without an App
must call rdom_tui::runtime::builtins::validation::install, and
a backend-less Dom that matches these pseudo-classes installs
its own.
Sourcepub fn constraint_validity(&self, id: NodeId) -> Option<bool>
pub fn constraint_validity(&self, id: NodeId) -> Option<bool>
What :valid / :invalid match (HTML §4.16.3):
- a candidate:
Some(verdict)of the validity hook (set_validity_hook);Some(true)without one, in every build; - a
<form>:Some(false)when a candidate it owns (form_listed_elements) is invalid, elseSome(true); - a
<fieldset>: the same over its descendant candidates; - anything else, barred controls included:
None(neither).
Sourcepub fn is_required_control(&self, id: NodeId) -> bool
pub fn is_required_control(&self, id: NodeId) -> bool
Whether id matches :required (HTML §4.16.3): an <input> in
a state the required attribute applies to (not hidden, range,
color or the button types), a <select> or a <textarea>, with
required.
Sourcepub fn required_applies(&self, id: NodeId) -> bool
pub fn required_applies(&self, id: NodeId) -> bool
Whether the required attribute applies to id (HTML §4.10.5.3.4
and the per-state lists of §4.10.5.1): a <select>, a
<textarea>, or an <input> in any state but hidden, range,
color and the button types — the one list behind :required /
:optional and a backend’s valueMissing check.
Sourcepub fn is_optional_control(&self, id: NodeId) -> bool
pub fn is_optional_control(&self, id: NodeId) -> bool
Whether id matches :optional: an <input>, <select> or
<textarea> that is not required.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn will_validate(&self, id: NodeId) -> bool
pub fn will_validate(&self, id: NodeId) -> bool
Whether id is a candidate for constraint validation (HTML
§4.10.20.1, the willValidate IDL attribute): a submittable
element (<button>, <input>, <select>, <textarea>) that is
not barred. Barred are:
- an actually disabled control
(own
disabled, or a disabled<fieldset>); - a control with a
<datalist>ancestor; - a
<button>that is not a submit button; - an
<input>in the Hidden, Reset or Button state; - an
<input>withreadonlyin a statereadonlyapplies to (the text, date / time and number states — not a checkbox), and a<textarea readonly>.
<object>, <output> and <fieldset> are never candidates.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn content_editable_state(&self, id: NodeId) -> Option<ContentEditableState>
pub fn content_editable_state(&self, id: NodeId) -> Option<ContentEditableState>
id’s explicit contenteditable state, or None for the
inherit state (attribute missing or invalid) and for non-elements.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn add_event_listener(
&mut self,
node: NodeId,
event_type: impl Into<String>,
options: ListenerOptions,
handler: impl FnMut(&mut EventCtx<'_, Ext>) + 'static,
) -> Result<ListenerId>
pub fn add_event_listener( &mut self, node: NodeId, event_type: impl Into<String>, options: ListenerOptions, handler: impl FnMut(&mut EventCtx<'_, Ext>) + 'static, ) -> Result<ListenerId>
Register a listener on node for events of type event_type.
Returns a ListenerId that can be passed to remove_event_listener.
Sourcepub fn remove_event_listener(&mut self, handle: ListenerId) -> bool
pub fn remove_event_listener(&mut self, handle: ListenerId) -> bool
Remove a previously-registered listener. Returns true if the
listener existed and was removed; false if it was already gone
(e.g. a once handler that already fired).
Sourcepub fn listener_count(&self, node: NodeId) -> usize
pub fn listener_count(&self, node: NodeId) -> usize
How many listeners are currently registered on node.
Sourcepub fn set_activation_hook(&mut self, hook: Option<ActivationHook<Ext>>)
pub fn set_activation_hook(&mut self, hook: Option<ActivationHook<Ext>>)
Install (or remove, with None) the Dom’s activation-behavior hook.
See ActivationHook. A backend installs one hook for all its
elements with activation behavior and dispatches on tag / type
inside it.
Sourcepub fn dispatch_event(
&mut self,
target: NodeId,
event: &mut Event,
) -> Result<()>
pub fn dispatch_event( &mut self, target: NodeId, event: &mut Event, ) -> Result<()>
Dispatch event at target per DOM §2.9: one capture pass from
the root down, one bubble pass from the target up. The target
takes part in both — its capture listeners fire in the capture
pass and its non-capture listeners in the bubble pass, each
reporting EventPhase::AtTarget — so registration order never
interleaves them, and stop_propagation() in a target capture
listener suppresses the target’s bubble listeners. Returns Err
on an invalid target.
When dispatch ends, phase, current_target, and the two
stop-propagation flags are reset (spec step 5.9), so the same
Event value can be dispatched again; default_prevented
persists.
Handlers may mutate the Dom via EventCtx::dom. The ancestor path
is computed up-front so mid-dispatch mutations don’t destabilize
iteration. Listeners added during dispatch fire on subsequent
dispatches, not the current one.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn hovered(&self) -> Option<NodeId>
pub fn hovered(&self) -> Option<NodeId>
The node currently flagged as hovered (see :hover). None when
nothing is hovered. Matching consults this field directly.
Sourcepub fn active(&self) -> Option<NodeId>
pub fn active(&self) -> Option<NodeId>
The element currently being activated (see :active): the
backend sets it for the duration of a primary-button press.
None when nothing is being activated.
Sourcepub fn focus_visible(&self) -> bool
pub fn focus_visible(&self) -> bool
Whether the focused element’s focus should be made evident —
the UA’s judgement behind :focus-visible (Selectors 4 §13.2),
which matches the focused element exactly while this is true.
Starts true (focus before any pointer interaction is evident,
as browsers treat script focus on a fresh page); a backend flips
it with set_focus_visible from its
input-modality heuristics. It persists across focus changes, so
focus moved by script keeps the previous element’s visibility,
as the spec asks.
Sourcepub fn pointer_capture(&self) -> Option<NodeId>
pub fn pointer_capture(&self) -> Option<NodeId>
The node that currently owns the pointer via
set_pointer_capture. None
(the default) means routing uses hit-testing as usual.
Sourcepub fn selection(&self) -> Option<&Selection>
pub fn selection(&self) -> Option<&Selection>
The document’s text selection, if any. None means no
selection (not even a caret). Mutated via
set_selection which fires
Mutation::SelectionChanged for paint observers.
Sourcepub fn selection_range(&self) -> Option<Range>
pub fn selection_range(&self) -> Option<Range>
The current selection normalized to a document-ordered
Range — start precedes end per
compare_boundary_points.
Useful for paint + copy walks that need ordered traversal.
Returns None when nothing is selected OR when the
anchor/focus nodes are disconnected (shouldn’t happen in
practice, but handled defensively).
Source§impl<Ext: 'static> Dom<Ext>
impl<Ext: 'static> Dom<Ext>
Sourcepub fn set_hovered(&mut self, id: Option<NodeId>)
pub fn set_hovered(&mut self, id: Option<NodeId>)
Set or clear the hovered node. Fires an InteractionChanged
mutation record when the value actually changes; no-op when
setting to the current value.
Sourcepub fn set_active(&mut self, id: Option<NodeId>)
pub fn set_active(&mut self, id: Option<NodeId>)
Set or clear the element being activated (:active). Fires an
InteractionChanged { kind: Active } record when the value
changes; no-op otherwise. Detaching the element clears it, like
hover and focus.
Sourcepub fn set_focused(&mut self, id: Option<NodeId>)
pub fn set_focused(&mut self, id: Option<NodeId>)
Set or clear the focused node. Fires an InteractionChanged
record on change.
Sourcepub fn set_focus_visible(&mut self, visible: bool)
pub fn set_focus_visible(&mut self, visible: bool)
Set whether the focused element’s focus should be made evident
(see focus_visible). Fires an
InteractionChanged { kind: FocusVisible } record naming the
focused element as both prev and next when the value
changes; no-op otherwise.
Sourcepub fn set_pointer_capture(&mut self, id: NodeId) -> Result<()>
pub fn set_pointer_capture(&mut self, id: NodeId) -> Result<()>
Claim the pointer for id. While set, the runtime routes
mousemove / drag / mouseup to id regardless of where
the cursor lands — critical for drag-select, resize
handles, scrubbing.
Typical usage from a mousedown listener:
dom.add_event_listener(handle, "mousedown",
ListenerOptions::default(), |ctx| {
let target = ctx.event.target.unwrap();
ctx.dom.set_pointer_capture(target).unwrap();
})?;The capture releases automatically on mouseup, or can be
released explicitly via release_pointer_capture.
Returns Err(DomError::InvalidNode) if id doesn’t exist.
Does not fire a mutation record — pointer capture
doesn’t affect cascade / selectors (no :pointer-captured
pseudo in v1).
Sourcepub fn release_pointer_capture(&mut self)
pub fn release_pointer_capture(&mut self)
Release any active pointer capture. Idempotent — no-op when nothing was captured. Also clears the drag-autoscroll opt-in.
Sourcepub fn set_drag_autoscroll(&mut self, on: bool)
pub fn set_drag_autoscroll(&mut self, on: bool)
Opt the active captured drag into edge autoscroll (DRAG-AUTOSCROLL):
while set, the backend scrolls the nearest scroll container as the
pointer dwells at its edge. Pair with
set_pointer_capture from a drag’s
mousedown handler (the same handler should prevent_default so the
runtime’s own text-selection/scrollbar defaults don’t claim the drag).
Auto-cleared when the capture releases. No-op without an active capture.
Sourcepub fn drag_autoscroll(&self) -> bool
pub fn drag_autoscroll(&self) -> bool
Whether the active captured drag opted into edge autoscroll. Read by the backend each frame to decide whether to run the autoscroll phase.
Sourcepub fn set_selection(&mut self, next: Option<Selection>)
pub fn set_selection(&mut self, next: Option<Selection>)
Set the document selection. None clears it.
Fires Mutation::SelectionChanged { prev, next } on change
so paint observers can refresh the ::selection overlay.
No-op when next == current selection.
Sourcepub fn selection_serial(&self) -> SelectionSerial
pub fn selection_serial(&self) -> SelectionSerial
A counter that advances on every actual selection change —
every set_selection that fires
Mutation::SelectionChanged, including the clear when the
selected nodes leave the tree. Equal readings mean the selection
was not touched in between, even if it moved away and back.
Backends use it to tell their own caret updates from foreign ones without observing mutations — rdom-tui’s undo grouping keeps a typing run open only while the selection is the one its last edit left (Blink closes the typing command on any other selection change). No web API exposes this; it is bookkeeping.
Sourcepub fn query_selector(&self, selector: &str) -> Option<NodeRef<'_, Ext>>
pub fn query_selector(&self, selector: &str) -> Option<NodeRef<'_, Ext>>
Find the first element in the document matching selector,
in document order. DOM Document.querySelector.
Document-rooted shortcut for the more general
Self::query_selector_in. Malformed selectors return
None (browser-DOM throws; rdom diverges per §9.1 spec
table).
Sourcepub fn query_selector_all(&self, selector: &str) -> NodeList<'_, Ext>
pub fn query_selector_all(&self, selector: &str) -> NodeList<'_, Ext>
All elements in the document matching selector, in
document order. DOM Document.querySelectorAll.
Document-rooted shortcut for
Self::query_selector_all_in. Malformed selectors yield
an empty list.
Sourcepub fn elements_by_tag(&self, tag: &str) -> NodeList<'_, Ext>
pub fn elements_by_tag(&self, tag: &str) -> NodeList<'_, Ext>
All elements in the document with the given tag name, in
document order. DOM Document.getElementsByTagName.
Returns a snapshot — unlike browser’s live HTMLCollection (Lock #2, parity ledger §25). Tag comparison is case- sensitive (rdom tags are lowercased at parse time, so authors pass lowercase).
Sourcepub fn document_element(&self) -> NodeRef<'_, Ext>
pub fn document_element(&self) -> NodeRef<'_, Ext>
The document element. DOM Document.documentElement.
When the root is an element (typically <html> via
Dom::with_root_tag("html")), this is the root itself.
When the root is a Fragment (the default), returns the
first element child of the fragment, or the fragment
itself if it has no element children.
Sourcepub fn active_element(&self) -> Option<NodeRef<'_, Ext>>
pub fn active_element(&self) -> Option<NodeRef<'_, Ext>>
The currently focused element. DOM Document.activeElement.
Alias for Self::focused returning a NodeRef.
Sourcepub fn has_focus(&self) -> bool
pub fn has_focus(&self) -> bool
true iff the document has a focused element. DOM
Document.hasFocus. (rdom has a single document; the
browser semantics of “focused window” don’t apply.)
Sourcepub fn create_range(&self) -> Range
pub fn create_range(&self) -> Range
Construct an empty Range collapsed at the document root,
offset 0. DOM Document.createRange().
The returned range can be re-anchored via struct-literal
assignment or Range::ordered_unchecked. Range boundary
setters (setStart / setEnd) are polish.
Source§impl<Ext: Default> Dom<Ext>
impl<Ext: Default> Dom<Ext>
Sourcepub fn with_root_tag(tag: &str) -> Self
pub fn with_root_tag(tag: &str) -> Self
Create a new arena with a named element as the root.
Sourcepub fn create_element(&mut self, tag: &str) -> NodeId
pub fn create_element(&mut self, tag: &str) -> NodeId
Create a new Element node. Orphan — not attached to any parent.
Use append_child to attach it.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn create_element_with_ext(&mut self, tag: &str, ext: Ext) -> NodeId
pub fn create_element_with_ext(&mut self, tag: &str, ext: Ext) -> NodeId
Create an Element with explicit extension data (useful when Ext
doesn’t implement Default or you want to pre-populate state).
Sourcepub fn create_text_node(&mut self, data: &str) -> NodeId
pub fn create_text_node(&mut self, data: &str) -> NodeId
Create a Text node (content of a text child).
Sourcepub fn create_comment(&mut self, data: &str) -> NodeId
pub fn create_comment(&mut self, data: &str) -> NodeId
Create a Comment node.
Sourcepub fn create_document_fragment(&mut self) -> NodeId
pub fn create_document_fragment(&mut self) -> NodeId
Create a DocumentFragment. Used as a detachable subtree container; inserting a fragment unwraps it.
Sourcepub fn contains(&self, id: NodeId) -> bool
pub fn contains(&self, id: NodeId) -> bool
Does the arena currently hold this id? false for a freed node
even after its slot has been recycled (the generation differs).
pub fn is_empty(&self) -> bool
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn form_owner(&self, id: NodeId) -> Option<NodeId>
pub fn form_owner(&self, id: NodeId) -> Option<NodeId>
The form owner of id (HTML §4.10.17.3):
- a listed element (
<button>,<fieldset>,<input>,<object>,<output>,<select>,<textarea>) that has aformattribute and is connected is owned by the first element in the document with that id if it is a<form>— and by nothing otherwise, even inside another form; - anything else is owned by its nearest ancestor
<form>.
A form is not its own owner. Dead / non-element ids have none.
Sourcepub fn form_listed_elements(&self, form: NodeId) -> Vec<NodeId>
pub fn form_listed_elements(&self, form: NodeId) -> Vec<NodeId>
The listed elements whose form owner is form, in tree order of
form’s whole tree — HTML form.elements (§4.10.3), which
includes controls outside the form that name it with form=.
Empty for a non-<form>. One pass over the tree.
Whether id is a submit button (HTML §4.10.6, §4.10.5.1.19–20):
a <button> whose type is missing, invalid or submit, or an
<input type="submit"> / <input type="image">. type keywords
match ASCII case-insensitively (§2.3.3).
Sourcepub fn submit_detail(
&self,
form: NodeId,
submitter: Option<NodeId>,
) -> SubmitDetail
pub fn submit_detail( &self, form: NodeId, submitter: Option<NodeId>, ) -> SubmitDetail
The submit event payload for form submitted by submitter
(HTML §4.10.21.3 with the §4.10.19.6 attributes): each of
action / method / enctype / target is the submitter’s
formaction / formmethod / formenctype / formtarget when the
submitter is a submit button carrying it, else the form’s
action / method / enctype / target. no_validate is the
submitter’s formnovalidate or the form’s novalidate. A
submitter that is not a submit button contributes no override
but is still reported.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn is_actually_disabled(&self, id: NodeId) -> bool
pub fn is_actually_disabled(&self, id: NodeId) -> bool
Whether id is actually disabled (HTML §4.16.3, the state
:disabled matches):
- a
<button>,<input>,<select>,<textarea>or<fieldset>with adisabledattribute (any value); - one of those that is a descendant of a
<fieldset disabled>and not a descendant of that fieldset’s first<legend>child (§4.10.18.5 form controls, §4.10.15 “disabled fieldset”); - an
<optgroup disabled>; - an
<option disabled>, or an<option>whose parent is an<optgroup disabled>(§4.10.10).
Every other element — including a <div disabled> — is never
disabled: the attribute means nothing there. A dead or
non-element id is not disabled.
Sourcepub fn is_enabled_control(&self, id: NodeId) -> bool
pub fn is_enabled_control(&self, id: NodeId) -> bool
Whether id matches :enabled (HTML §4.16.3): one of the
elements that can be disabled (<button>, <input>,
<select>, <textarea>, <fieldset>, <optgroup>, <option>)
that is not actually disabled.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn get_element_by_id(&self, id_value: &str) -> Option<NodeId>
pub fn get_element_by_id(&self, id_value: &str) -> Option<NodeId>
The element carrying this id attribute, or None.
document.getElementById semantics for the common case: a hash
lookup, O(1) when the id is unique. When several elements share
the id, the first one in document order among those connected
to the root wins (the web’s answer); that path walks the few
candidates’ ancestor chains.
Divergence (see DIVERGENCES.md): the lookup is arena-wide, so
a detached element is found when no connected element carries
the id. The web only searches the document tree.
Sourcepub fn get_elements_by_tag_name_all(&self, tag: &str) -> Vec<NodeId>
pub fn get_elements_by_tag_name_all(&self, tag: &str) -> Vec<NodeId>
All elements with the given tag name across the entire arena, in
arena order (creation order, except for recycled slots). The
wildcard "*" returns every element in the arena.
Sourcepub fn get_elements_by_class_name_all(&self, names: &str) -> Vec<NodeId>
pub fn get_elements_by_class_name_all(&self, names: &str) -> Vec<NodeId>
All elements whose classList contains every class in the whitespace-
separated names string, across the entire arena. Empty names
returns every element.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn input_type_state(&self, id: NodeId) -> Option<InputTypeState>
pub fn input_type_state(&self, id: NodeId) -> Option<InputTypeState>
The InputTypeState of id when it is an <input>, None
for any other node.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn insert_adjacent_element(
&mut self,
reference: NodeId,
position: AdjacentPosition,
new_element: NodeId,
) -> Result<NodeId>
pub fn insert_adjacent_element( &mut self, reference: NodeId, position: AdjacentPosition, new_element: NodeId, ) -> Result<NodeId>
Insert new_element adjacent to reference. Returns the inserted
element’s id on success. Errors if reference has no parent for
BeforeBegin/AfterEnd, or if the hierarchy would cycle.
Source§impl<Ext: Default> Dom<Ext>
impl<Ext: Default> Dom<Ext>
Sourcepub fn insert_adjacent_text(
&mut self,
reference: NodeId,
position: AdjacentPosition,
text: &str,
) -> Result<NodeId>
pub fn insert_adjacent_text( &mut self, reference: NodeId, position: AdjacentPosition, text: &str, ) -> Result<NodeId>
Insert a freshly-created Text node containing text adjacent to
reference. Returns the new Text node’s id.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn outer_markup(&self, id: NodeId) -> String
pub fn outer_markup(&self, id: NodeId) -> String
Serialize id and its subtree to HTML-ish markup.
- Elements:
<tag attr="v" class="c d">children</tag> - Void elements:
<hr/> - Text: entity-encoded content
- Comments:
<!-- data --> - Fragments: concatenated children (no wrapper tag)
Sourcepub fn inner_markup(&self, id: NodeId) -> String
pub fn inner_markup(&self, id: NodeId) -> String
Children serialized without id’s own wrapper. For an Element
this is the classic innerHTML; for a Fragment it’s identical to
outer_markup; for Text/Comment it returns an empty string.
Source§impl<Ext: 'static> Dom<Ext>
impl<Ext: 'static> Dom<Ext>
Sourcepub fn add_mutation_observer(
&mut self,
observer: Box<dyn MutationObserver<Ext>>,
) -> ObserverId
pub fn add_mutation_observer( &mut self, observer: Box<dyn MutationObserver<Ext>>, ) -> ObserverId
Register a mutation observer. Fires for every subsequent DOM
mutation on this Dom. Returns a handle for removal. Callable
from inside an observe() callback; the new observer first sees
the next record.
Sourcepub fn remove_mutation_observer(&mut self, id: ObserverId) -> bool
pub fn remove_mutation_observer(&mut self, id: ObserverId) -> bool
Remove a previously-registered observer. Returns true if the
observer existed and was removed. Callable from inside an
observe() callback, including by the observer being notified
(it is dropped once its call returns).
Sourcepub fn observer_count(&self) -> usize
pub fn observer_count(&self) -> usize
How many observers are currently registered.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn compare_document_position(
&self,
a: NodeId,
b: NodeId,
) -> DocumentPosition
pub fn compare_document_position( &self, a: NodeId, b: NodeId, ) -> DocumentPosition
a.compareDocumentPosition(b): a bitmask describing b relative
to a (DOM §4.4). Same orientation as the web: the bits say where
the argument sits.
a == b→ empty bits (0).bis a descendant ofa→CONTAINED_BY | FOLLOWING(20).bis an ancestor ofa→CONTAINS | PRECEDING(10).bcomes later in tree order →FOLLOWING.bcomes earlier in tree order →PRECEDING.- different trees →
DISCONNECTED | IMPLEMENTATION_SPECIFIC | PRECEDING.
FOLLOWING therefore always means “b is later in tree order”,
whether b is a sibling’s subtree or a’s own descendant.
Sourcepub fn is_equal_node(&self, a: NodeId, b: NodeId) -> bool
pub fn is_equal_node(&self, a: NodeId, b: NodeId) -> bool
Is a equal to b structurally (same tag, attrs, classes, text,
and recursively equal children)? Compares the tree shape — IDs +
parents are not considered. Iterative over a stack of node pairs,
so any depth is safe (P7G-CORE-SMALL-1).
Sourcepub fn compare_boundary_points(
&self,
a: Position,
b: Position,
) -> Option<Ordering>
pub fn compare_boundary_points( &self, a: Position, b: Position, ) -> Option<Ordering>
Order two boundary points per DOM §5.2 (“position of a boundary
point relative to another”). Less when a comes before b,
Equal when they are the same point, None when the nodes are in
different trees.
An element position (el, k) sits between el’s children k-1
and k, so it orders against a point inside child j by comparing
j with k — not by which node contains the other.
Sourcepub fn ancestor_path(&self, id: NodeId) -> Vec<NodeId>
pub fn ancestor_path(&self, id: NodeId) -> Vec<NodeId>
Path from root → this node as Vec<NodeId> (inclusive on both ends).
Empty if the node isn’t in the arena.
Sourcepub fn common_ancestor(&self, a: NodeId, b: NodeId) -> Option<NodeId>
pub fn common_ancestor(&self, a: NodeId, b: NodeId) -> Option<NodeId>
Lowest common ancestor of a and b — the deepest node
that contains both. Returns None if a and b live in
different arenas or if either node is invalid.
Used by the runtime for click synthesis: when mousedown
fires on one target and mouseup on another, the click
event dispatches on their common ancestor (HTML semantics).
When a == b, returns Some(a). When one is an ancestor
of the other, returns the ancestor.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn get_elements_by_tag_name(
&self,
root_id: NodeId,
tag: &str,
) -> Vec<NodeId>
pub fn get_elements_by_tag_name( &self, root_id: NodeId, tag: &str, ) -> Vec<NodeId>
Return descendants of root_id whose tag matches tag, in document
order. The special wildcard "*" matches every element.
root_id itself is NOT included in the result (matches browser
behaviour: element.getElementsByTagName("div") returns descendants
only). If you also want root_id to be considered, wrap it in a
parent or use matches yourself.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn is_placeholder_shown(&self, id: NodeId) -> bool
pub fn is_placeholder_shown(&self, id: NodeId) -> bool
Whether id matches :placeholder-shown: it has a non-empty
placeholder attribute and no text content, i.e. it is showing
its placeholder hint. Also what decides whether ::placeholder
rules style anything.
Sourcepub fn query_selector_in(
&self,
root_id: NodeId,
selector: &str,
) -> Result<Option<NodeId>, ParseError>
pub fn query_selector_in( &self, root_id: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError>
Find the first descendant of root_id matching selector, in
document order. Returns None if none matches. Errors if the
selector is malformed.
The DOM-shaped one-arg form is Dom::query_selector; this
_in form is the explicit-root variant (M4b step 18 rename).
Sourcepub fn query_selector_all_in(
&self,
root_id: NodeId,
selector: &str,
) -> Result<Vec<NodeId>, ParseError>
pub fn query_selector_all_in( &self, root_id: NodeId, selector: &str, ) -> Result<Vec<NodeId>, ParseError>
All descendants of root_id matching selector, in document
order. The DOM-shaped one-arg form is
Dom::query_selector_all; this _in form is the
explicit-root variant (M4b step 18 rename).
Sourcepub fn matches(&self, id: NodeId, selector: &str) -> Result<bool, ParseError>
pub fn matches(&self, id: NodeId, selector: &str) -> Result<bool, ParseError>
Does id match selector? Errors on malformed selector.
Sourcepub fn closest(
&self,
id: NodeId,
selector: &str,
) -> Result<Option<NodeId>, ParseError>
pub fn closest( &self, id: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError>
Walk from id (inclusive) up the tree and return the first ancestor
that matches selector. None if none does.
Sourcepub fn matches_list(&self, id: NodeId, list: &SelectorList) -> bool
pub fn matches_list(&self, id: NodeId, list: &SelectorList) -> bool
Does id match any selector in list?
Does id match any selector in the pre-parsed list? Public so
downstream crates (rdom-tui’s cascade) can drive rule matching
without re-parsing selector strings on every call.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn in_same_radio_group(&self, a: NodeId, b: NodeId) -> bool
pub fn in_same_radio_group(&self, a: NodeId, b: NodeId) -> bool
Whether a and b are in the same radio button group (HTML
§4.10.5.1.18). Every radio is in its own group, so a == b is
true for a radio; anything that is not an <input type="radio">
is in no group at all.
Sourcepub fn radio_group(&self, id: NodeId) -> Vec<NodeId>
pub fn radio_group(&self, id: NodeId) -> Vec<NodeId>
The radio button group of id in tree order, id included
(HTML §4.10.5.1.18). A radio without a non-empty name is alone
in its group; a non-radio has none (empty). One pass over id’s
tree; form owners are resolved only for same-named radios.
Source§impl<Ext> Dom<Ext>
impl<Ext> Dom<Ext>
Sourcepub fn text_content(&self, id: NodeId) -> String
pub fn text_content(&self, id: NodeId) -> String
Concatenate the string content of id and all its descendants.
- Text nodes: own
data. - Element / Fragment: recursive concat of descendants.
- Comment: empty string (matches spec — comments are not included in textContent).
Source§impl<Ext: Default> Dom<Ext>
impl<Ext: Default> Dom<Ext>
Sourcepub fn set_text_content(&mut self, id: NodeId, text: &str) -> Result<()>
pub fn set_text_content(&mut self, id: NodeId, text: &str) -> Result<()>
Replace all children of id with a single Text node containing text.
Matches Node.textContent setter semantics: any existing children
are detached + dropped; if text is empty the node has no
children; otherwise it has exactly one Text child.
Element-only operation fails with WrongNodeType on Text/Comment
(use set_node_value on those).
Source§impl<Ext: 'static> Dom<Ext>
impl<Ext: 'static> Dom<Ext>
Sourcepub fn append_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
pub fn append_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
Append child as the last child of parent. If child is a
Fragment, its children are appended and the fragment is emptied.
Returns Err(HierarchyRequest) if child is an ancestor of
parent (would create a cycle), Err(InvalidNode) for unknown ids.
Sourcepub fn prepend_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
pub fn prepend_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
Prepend child as the first child of parent.
Sourcepub fn insert_before(
&mut self,
parent: NodeId,
new_child: NodeId,
reference_child: Option<NodeId>,
) -> Result<()>
pub fn insert_before( &mut self, parent: NodeId, new_child: NodeId, reference_child: Option<NodeId>, ) -> Result<()>
Insert new_child before reference_child within parent.
If reference_child is None, appends at the end (matches spec
behavior).
Sourcepub fn remove_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
pub fn remove_child(&mut self, parent: NodeId, child: NodeId) -> Result<()>
Remove child from parent. Child is detached (parent + sibling
pointers cleared) but remains in the arena as an orphan — it
can be reattached elsewhere, or explicitly freed via
drop_subtree.
The arena has no GC: a detached node is never reclaimed on its
own. Code that removes nodes it will not reattach — especially
high-churn UIs (a virtualized list/table re-materializing rows on
every scroll) — must free them, or arena slots leak. Use
remove_child_dropping to remove
and free in one call.
Sourcepub fn replace_child(
&mut self,
parent: NodeId,
old_child: NodeId,
new_child: NodeId,
) -> Result<()>
pub fn replace_child( &mut self, parent: NodeId, old_child: NodeId, new_child: NodeId, ) -> Result<()>
Replace old_child with new_child under parent. old_child
is detached and becomes an orphan.
Sourcepub fn insert_adjacent(
&mut self,
reference: NodeId,
position: AdjacentPosition,
new_child: NodeId,
) -> Result<()>
pub fn insert_adjacent( &mut self, reference: NodeId, position: AdjacentPosition, new_child: NodeId, ) -> Result<()>
insertAdjacentElement(position, new_child). reference is the
node relative to which we insert.
Sourcepub fn clear_children(&mut self, parent: NodeId) -> Result<()>
pub fn clear_children(&mut self, parent: NodeId) -> Result<()>
Remove all children from parent. They become orphans in the
arena (not freed — see remove_child on
the no-GC contract). Fires a single ChildListChanged record with
every removed child. To remove and free in one call, use
clear_children_dropping.
Sourcepub fn drop_subtree(&mut self, id: NodeId) -> Result<()>
pub fn drop_subtree(&mut self, id: NodeId) -> Result<()>
Drop id and its entire subtree from the arena — frees every slot.
Useful when you know you’ll never reattach the nodes.
The root cannot be dropped (HierarchyRequest): Dom::root must
stay live for the lifetime of the arena. Use
clear_children_dropping to
empty it.
Sourcepub fn remove_child_dropping(
&mut self,
parent: NodeId,
child: NodeId,
) -> Result<()>
pub fn remove_child_dropping( &mut self, parent: NodeId, child: NodeId, ) -> Result<()>
Remove child from parent and free its subtree from the
arena (the non-leaking remove_child).
Use when you won’t reattach the removed node. Fires the same
single ChildListChanged record remove_child does (the
follow-up free runs on the already-detached orphan, so it adds no
extra record). Observers still see the removed node alive in their
synchronous callback — it’s freed only after dispatch returns.
Sourcepub fn clear_children_dropping(&mut self, parent: NodeId) -> Result<()>
pub fn clear_children_dropping(&mut self, parent: NodeId) -> Result<()>
Remove all children from parent and free their subtrees
from the arena (the non-leaking clear_children).
Fires the same single ChildListChanged record clear_children
does; the frees run on the already-detached orphans.