pub struct HtmlDocument { /* private fields */ }Implementations§
Source§impl HtmlDocument
impl HtmlDocument
Sourcepub fn from_html(html: &str, config: DocumentConfig) -> Self
pub fn from_html(html: &str, config: DocumentConfig) -> Self
Parse HTML (or XHTML) into an HtmlDocument
Sourcepub fn into_inner(self) -> BaseDocument
pub fn into_inner(self) -> BaseDocument
Convert the HtmlDocument into it’s inner BaseDocument
Methods from Deref<Target = BaseDocument>§
Sourcepub fn set_net_provider(&mut self, net_provider: Arc<dyn NetProvider>)
pub fn set_net_provider(&mut self, net_provider: Arc<dyn NetProvider>)
Set the Document’s networking provider
Set the Document’s navigation provider
Sourcepub fn set_shell_provider(&mut self, shell_provider: Arc<dyn ShellProvider>)
pub fn set_shell_provider(&mut self, shell_provider: Arc<dyn ShellProvider>)
Set the Document’s shell provider
Sourcepub fn set_html_parser_provider(
&mut self,
html_parser_provider: Arc<dyn HtmlParserProvider>,
)
pub fn set_html_parser_provider( &mut self, html_parser_provider: Arc<dyn HtmlParserProvider>, )
Set the Document’s html parser provider
Sourcepub fn set_script_engine(&mut self, engine: Box<dyn ScriptEngine>)
pub fn set_script_engine(&mut self, engine: Box<dyn ScriptEngine>)
Set the script engine for this document
Sourcepub fn set_event_sink(&mut self, sink: Arc<dyn EventSink>)
pub fn set_event_sink(&mut self, sink: Arc<dyn EventSink>)
Set the event sink for this document
Sourcepub fn set_events_enabled(&mut self, enabled: bool)
pub fn set_events_enabled(&mut self, enabled: bool)
Enable or disable event forwarding to the event sink This is used for lifecycle management - events should only be forwarded when the capsule is “Running”
Sourcepub fn get_event_listeners(&self, node_id: usize, event_name: &str) -> &[u64]
pub fn get_event_listeners(&self, node_id: usize, event_name: &str) -> &[u64]
Query registered event listeners for a given node ID and event name. Returns an empty Vec if no listeners are registered.
Sourcepub fn execute_script(
&mut self,
code: &str,
language: ScriptLanguage,
context: &ExecutionContext,
) -> Result<ScriptValue, ScriptError>
pub fn execute_script( &mut self, code: &str, language: ScriptLanguage, context: &ExecutionContext, ) -> Result<ScriptValue, ScriptError>
Execute script code
Sourcepub fn poll_script_engine(&mut self) -> Result<bool, ScriptError>
pub fn poll_script_engine(&mut self) -> Result<bool, ScriptError>
Poll script engine for async work
Sourcepub fn set_script_error_handler(
&mut self,
callback: Option<Box<dyn Fn(&ScriptError) + Send + Sync>>,
)
pub fn set_script_error_handler( &mut self, callback: Option<Box<dyn Fn(&ScriptError) + Send + Sync>>, )
Set error handler for script engine
Sourcepub fn handle_ui_event_with_script(&mut self, event: &DomEvent) -> EventHandled
pub fn handle_ui_event_with_script(&mut self, event: &DomEvent) -> EventHandled
Handle UI event with script engine support
Sourcepub fn set_base_url(&mut self, url: &str)
pub fn set_base_url(&mut self, url: &str)
Set base url for resolving linked resources (stylesheets, images, fonts, etc)
pub fn guard(&self) -> &SharedRwLock
pub fn tree(&self) -> &Slab<Node>
pub fn id(&self) -> usize
pub fn get_node(&self, node_id: usize) -> Option<&Node>
pub fn get_node_mut(&mut self, node_id: usize) -> Option<&mut Node>
pub fn get_focussed_node_id(&self) -> Option<usize>
pub fn mutate<'doc>(&'doc mut self) -> DocumentMutator<'doc>
pub fn handle_dom_event<F>(&mut self, event: &mut DomEvent, dispatch_event: F)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Sourcepub fn label_bound_input_element(&self, label_node_id: usize) -> Option<&Node>
pub fn label_bound_input_element(&self, label_node_id: usize) -> Option<&Node>
Find the label’s bound input elements: the element id referenced by the “for” attribute of a given label element or the first input element which is nested in the label Note that although there should only be one bound element, we return all possibilities instead of just the first in order to allow the caller to decide which one is correct
pub fn toggle_radio(&mut self, radio_set_name: String, target_radio_id: usize)
pub fn set_style_property(&mut self, node_id: usize, name: &str, value: &str)
pub fn remove_style_property(&mut self, node_id: usize, name: &str)
pub fn set_sub_document( &mut self, node_id: usize, sub_document: Box<dyn Document>, )
pub fn remove_sub_document(&mut self, node_id: usize)
pub fn root_node(&self) -> &Node
pub fn root_node_mut(&mut self) -> &mut Node
pub fn root_element(&self) -> Option<&Node>
Sourcepub fn try_root_element(&self) -> Option<&Node>
pub fn try_root_element(&self) -> Option<&Node>
Deprecated alias for BaseDocument::root_element.
Both return Option<&Node> after D-2c-followup widened the signature
to eliminate the chained-unwrap panic when the document has no
element child (e.g. before any HTML is parsed into it). Retained for
callers that want explicit Option-style naming.
pub fn create_node(&mut self, node_data: NodeData) -> usize
Sourcepub fn has_changes(&self) -> bool
pub fn has_changes(&self) -> bool
Whether the document has been mutated
pub fn create_text_node(&mut self, text: &str) -> usize
Sourcepub fn deep_clone_node(&mut self, node_id: usize) -> usize
pub fn deep_clone_node(&mut self, node_id: usize) -> usize
Hardened for D-2c: atomic recursive clone. If node_id is stale OR any
descendant goes stale mid-recursion, the clone rolls back: the parent
slot and every already-cloned child slot are dropped from the slab via
drop_node_ignoring_parent, returning cleanly without panicking.
On any failure path, returns usize::MAX as a documented sentinel —
unreachable in practice (slabs don’t reach that size), so it eliminates
the collision with the document root slot id (0) that a naïve 0
sentinel would have. Callers — e.g. html5ever’s TreeSink::clone_subtree
trait method — can safely pass the result on without disambiguating,
trusting that a real clone produces a slot id strictly in [1, MAX-1].
pub fn print_tree(&self)
pub fn print_subtree(&self, node_id: usize)
pub fn reload_resource_by_href(&mut self, href_to_reload: &str)
pub fn process_style_element(&mut self, target_id: usize)
pub fn remove_user_agent_stylesheet(&mut self, contents: &str)
pub fn add_user_agent_stylesheet(&mut self, css: &str)
pub fn make_stylesheet( &self, css: impl AsRef<str>, origin: Origin, ) -> DocumentStyleSheet
pub fn upsert_stylesheet_for_node(&mut self, node_id: usize)
pub fn add_stylesheet_for_node( &mut self, stylesheet: DocumentStyleSheet, node_id: usize, )
pub fn handle_messages(&mut self)
pub fn handle_message(&mut self, msg: DocumentEvent)
pub fn load_resource(&mut self, res: ResourceLoadResponse)
pub fn snapshot_node(&mut self, node_id: usize)
pub fn snapshot_node_and(&mut self, node_id: usize, cb: impl FnOnce(&mut Node))
pub fn hit(&self, x: f32, y: f32) -> Option<HitResult>
pub fn focus_next_node(&mut self) -> Option<usize>
Sourcepub fn focus_prev_node(&mut self) -> Option<usize>
pub fn focus_prev_node(&mut self) -> Option<usize>
Move focus to the previous focusable node in document order (reverse Tab).
Sourcepub fn clear_focus(&mut self)
pub fn clear_focus(&mut self)
Clear the focussed node
pub fn set_mousedown_node_id(&mut self, node_id: Option<usize>)
pub fn set_focus_to(&mut self, focus_node_id: usize) -> bool
pub fn active_node(&mut self) -> bool
pub fn unactive_node(&mut self) -> bool
pub fn set_hover_to(&mut self, x: f32, y: f32) -> bool
pub fn clear_hover(&mut self) -> bool
pub fn get_hover_node_id(&self) -> Option<usize>
pub fn set_viewport(&mut self, viewport: Viewport)
pub fn viewport(&self) -> &Viewport
pub fn viewport_mut(&mut self) -> ViewportMut<'_>
pub fn zoom_by(&mut self, increment: f32)
pub fn zoom_to(&mut self, zoom: f32)
pub fn get_viewport(&self) -> Viewport
pub fn devtools(&self) -> &DevtoolSettings
pub fn devtools_mut(&mut self) -> &mut DevtoolSettings
pub fn is_animating(&self) -> bool
Sourcepub fn set_stylist_device(&mut self, device: Device)
pub fn set_stylist_device(&mut self, device: Device)
Update the device and reset the stylist to process the new size
pub fn stylist_device(&mut self) -> &Device
pub fn get_cursor(&self) -> Option<CursorIcon>
pub fn scroll_node_by<F>( &mut self, node_id: usize, x: f64, y: f64, dispatch_event: F, )
Sourcepub fn scroll_node_by_has_changed<F>(
&mut self,
node_id: usize,
x: f64,
y: f64,
dispatch_event: F,
) -> bool
pub fn scroll_node_by_has_changed<F>( &mut self, node_id: usize, x: f64, y: f64, dispatch_event: F, ) -> bool
Scroll a node by given x and y Will bubble scrolling up to parent node once it can no longer scroll further If we’re already at the root node, bubbles scrolling up to the viewport
pub fn scroll_viewport_by(&mut self, x: f64, y: f64)
Sourcepub fn scroll_viewport_by_has_changed(&mut self, x: f64, y: f64) -> bool
pub fn scroll_viewport_by_has_changed(&mut self, x: f64, y: f64) -> bool
Scroll the viewport by the given values
pub fn scroll_by( &mut self, anchor_node_id: Option<usize>, scroll_x: f64, scroll_y: f64, dispatch_event: &mut dyn FnMut(DomEvent), ) -> bool
pub fn viewport_scroll(&self) -> Point<f64>
pub fn set_viewport_scroll(&mut self, scroll: Point<f64>)
Sourcepub fn get_client_bounding_rect(&self, node_id: usize) -> Option<BoundingRect>
pub fn get_client_bounding_rect(&self, node_id: usize) -> Option<BoundingRect>
Computes the size and position of the Node relative to the viewport
pub fn find_title_node(&self) -> Option<&Node>
pub fn with_text_input( &mut self, node_id: usize, cb: impl FnOnce(PlainEditorDriver<'_, TextBrush>), )
Sourcepub fn find_text_position(&self, x: f32, y: f32) -> Option<(usize, usize)>
pub fn find_text_position(&self, x: f32, y: f32) -> Option<(usize, usize)>
Find the text position (inline_root_id, byte_offset) at a given point. Uses hit() for proper coordinate transformation, then finds the inline root and byte offset.
Sourcepub fn set_text_selection(
&mut self,
anchor_node: usize,
anchor_offset: usize,
focus_node: usize,
focus_offset: usize,
)
pub fn set_text_selection( &mut self, anchor_node: usize, anchor_offset: usize, focus_node: usize, focus_offset: usize, )
Set the text selection range (creates a new selection from anchor to focus)
Sourcepub fn clear_text_selection(&mut self)
pub fn clear_text_selection(&mut self)
Clear the text selection
Sourcepub fn update_selection_focus(&mut self, focus_node: usize, focus_offset: usize)
pub fn update_selection_focus(&mut self, focus_node: usize, focus_offset: usize)
Update the selection focus point (used during mouse drag to extend selection).
Sourcepub fn extend_text_selection_to_point(&mut self, x: f32, y: f32) -> bool
pub fn extend_text_selection_to_point(&mut self, x: f32, y: f32) -> bool
Extend text selection to the given point. Returns true if selection was updated. This is a convenience method that combines find_text_position and update_selection_focus.
Sourcepub fn has_text_selection(&self) -> bool
pub fn has_text_selection(&self) -> bool
Check if there is an active (non-empty) text selection
Sourcepub fn get_selected_text(&self) -> Option<String>
pub fn get_selected_text(&self) -> Option<String>
Get the selected text content, supporting selection across multiple inline roots.
Sourcepub fn get_text_selection_ranges(&self) -> Vec<(usize, usize, usize)>
pub fn get_text_selection_ranges(&self) -> Vec<(usize, usize, usize)>
Get all selection ranges as Vec<(node_id, start_offset, end_offset)>. Returns empty vec if no selection.
pub fn print_taffy_tree(&self)
pub fn debug_log_node(&self, node_id: usize)
Sourcepub fn reset_form_owner(&mut self, node_id: usize)
pub fn reset_form_owner(&mut self, node_id: usize)
Resets the form owner for a given node by either using an explicit form attribute or finding the nearest ancestor form element
§Arguments
node_id- The ID of the node whose form owner needs to be reset
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#reset-the-form-owner
Sourcepub fn submit_form(&self, node_id: usize, submitter_id: usize)
pub fn submit_form(&self, node_id: usize, submitter_id: usize)
Submits a form with the given form node ID and submitter node ID
§Arguments
node_id- The ID of the form node to submitsubmitter_id- The ID of the node that triggered the submission
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm
pub fn flush_styles_to_layout(&mut self, node_id: usize)
Sourcepub fn get_element_by_id(&self, id: &str) -> Option<usize>
pub fn get_element_by_id(&self, id: &str) -> Option<usize>
Find the node with the specified id attribute (if one exists)
Sourcepub fn query_selector<'input>(
&self,
selector: &'input str,
) -> Result<Option<usize>, ParseError<'input, StyleParseErrorKind<'input>>>
pub fn query_selector<'input>( &self, selector: &'input str, ) -> Result<Option<usize>, ParseError<'input, StyleParseErrorKind<'input>>>
Find the first node that matches the selector specified as a string Returns:
- Err(_) if parsing the selector fails
- Ok(None) if nothing matches
- Ok(Some(node_id)) with the first node ID that matches if one is found
Sourcepub fn query_selector_raw(
&self,
selector_list: &SelectorList<SelectorImpl>,
) -> Option<usize>
pub fn query_selector_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> Option<usize>
Find the first node that matches the selector(s) specified in selector_list
Sourcepub fn query_selector_all<'input>(
&self,
selector: &'input str,
) -> Result<SmallVec<[usize; 32]>, ParseError<'input, StyleParseErrorKind<'input>>>
pub fn query_selector_all<'input>( &self, selector: &'input str, ) -> Result<SmallVec<[usize; 32]>, ParseError<'input, StyleParseErrorKind<'input>>>
Find all nodes that match the selector specified as a string Returns:
Err(_)if parsing the selector failsOk(SmallVec<usize>)with all matching nodes otherwise
Sourcepub fn query_selector_all_raw(
&self,
selector_list: &SelectorList<SelectorImpl>,
) -> SmallVec<[usize; 32]>
pub fn query_selector_all_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> SmallVec<[usize; 32]>
Find all nodes that match the selector(s) specified in selector_list
Sourcepub fn query_selector_all_from<'input>(
&self,
root_id: usize,
selector: &'input str,
) -> Result<SmallVec<[usize; 32]>, ParseError<'input, StyleParseErrorKind<'input>>>
pub fn query_selector_all_from<'input>( &self, root_id: usize, selector: &'input str, ) -> Result<SmallVec<[usize; 32]>, ParseError<'input, StyleParseErrorKind<'input>>>
Element-scoped query: all nodes matching selector within the subtree
rooted at root_id, EXCLUDING the root itself — DOM
element.querySelectorAll semantics. Unlike the document-global
query_selector_all, this traverses from the
given node, so it also queries detached subtrees (e.g. a cloneNode
result not yet inserted) that the global query cannot reach.
Sourcepub fn query_selector_all_from_raw(
&self,
root_id: usize,
selector_list: &SelectorList<SelectorImpl>,
) -> SmallVec<[usize; 32]>
pub fn query_selector_all_from_raw( &self, root_id: usize, selector_list: &SelectorList<SelectorImpl>, ) -> SmallVec<[usize; 32]>
Find all nodes matching selector_list in the subtree rooted at
root_id, excluding the root. Empty if root_id is absent.
pub fn try_parse_selector_list<'input>( &self, input: &'input str, ) -> Result<SelectorList<SelectorImpl>, ParseError<'input, StyleParseErrorKind<'input>>>
Sourcepub fn resolve(&mut self, current_time_for_animations: f64)
pub fn resolve(&mut self, current_time_for_animations: f64)
Restyle the tree and then relayout it
pub fn resolve_scroll_animation(&mut self)
Sourcepub fn resolve_layout_children(&mut self)
pub fn resolve_layout_children(&mut self)
Ensure that the layout_children field is populated for all nodes
pub fn resolve_deferred_tasks(&mut self)
Sourcepub fn resolve_layout(&mut self)
pub fn resolve_layout(&mut self)
Walk the nodes now that they’re properly styled and transfer their styles to the taffy style system
TODO: update taffy to use an associated type instead of slab key TODO: update taffy to support traited styles so we don’t even need to rely on taffy for storage
pub fn resolve_stylist(&mut self, now: f64)
Sourcepub fn node_chain(&self, node_id: usize) -> Vec<usize>
pub fn node_chain(&self, node_id: usize) -> Vec<usize>
Collect the nodes into a chain by traversing upwards
pub fn visit<F>(&self, visit: F)
Sourcepub fn non_anon_ancestor_if_anon(&self, node_id: usize) -> usize
pub fn non_anon_ancestor_if_anon(&self, node_id: usize) -> usize
If the node is non-anonymous then returns the node’s id Else find’s the first non-anonymous ancester of the node
pub fn iter_children_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )
pub fn iter_subtree_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )
pub fn iter_children_and_pseudos_mut( &mut self, node_id: usize, cb: impl FnMut(usize, &mut BaseDocument), )
pub fn prev_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<usize>
pub fn next_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<usize>
pub fn node_layout_ancestors(&self, node_id: usize) -> Vec<usize>
pub fn maybe_node_layout_ancestors(&self, node_id: Option<usize>) -> Vec<usize>
Sourcepub fn compare_document_order(&self, node_a: usize, node_b: usize) -> Ordering
pub fn compare_document_order(&self, node_a: usize, node_b: usize) -> Ordering
Compare the document order of two nodes. Returns Ordering::Less if node_a comes before node_b in document order. Returns Ordering::Greater if node_a comes after node_b. Returns Ordering::Equal if they are the same node.
Trait Implementations§
Source§impl Deref for HtmlDocument
impl Deref for HtmlDocument
Source§type Target = BaseDocument
type Target = BaseDocument
Source§fn deref(&self) -> &BaseDocument
fn deref(&self) -> &BaseDocument
Source§impl DerefMut for HtmlDocument
impl DerefMut for HtmlDocument
Source§impl Document for HtmlDocument
impl Document for HtmlDocument
Source§impl From<HtmlDocument> for BaseDocument
impl From<HtmlDocument> for BaseDocument
Source§fn from(doc: HtmlDocument) -> BaseDocument
fn from(doc: HtmlDocument) -> BaseDocument
Auto Trait Implementations§
impl !Freeze for HtmlDocument
impl !RefUnwindSafe for HtmlDocument
impl !Send for HtmlDocument
impl !Sync for HtmlDocument
impl !UnwindSafe for HtmlDocument
impl Unpin for HtmlDocument
impl UnsafeUnpin for HtmlDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more