Skip to main content

DocGuard

Enum DocGuard 

Source
pub enum DocGuard<'a> {
    Ref(&'a BaseDocument),
    RefCell(Ref<'a, BaseDocument>),
    RwLock(RwLockReadGuard<'a, BaseDocument>),
    Mutex(MutexGuard<'a, BaseDocument>),
}

Variants§

Methods from Deref<Target = BaseDocument>§

Source

pub fn base_url(&self) -> &Url

The base url used for resolving linked resources (stylesheets, images, fonts, etc)

Source

pub fn guard(&self) -> &SharedRwLock

Source

pub fn tree(&self) -> &NodeTree

Source

pub fn id(&self) -> usize

Source

pub fn favicon_url(&self) -> Option<String>

Source

pub fn get_node(&self, node_id: NodeId) -> Option<&Node>

Source

pub fn get_focussed_node_id(&self) -> Option<NodeId>

Source

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

Source

pub fn sub_document_node_ids(&self) -> Vec<NodeId>

Source

pub fn custom_widget_node_ids(&self) -> Vec<NodeId>

Source

pub fn root_node(&self) -> &Node

Source

pub fn try_root_element(&self) -> Option<&Node>

Source

pub fn root_element(&self) -> &Node

Source

pub fn has_changes(&self) -> bool

Whether the document has been mutated

Source

pub fn print_tree(&self)

Source

pub fn print_subtree(&self, node_id: NodeId)

Source

pub fn url(&self) -> &Url

The document’s base URL

Source

pub fn author_stylesheets(&self) -> impl Iterator<Item = &DocumentStyleSheet>

Iterate over the author stylesheets (from <style> and <link> nodes) currently associated with this document

Source

pub fn useragent_stylesheets(&self) -> impl Iterator<Item = &DocumentStyleSheet>

Iterate over the user-agent stylesheets currently associated with this document

Source

pub fn make_stylesheet( &self, css: impl AsRef<str>, origin: Origin, ) -> DocumentStyleSheet

Source

pub fn has_pending_critical_resources(&self) -> bool

Whether the Document has pending requests for “critical” resources (that should block rendering)

Source

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.

Source

pub fn hit(&self, x: f32, y: f32) -> Option<HitResult>

Source

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.

Source

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.

Source

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.

Source

pub fn hovered_scrollbar(&self) -> Option<ScrollbarRef>

The scrollbar thumb currently under the pointer, if any.

Source

pub fn scrollbar_drag_target(&self) -> Option<ScrollbarRef>

The scrollbar thumb currently being dragged, if any.

Source

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.

Source

pub fn get_hover_node_id(&self) -> Option<NodeId>

Source

pub fn get_mousedown_node_id(&self) -> Option<NodeId>

Source

pub fn media_type(&self) -> &MediaType

Returns the current CSS media type used to evaluate @media rules.

Source

pub fn viewport(&self) -> &Viewport

Source

pub fn get_viewport(&self) -> Viewport

Source

pub fn incremental_layout(&self) -> bool

Returns whether incremental layout is currently enabled for this document.

Both modes run the same style → damage → box construction → layout pipeline. In incremental mode only nodes carrying RestyleDamage (from mutations or restyles) are reconstructed and have their layout caches cleared; in non-incremental mode every node is marked damaged at the start of each resolve, so everything is rebuilt each frame.

Source

pub fn devtools(&self) -> &DevtoolSettings

Source

pub fn subdoc(&self, node_id: NodeId) -> Option<&dyn Document>

Source

pub fn is_animating(&self) -> bool

Source

pub fn get_cursor(&self) -> Option<CursorIcon>

Source

pub fn viewport_scroll(&self) -> Point<f64>

Source

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.

Source

pub fn get_client_bounding_rect(&self, node_id: NodeId) -> Option<BoundingRect>

Computes the size and position of the Node relative to the viewport

Source

pub fn offset_rect(&self, node_id: NodeId) -> Option<BoundingRect>

CSSOM View’s offsetLeft/offsetTop/offsetWidth/offsetHeight as a single rect: the node’s border box, positioned relative to the padding edge of its offsetParent (or to the initial containing block when the offsetParent is a non-positioned body, or there is none).

Nodes with their own layout box use that box directly. Non-atomic inline elements have no layout box: they use the bounding box of their per-line-box fragments, and their offsetParent is resolved from the containing inline root.

Source

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.

Source

pub fn inline_fragment_rects( &self, node_id: NodeId, ) -> Option<impl Iterator<Item = 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).

Source

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.

Source

pub fn find_body_node(&self) -> Option<&Node>

The document’s body element, as for document.body

Source

pub fn find_head_node(&self) -> Option<&Node>

The document’s head element, as for document.head

Source

pub fn find_title_node(&self) -> Option<&Node>

The document’s title element

Source

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.

Source

pub fn has_text_selection(&self) -> bool

Check if there is an active (non-empty) text selection

Source

pub fn get_selected_text(&self) -> Option<String>

Get the selected text content, supporting selection across multiple inline roots.

Source

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.

Source

pub fn stylesheet_owner_nodes(&self) -> impl Iterator<Item = NodeId> + '_

The owner nodes (<style> / <link> elements) of the document’s author stylesheets (document.styleSheets).

Ordered by node id, which matches document order for stylesheets created while parsing (and is the order the stylist uses too, see add_stylesheet_for_node).

Source

pub fn node_has_stylesheet(&self, node_id: NodeId) -> bool

Whether node_id currently owns a stylesheet

Source

pub fn stylesheet_generation(&self) -> u64

A counter which changes whenever the set of stylesheets (or the stylesheet object owned by some node) changes. CSSOM wrappers use it to detect that rule data cached on the script side is stale.

Source

pub fn stylesheet_disabled(&self, node_id: NodeId) -> bool

Whether the stylesheet owned by node_id has been disabled through the CSSOM (CSSStyleSheet.disabled / HTMLStyleElement.disabled / HTMLLinkElement.disabled). false if the node owns no stylesheet.

Source

pub fn stylesheet_rule_count( &self, node_id: NodeId, path: &[usize], ) -> Option<usize>

The number of rules in the rule list at path (CSSRuleList.length)

Source

pub fn stylesheet_rule_info( &self, node_id: NodeId, path: &[usize], ) -> Option<CssRuleInfo>

The CSSOM-visible attributes of the rule at path

Source

pub fn stylesheet_rule_style_css_text( &self, node_id: NodeId, path: &[usize], ) -> Option<String>

The serialized declarations of the rule at path (CSSRule.style.cssText)

Source

pub fn stylesheet_rule_style_property_names( &self, node_id: NodeId, path: &[usize], ) -> Option<Vec<String>>

The names of the declarations of the rule at path, in order (CSSRule.style.length / .item())

Source

pub fn stylesheet_rule_style_get_property( &self, node_id: NodeId, path: &[usize], property: &str, ) -> Option<(String, bool)>

The serialized value of property in the declarations of the rule at path, and whether it is !important (CSSRule.style.getPropertyValue() / .getPropertyPriority()). Returns an empty string for unset or unknown properties.

Source

pub fn print_takia_tree(&self)

Source

pub fn debug_log_node(&self, node_id: NodeId)

Source

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 submit
  • submitter_id - The ID of the node that triggered the submission

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-algorithm

Source

pub fn profile(&self) -> Option<Profile>

Source

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.

Source

pub fn query_selector( &self, selector: &str, ) -> Result<Option<NodeId>, ParseError>

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
Source

pub fn query_selector_in( &self, scope: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError>

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 fails
  • Ok(None) if nothing matches
  • Ok(Some(node_id)) with the first matching descendant ID otherwise
Source

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.

Source

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.

Source

pub fn query_selector_all( &self, selector: &str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError>

Find all nodes that match the selector specified as a string Returns:

  • Err(_) if parsing the selector fails
  • Ok(SmallVec<usize>) with all matching nodes otherwise
Source

pub fn query_selector_all_in( &self, scope: NodeId, selector: &str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError>

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 fails
  • Ok(_) with all matching descendant IDs otherwise
Source

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.

Source

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.

Source

pub fn matches_selector( &self, node_id: NodeId, selector: &str, ) -> Result<bool, ParseError>

Test whether the node identified by node_id matches the selector specified as a string.

Non-element nodes never match.

Source

pub fn closest( &self, node_id: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError>

Find the closest matching element at or above the node identified by node_id.

Non-element nodes never match and return None.

Source

pub fn try_parse_selector_list( &self, input: &str, ) -> Result<SelectorList<SelectorImpl>, ParseError>

Source

pub fn radio_group(&self, id: NodeId) -> Vec<NodeId>

Members in current physical tree order, including disabled members. An empty/missing name is a singleton; tree and form owners isolate groups. Only the live host tree is traversed, never an application’s data source.

Source

pub fn image_request(&self, node: NodeId) -> Option<ImageRequestId>

Current element-consumer identity; changes even for an explicit same-URL reload.

Source

pub fn resource_stats(&self) -> ResourceStats

Source

pub fn css_declaration_is_valid(&self, property: &str, value: &str) -> bool

Check whether value is a valid value for the CSS property property. Used by CSSOM APIs (element.style.setProperty and friends), which must ignore invalid declarations.

Source

pub fn style_attr_serialize(&self, style_attr: &str) -> String

The canonical CSSOM serialization of a style attribute string (CSSStyleDeclaration.cssText getter).

Source

pub fn style_attr_get_property( &self, style_attr: &str, property: &str, ) -> String

The canonical serialization of property’s value in a style attribute string (CSSStyleDeclaration.getPropertyValue()). Handles shorthands. Returns an empty string if the property is not set or not recognised.

Source

pub fn style_attr_set_property( &self, style_attr: &str, property: &str, value: &str, important: bool, ) -> Option<String>

Set property to value in a style attribute string (CSSStyleDeclaration.setProperty()), expanding shorthands.

Returns the new (canonically serialized) style attribute, or None if the declaration was invalid (in which case the style is unchanged, per CSSOM). An empty value removes the property.

Source

pub fn style_attr_remove_property( &self, style_attr: &str, property: &str, ) -> Option<(String, String)>

Remove property from a style attribute string (CSSStyleDeclaration.removeProperty()), removing all longhands if it is a shorthand.

Returns the new (canonically serialized) style attribute and the removed property’s previous serialized value.

Source

pub fn css_supports_condition(&self, condition: &str) -> bool

Evaluate a @supports condition (e.g. (display: grid), selector(:hover)) or a bare declaration (e.g. display: grid), as used by the CSSOM CSS.supports(conditionText) API. Returns false for unparseable conditions.

Source

pub fn resolved_style_value( &self, node_id: NodeId, property_name: &str, ) -> String

Compute the resolved value of a CSS property for the given node, as exposed by getComputedStyle(). Returns an empty string for unknown properties and for nodes without styles.

Layout-dependent properties (width/height, margins, padding, insets, transform-origin, grid-template-rows/columns) resolve to used values, so resolve should be called before this method to ensure layout is up to date.

Source

pub fn resolve_undisplayed_style( &self, node_id: NodeId, ) -> Option<Arc<ComputedValues>>

Compute the style of an element which the regular style traversal skipped because it lives inside a display: none subtree.

The style traversal culls display: none subtrees, so such elements never have styles stored on them, but getComputedStyle() must still return their computed values. This resolves the style on demand (styling any unstyled ancestors along the way) without storing it on the node. Returns None for non-elements and elements outside the document.

Source

pub fn top_layers(&self) -> &[TopLayer]

Source

pub fn top_layer_is_rendered(&self, node_id: NodeId) -> bool

A top layer does not escape a display:none ancestor. Its lease remains current while hidden, but neither its box nor its backdrop participates.

Source

pub fn node_chain(&self, node_id: NodeId) -> Vec<NodeId>

Collect the nodes into a chain by traversing upwards

Source

pub fn visit<F>(&self, visit: F)
where F: FnMut(NodeId, &Node),

Source

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

Source

pub fn next_node( &self, start: &Node, filter: impl FnMut(&Node) -> bool, ) -> Option<NodeId>

Source

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.

Source

pub fn node_element_ancestors(&self, node_id: NodeId) -> Vec<NodeId>

node_id and its ancestor elements in the DOM, root first. These are the elements that match :hover/:active when node_id does.

Source

pub fn maybe_node_element_ancestors( &self, node_id: Option<NodeId>, ) -> Vec<NodeId>

Source

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.

Source

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).

Source

pub fn build_accessibility_tree(&self) -> TreeUpdate

Trait Implementations§

Source§

impl Deref for DocGuard<'_>

Source§

type Target = BaseDocument

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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> 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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.