pub enum DocGuard<'a> {
Ref(&'a BaseDocument),
RefCell(Ref<'a, BaseDocument>),
RwLock(RwLockReadGuard<'a, BaseDocument>),
Mutex(MutexGuard<'a, BaseDocument>),
}Variants§
Ref(&'a BaseDocument)
RefCell(Ref<'a, BaseDocument>)
RwLock(RwLockReadGuard<'a, BaseDocument>)
Mutex(MutexGuard<'a, BaseDocument>)
Methods from Deref<Target = BaseDocument>§
Sourcepub fn base_url(&self) -> &Url
pub fn base_url(&self) -> &Url
The base url used for resolving linked resources (stylesheets, images, fonts, etc)
pub fn guard(&self) -> &SharedRwLock
pub fn tree(&self) -> &NodeTree
pub fn id(&self) -> usize
pub fn favicon_url(&self) -> Option<String>
pub fn get_node(&self, node_id: NodeId) -> Option<&Node>
pub fn get_focussed_node_id(&self) -> Option<NodeId>
Sourcepub fn label_bound_input_element(&self, label_node_id: NodeId) -> Option<&Node>
pub fn label_bound_input_element(&self, label_node_id: NodeId) -> 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 sub_document_node_ids(&self) -> Vec<NodeId>
pub fn custom_widget_node_ids(&self) -> Vec<NodeId>
pub fn root_node(&self) -> &Node
pub fn try_root_element(&self) -> Option<&Node>
pub fn root_element(&self) -> &Node
Sourcepub fn has_changes(&self) -> bool
pub fn has_changes(&self) -> bool
Whether the document has been mutated
pub fn print_tree(&self)
pub fn print_subtree(&self, node_id: NodeId)
Iterate over the author stylesheets (from <style> and <link> nodes)
currently associated with this document
Sourcepub fn useragent_stylesheets(&self) -> impl Iterator<Item = &DocumentStyleSheet>
pub fn useragent_stylesheets(&self) -> impl Iterator<Item = &DocumentStyleSheet>
Iterate over the user-agent stylesheets currently associated with this document
pub fn make_stylesheet( &self, css: impl AsRef<str>, origin: Origin, ) -> DocumentStyleSheet
Sourcepub fn has_pending_critical_resources(&self) -> bool
pub fn has_pending_critical_resources(&self) -> bool
Whether the Document has pending requests for “critical” resources (that should block rendering)
Sourcepub fn style_depends_on_state(&self, state: ElementState) -> bool
pub fn style_depends_on_state(&self, state: ElementState) -> bool
Returns whether any style rule depends on any of the given ElementState bits.
If not, changing those bits cannot affect styling and snapshotting can be skipped.
pub fn hit(&self, x: f32, y: f32) -> Option<HitResult>
Sourcepub fn element_from_point(&self, x: f32, y: f32) -> Option<NodeId>
pub fn element_from_point(&self, x: f32, y: f32) -> Option<NodeId>
The topmost element at viewport coordinates (x, y), or None if the point
is outside the viewport. Anonymous boxes and text nodes are resolved to
their nearest element; a point over the background hits the root element.
This implements the hit-testing semantics of document.elementFromPoint().
Hit testing consults layout, so resolve should be called
before this method to ensure layout is up to date.
Sourcepub fn elements_from_point(&self, x: f32, y: f32) -> Vec<NodeId>
pub fn elements_from_point(&self, x: f32, y: f32) -> Vec<NodeId>
All elements at viewport coordinates (x, y), from topmost to bottommost,
as for document.elementsFromPoint().
The spec’s paint-order list is approximated with the hit element followed
by its ancestor elements (which is correct for non-overlapping content).
As with element_from_point, layout should be
resolved before calling this method.
Sourcepub fn nearest_non_anonymous_ancestor(&self, node_id: NodeId) -> Option<NodeId>
pub fn nearest_non_anonymous_ancestor(&self, node_id: NodeId) -> Option<NodeId>
Walk up the tree to the nearest DOM node whose id is stable across box-tree reconstruction, so canonicalized interaction state never goes stale.
Layout-generated nodes (anonymous blocks and ::before/::after
pseudo-elements, both stored as anonymous blocks) get new ids on every
reconstruction, so we skip any anonymous node and a non-anonymous node
whose parent is anonymous (the pseudo’s text content). The first
non-anonymous node with a non-anonymous parent is a real DOM node; the
root element’s Document parent guarantees termination.
Returns None if node_id (or an ancestor) no longer exists.
Sourcepub fn hovered_scrollbar(&self) -> Option<ScrollbarRef>
pub fn hovered_scrollbar(&self) -> Option<ScrollbarRef>
The scrollbar thumb currently under the pointer, if any.
Sourcepub fn scrollbar_drag_target(&self) -> Option<ScrollbarRef>
pub fn scrollbar_drag_target(&self) -> Option<ScrollbarRef>
The scrollbar thumb currently being dragged, if any.
Sourcepub fn scrollbar_opacity(&self, node_id: NodeId) -> f32
pub fn scrollbar_opacity(&self, node_id: NodeId) -> f32
The current opacity of node_id’s overlay scrollbars. They show at
full opacity on scroll and fade out after a delay (Chromium’s overlay
timings); the pointer resting on a thumb, or dragging it, holds them
visible.
pub fn get_hover_node_id(&self) -> Option<NodeId>
pub fn get_mousedown_node_id(&self) -> Option<NodeId>
Sourcepub fn media_type(&self) -> &MediaType
pub fn media_type(&self) -> &MediaType
Returns the current CSS media type used to evaluate @media rules.
pub fn viewport(&self) -> &Viewport
pub fn get_viewport(&self) -> Viewport
Sourcepub fn incremental_layout(&self) -> bool
pub fn incremental_layout(&self) -> bool
Returns whether incremental layout is currently enabled for this document.
pub fn devtools(&self) -> &DevtoolSettings
pub fn subdoc(&self, node_id: NodeId) -> Option<&dyn Document>
pub fn is_animating(&self) -> bool
pub fn get_cursor(&self) -> Option<CursorIcon>
pub fn viewport_scroll(&self) -> Point<f64>
Sourcepub fn get_fragment_target(&self, fragment: &str) -> Option<NodeId>
pub fn get_fragment_target(&self, fragment: &str) -> Option<NodeId>
Find the node targeted by a URL fragment (the #... part of a URL).
Per the HTML spec, this is the element whose id matches the fragment, falling
back to the first <a> element whose name attribute matches.
Sourcepub fn get_client_bounding_rect(&self, node_id: NodeId) -> Option<BoundingRect>
pub fn get_client_bounding_rect(&self, node_id: NodeId) -> Option<BoundingRect>
Computes the size and position of the Node relative to the viewport
Sourcepub fn node_client_rects(&self, node_id: NodeId) -> Vec<BoundingRect>
pub fn node_client_rects(&self, node_id: NodeId) -> Vec<BoundingRect>
Computes the sizes and positions of the Node’s box fragments relative to the
viewport (CSSOM getClientRects() semantics). Nodes with their own layout box
return a single rect. Non-atomic inline elements (which are laid out as style
spans within an inline root’s text layout) return one rect per line box.
Sourcepub fn inline_fragment_rects(
&self,
node_id: NodeId,
) -> Option<Vec<BoundingRect>>
pub fn inline_fragment_rects( &self, node_id: NodeId, ) -> Option<Vec<BoundingRect>>
Computes per-line-box fragment rects for a non-atomic inline element by walking
the containing inline root’s text layout. Returns None for nodes that have
their own layout box (which should use get_client_bounding_rect instead).
Sourcepub fn find_element_by_tag_name(&self, tag: &LocalName) -> Option<&Node>
pub fn find_element_by_tag_name(&self, tag: &LocalName) -> Option<&Node>
The first element in tree order with the given tag name. The root element and
its children are checked first as a fast path before a full tree search, making
this suitable for the documentElement/head/body document accessors.
Sourcepub fn find_body_node(&self) -> Option<&Node>
pub fn find_body_node(&self) -> Option<&Node>
The document’s body element, as for document.body
Sourcepub fn find_head_node(&self) -> Option<&Node>
pub fn find_head_node(&self) -> Option<&Node>
The document’s head element, as for document.head
Sourcepub fn find_title_node(&self) -> Option<&Node>
pub fn find_title_node(&self) -> Option<&Node>
The document’s title element
Sourcepub fn find_text_position(&self, x: f32, y: f32) -> Option<(NodeId, usize)>
pub fn find_text_position(&self, x: f32, y: f32) -> Option<(NodeId, 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 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<(NodeId, usize, usize)>
pub fn get_text_selection_ranges(&self) -> Vec<(NodeId, 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: NodeId)
Sourcepub fn submit_form(&self, node_id: NodeId, submitter_id: NodeId)
pub fn submit_form(&self, node_id: NodeId, submitter_id: NodeId)
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
Sourcepub fn get_element_by_id(&self, id: &str) -> Option<NodeId>
pub fn get_element_by_id(&self, id: &str) -> Option<NodeId>
Find the node with the specified id attribute (if one exists). If multiple nodes have the same id, the first in tree order is returned.
Sourcepub fn query_selector<'input>(
&self,
selector: &'input str,
) -> Result<Option<NodeId>, ParseError<'input>>
pub fn query_selector<'input>( &self, selector: &'input str, ) -> Result<Option<NodeId>, ParseError<'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_in<'input>(
&self,
scope: NodeId,
selector: &'input str,
) -> Result<Option<NodeId>, ParseError<'input>>
pub fn query_selector_in<'input>( &self, scope: NodeId, selector: &'input str, ) -> Result<Option<NodeId>, ParseError<'input>>
Find the first descendant of scope that matches the selector specified
as a string.
The scope node itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Returns:
Err(_)if parsing the selector failsOk(None)if nothing matchesOk(Some(node_id))with the first matching descendant ID otherwise
Sourcepub fn query_selector_raw(
&self,
selector_list: &SelectorList<SelectorImpl>,
) -> Option<NodeId>
pub fn query_selector_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> Option<NodeId>
Find the first descendant of the document root that matches the
selector(s) specified in selector_list.
The document root itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Sourcepub fn query_selector_in_raw(
&self,
scope: NodeId,
selector_list: &SelectorList<SelectorImpl>,
) -> Option<NodeId>
pub fn query_selector_in_raw( &self, scope: NodeId, selector_list: &SelectorList<SelectorImpl>, ) -> Option<NodeId>
Find the first descendant of scope that matches the selector(s)
specified in selector_list.
The scope node itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Sourcepub fn query_selector_all<'input>(
&self,
selector: &'input str,
) -> Result<SmallVec<[NodeId; 32]>, ParseError<'input>>
pub fn query_selector_all<'input>( &self, selector: &'input str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError<'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_in<'input>(
&self,
scope: NodeId,
selector: &'input str,
) -> Result<SmallVec<[NodeId; 32]>, ParseError<'input>>
pub fn query_selector_all_in<'input>( &self, scope: NodeId, selector: &'input str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError<'input>>
Find all descendants of scope that match the selector specified as a
string, in tree order.
The scope node itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Returns:
Err(_)if parsing the selector failsOk(_)with all matching descendant IDs otherwise
Sourcepub fn query_selector_all_raw(
&self,
selector_list: &SelectorList<SelectorImpl>,
) -> SmallVec<[NodeId; 32]>
pub fn query_selector_all_raw( &self, selector_list: &SelectorList<SelectorImpl>, ) -> SmallVec<[NodeId; 32]>
Find all descendants of the document root that match the selector(s)
specified in selector_list, in tree order.
The document root itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Sourcepub fn query_selector_all_in_raw(
&self,
scope: NodeId,
selector_list: &SelectorList<SelectorImpl>,
) -> SmallVec<[NodeId; 32]>
pub fn query_selector_all_in_raw( &self, scope: NodeId, selector_list: &SelectorList<SelectorImpl>, ) -> SmallVec<[NodeId; 32]>
Find all descendants of scope that match the selector(s) specified in
selector_list, in tree order.
The scope node itself is never matched. Selector parts may match nodes outside the scope while evaluating relationships between descendants.
Sourcepub fn matches_selector<'input>(
&self,
node_id: NodeId,
selector: &'input str,
) -> Result<bool, ParseError<'input>>
pub fn matches_selector<'input>( &self, node_id: NodeId, selector: &'input str, ) -> Result<bool, ParseError<'input>>
Test whether the node identified by node_id matches the selector
specified as a string.
Non-element nodes never match.
Sourcepub fn closest<'input>(
&self,
node_id: NodeId,
selector: &'input str,
) -> Result<Option<NodeId>, ParseError<'input>>
pub fn closest<'input>( &self, node_id: NodeId, selector: &'input str, ) -> Result<Option<NodeId>, ParseError<'input>>
Find the closest matching element at or above the node identified by
node_id.
Non-element nodes never match and return None.
pub fn try_parse_selector_list<'input>( &self, input: &'input str, ) -> Result<SelectorList<SelectorImpl>, ParseError<'input>>
Sourcepub fn node_chain(&self, node_id: NodeId) -> Vec<NodeId>
pub fn node_chain(&self, node_id: NodeId) -> Vec<NodeId>
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: NodeId) -> NodeId
pub fn non_anon_ancestor_if_anon(&self, node_id: NodeId) -> NodeId
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 next_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<NodeId>
Sourcepub fn prev_node(
&self,
start: &Node,
filter: impl FnMut(&Node) -> bool,
) -> Option<NodeId>
pub fn prev_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<NodeId>
Mirror of Self::next_node: walks the tree in reverse document
order, wrapping around to the end of the document.
pub fn node_layout_ancestors(&self, node_id: NodeId) -> Vec<NodeId>
pub fn maybe_node_layout_ancestors( &self, node_id: Option<NodeId>, ) -> Vec<NodeId>
Sourcepub fn compare_document_order(&self, node_a: NodeId, node_b: NodeId) -> Ordering
pub fn compare_document_order(&self, node_a: NodeId, node_b: NodeId) -> 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.
Sourcepub fn collect_inline_roots_in_range(
&self,
start_node: NodeId,
end_node: NodeId,
) -> Vec<NodeId>
pub fn collect_inline_roots_in_range( &self, start_node: NodeId, end_node: NodeId, ) -> Vec<NodeId>
Collect all inline root nodes between start_node and end_node in document order. Both start and end are assumed to be inline roots. Returns the nodes in document order (from first to last).
pub fn build_accessibility_tree(&self) -> TreeUpdate
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for DocGuard<'a>
impl<'a> !Send for DocGuard<'a>
impl<'a> !Sync for DocGuard<'a>
impl<'a> !UnwindSafe for DocGuard<'a>
impl<'a> Freeze for DocGuard<'a>
impl<'a> Unpin for DocGuard<'a>
impl<'a> UnsafeUnpin for DocGuard<'a>
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