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.
The content is sniffed to decide between HTML and XML parsing. Callers which
know the document is XHTML from out-of-band information (a Content-Type
header or an .xht/.xhtml file extension) should use
from_xml instead, as the sniffing cannot detect all
XHTML documents.
Sourcepub fn from_xml(xml: &str, config: DocumentConfig) -> Self
pub fn from_xml(xml: &str, config: DocumentConfig) -> Self
Parse XML (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_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)
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_node_mut(&mut self, node_id: NodeId) -> Option<&mut Node>
pub fn get_focussed_node_id(&self) -> Option<NodeId>
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: 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 toggle_radio(&mut self, radio_set_name: String, target_radio_id: NodeId)
Sourcepub fn toggle_details_open(&mut self, details_id: NodeId)
pub fn toggle_details_open(&mut self, details_id: NodeId)
Toggle the open attribute of a <details> element, expanding or
collapsing it. This is the default action triggered when the element’s
first <summary> child is activated.
pub fn set_style_property(&mut self, node_id: NodeId, name: &str, value: &str)
pub fn remove_style_property(&mut self, node_id: NodeId, name: &str)
pub fn sub_document_node_ids(&self) -> Vec<NodeId>
pub fn set_sub_document( &mut self, node_id: NodeId, sub_document: Box<dyn Document>, )
pub fn remove_sub_document(&mut self, node_id: NodeId)
Sourcepub fn poll_subdocuments(&mut self, waker: Option<&Waker>) -> bool
pub fn poll_subdocuments(&mut self, waker: Option<&Waker>) -> bool
Poll all sub-documents (see Document::poll), allowing them to make progress
on any pending async operations (e.g. JavaScript timers). Hosts which poll a
wrapper around a BaseDocument should call this from their poll implementation.
Returns true if any sub-document reported changes.
pub fn root_node(&self) -> &Node
pub fn root_node_mut(&mut self) -> &mut Node
pub fn try_root_element(&self) -> Option<&Node>
pub fn root_element(&self) -> &Node
pub fn create_node(&mut self, node_data: NodeData) -> NodeId
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) -> NodeId
pub fn deep_clone_node(&mut self, node_id: NodeId) -> NodeId
pub fn print_tree(&self)
pub fn print_subtree(&self, node_id: NodeId)
pub fn reload_resource_by_href(&mut self, href_to_reload: &str)
pub fn process_style_element(&mut self, target_id: NodeId)
pub fn remove_user_agent_stylesheet(&mut self, sheet: &UserAgentStylesheet)
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
Sourcepub fn add_user_agent_stylesheet(&mut self, sheet: UserAgentStylesheet)
pub fn add_user_agent_stylesheet(&mut self, sheet: UserAgentStylesheet)
Append a user-agent stylesheet. Adding a sheet that is already present is a no-op.
pub fn make_stylesheet( &self, css: impl AsRef<str>, origin: Origin, ) -> DocumentStyleSheet
pub fn upsert_stylesheet_for_node(&mut self, node_id: NodeId)
pub fn add_stylesheet_for_node( &mut self, stylesheet: DocumentStyleSheet, node_id: NodeId, )
pub fn handle_messages(&mut self)
pub fn handle_message(&mut self, msg: DocumentEvent)
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)
pub fn load_resource(&mut self, res: ResourceLoadResponse)
Sourcepub fn snapshot_node(&mut self, node_id: NodeId)
pub fn snapshot_node(&mut self, node_id: NodeId)
Snapshot the node’s pre-mutation state (element state and attributes) ahead of an attribute mutation, so that the next style traversal can diff selector matches then-vs-now and invalidate the affected elements.
Sourcepub fn snapshot_node_state_only(&mut self, node_id: NodeId)
pub fn snapshot_node_state_only(&mut self, node_id: NodeId)
Snapshot only the node’s pre-change ElementState ahead of a state change
(hover/focus/active/etc). Cheaper than Self::snapshot_node as it does not
copy attributes or trigger attribute/class/id invalidation work.
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.
Sourcepub fn snapshot_node_and(
&mut self,
node_id: NodeId,
state: ElementState,
cb: impl FnOnce(&mut Node),
)
pub fn snapshot_node_and( &mut self, node_id: NodeId, state: ElementState, cb: impl FnOnce(&mut Node), )
Apply a state change (hover/focus/active/etc affecting the given ElementState
bits) to a node, taking a state-only snapshot beforehand if any style rule
depends on those bits.
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.
pub fn focus_next_node(&mut self) -> Option<NodeId>
Sourcepub fn focus_prev_node(&mut self) -> Option<NodeId>
pub fn focus_prev_node(&mut self) -> Option<NodeId>
Move focus to the previous focussable node in the document
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<NodeId>)
pub fn set_focus_to(&mut self, focus_node_id: NodeId) -> bool
pub fn active_node(&mut self) -> bool
pub fn unactive_node(&mut self) -> bool
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 set_hover_to(&mut self, x: f32, y: f32) -> bool
pub fn clear_hover(&mut self) -> bool
Sourcepub fn refresh_hover(&mut self) -> bool
pub fn refresh_hover(&mut self) -> bool
Re-resolve hover state against the current layout using the last known pointer position.
TODO: synthesizing pointerenter/pointerleave DOM events for hover changes caused by layout shifts.
pub fn get_hover_node_id(&self) -> Option<NodeId>
pub fn get_mousedown_node_id(&self) -> Option<NodeId>
pub fn set_viewport(&mut self, viewport: Viewport)
Sourcepub fn media_type(&self) -> &MediaType
pub fn media_type(&self) -> &MediaType
Returns the current CSS media type used to evaluate @media rules.
Sourcepub fn set_media_type(&mut self, media_type: MediaType)
pub fn set_media_type(&mut self, media_type: MediaType)
Sets the CSS media type used to evaluate @media rules (e.g. screen or print)
and queues a stylist device rebuild so updated rules apply on the next restyle.
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
Sourcepub fn incremental_layout(&self) -> bool
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.
Sourcepub fn set_incremental_layout(&mut self, enabled: bool)
pub fn set_incremental_layout(&mut self, enabled: bool)
Enables or disables incremental layout for this document.
Disabling it does not switch to a separate code path: all nodes are
simply treated as damaged on every resolve (see Self::incremental_layout).
pub fn devtools(&self) -> &DevtoolSettings
pub fn devtools_mut(&mut self) -> &mut DevtoolSettings
pub fn subdoc(&self, node_id: NodeId) -> Option<&(dyn Document + 'static)>
pub fn subdoc_mut( &mut self, node_id: NodeId, ) -> Option<&mut (dyn Document + 'static)>
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 viewport_scroll(&self) -> Point<f64>
pub fn set_viewport_scroll(&mut self, scroll: 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 offset_rect(&self, node_id: NodeId) -> Option<BoundingRect>
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.
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<impl Iterator<Item = BoundingRect>>
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).
Sourcepub fn find_element_by_tag_name(
&self,
tag: &Atom<LocalNameStaticSet>,
) -> Option<&Node>
pub fn find_element_by_tag_name( &self, tag: &Atom<LocalNameStaticSet>, ) -> 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
pub fn with_text_input( &mut self, node_id: NodeId, cb: impl FnOnce(PlainEditorDriver<'_, TextBrush>), )
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 set_text_selection(
&mut self,
anchor_node: NodeId,
anchor_offset: usize,
focus_node: NodeId,
focus_offset: usize,
)
pub fn set_text_selection( &mut self, anchor_node: NodeId, anchor_offset: usize, focus_node: NodeId, 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: NodeId,
focus_offset: usize,
)
pub fn update_selection_focus( &mut self, focus_node: NodeId, 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<(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.
Sourcepub fn stylesheet_owner_nodes(&self) -> impl Iterator<Item = NodeId>
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).
Sourcepub fn node_has_stylesheet(&self, node_id: NodeId) -> bool
pub fn node_has_stylesheet(&self, node_id: NodeId) -> bool
Whether node_id currently owns a stylesheet
Sourcepub fn stylesheet_generation(&self) -> u64
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.
Sourcepub fn stylesheet_disabled(&self, node_id: NodeId) -> bool
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.
Sourcepub fn set_stylesheet_disabled(
&mut self,
node_id: NodeId,
disabled: bool,
) -> bool
pub fn set_stylesheet_disabled( &mut self, node_id: NodeId, disabled: bool, ) -> bool
Set the disabled flag of the stylesheet owned by node_id. A disabled
stylesheet stays associated with its owner node but its rules no longer
apply to the document.
Returns false if the node owns no stylesheet.
Sourcepub fn stylesheet_rule_count(
&self,
node_id: NodeId,
path: &[usize],
) -> Option<usize>
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)
Sourcepub fn stylesheet_rule_info(
&self,
node_id: NodeId,
path: &[usize],
) -> Option<CssRuleInfo>
pub fn stylesheet_rule_info( &self, node_id: NodeId, path: &[usize], ) -> Option<CssRuleInfo>
The CSSOM-visible attributes of the rule at path
Sourcepub fn stylesheet_insert_rule(
&mut self,
node_id: NodeId,
path: &[usize],
rule: &str,
index: usize,
) -> Result<usize, CssomError>
pub fn stylesheet_insert_rule( &mut self, node_id: NodeId, path: &[usize], rule: &str, index: usize, ) -> Result<usize, CssomError>
Insert a rule parsed from rule at index in the rule list at path
(CSSStyleSheet.insertRule / CSSGroupingRule.insertRule /
CSSKeyframesRule.appendRule). Returns the index of the inserted rule.
Sourcepub fn stylesheet_delete_rule(
&mut self,
node_id: NodeId,
path: &[usize],
index: usize,
) -> Result<(), CssomError>
pub fn stylesheet_delete_rule( &mut self, node_id: NodeId, path: &[usize], index: usize, ) -> Result<(), CssomError>
Remove the rule at index from the rule list at path
(CSSStyleSheet.deleteRule / CSSGroupingRule.deleteRule /
CSSKeyframesRule.deleteRule).
Sourcepub fn stylesheet_rule_style_css_text(
&self,
node_id: NodeId,
path: &[usize],
) -> Option<String>
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)
Sourcepub fn stylesheet_rule_style_property_names(
&self,
node_id: NodeId,
path: &[usize],
) -> Option<Vec<String>>
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())
Sourcepub fn stylesheet_rule_style_get_property(
&self,
node_id: NodeId,
path: &[usize],
property: &str,
) -> Option<(String, bool)>
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.
Sourcepub fn stylesheet_rule_style_set_property(
&mut self,
node_id: NodeId,
path: &[usize],
property: &str,
value: &str,
important: bool,
) -> Result<(), CssomError>
pub fn stylesheet_rule_style_set_property( &mut self, node_id: NodeId, path: &[usize], property: &str, value: &str, important: bool, ) -> Result<(), CssomError>
Set property to value in the declarations of the rule at path
(CSSRule.style.setProperty()). Invalid declarations are ignored, per
CSSOM. An empty value removes the property.
Sourcepub fn stylesheet_rule_style_remove_property(
&mut self,
node_id: NodeId,
path: &[usize],
property: &str,
) -> Result<String, CssomError>
pub fn stylesheet_rule_style_remove_property( &mut self, node_id: NodeId, path: &[usize], property: &str, ) -> Result<String, CssomError>
Remove property from the declarations of the rule at path
(CSSRule.style.removeProperty()). Returns the removed property’s
previous serialized value.
Sourcepub fn stylesheet_rule_set_selector_text(
&mut self,
node_id: NodeId,
path: &[usize],
selectors: &str,
) -> Result<(), CssomError>
pub fn stylesheet_rule_set_selector_text( &mut self, node_id: NodeId, path: &[usize], selectors: &str, ) -> Result<(), CssomError>
Replace the selectors of the style rule at path with those parsed
from selectors (CSSStyleRule.selectorText setter). Per CSSOM, an
invalid selector list leaves the rule unchanged (without throwing).
Sourcepub fn stylesheet_rule_style_set_css_text(
&mut self,
node_id: NodeId,
path: &[usize],
css: &str,
) -> Result<(), CssomError>
pub fn stylesheet_rule_style_set_css_text( &mut self, node_id: NodeId, path: &[usize], css: &str, ) -> Result<(), CssomError>
Replace the declarations of the rule at path with those parsed from
css (CSSRule.style.cssText setter).
pub fn print_taffy_tree(&self)
pub fn debug_log_node(&self, node_id: NodeId)
Sourcepub fn reset_form_owner(&mut self, node_id: NodeId)
pub fn reset_form_owner(&mut self, node_id: NodeId)
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: 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(
&self,
selector: &str,
) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
pub fn query_selector( &self, selector: &str, ) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
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(
&self,
scope: NodeId,
selector: &str,
) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
pub fn query_selector_in( &self, scope: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
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(
&self,
selector: &str,
) -> Result<SmallVec<[NodeId; 32]>, ParseError<StyleParseErrorKind>>
pub fn query_selector_all( &self, selector: &str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError<StyleParseErrorKind>>
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(
&self,
scope: NodeId,
selector: &str,
) -> Result<SmallVec<[NodeId; 32]>, ParseError<StyleParseErrorKind>>
pub fn query_selector_all_in( &self, scope: NodeId, selector: &str, ) -> Result<SmallVec<[NodeId; 32]>, ParseError<StyleParseErrorKind>>
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(
&self,
node_id: NodeId,
selector: &str,
) -> Result<bool, ParseError<StyleParseErrorKind>>
pub fn matches_selector( &self, node_id: NodeId, selector: &str, ) -> Result<bool, ParseError<StyleParseErrorKind>>
Test whether the node identified by node_id matches the selector
specified as a string.
Non-element nodes never match.
Sourcepub fn closest(
&self,
node_id: NodeId,
selector: &str,
) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
pub fn closest( &self, node_id: NodeId, selector: &str, ) -> Result<Option<NodeId>, ParseError<StyleParseErrorKind>>
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( &self, input: &str, ) -> Result<SelectorList<SelectorImpl>, ParseError<StyleParseErrorKind>>
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
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
Sourcepub fn css_declaration_is_valid(&self, property: &str, value: &str) -> bool
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.
Sourcepub fn style_attr_serialize(&self, style_attr: &str) -> String
pub fn style_attr_serialize(&self, style_attr: &str) -> String
The canonical CSSOM serialization of a style attribute string
(CSSStyleDeclaration.cssText getter).
Sourcepub fn style_attr_get_property(
&self,
style_attr: &str,
property: &str,
) -> String
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.
Sourcepub fn style_attr_set_property(
&self,
style_attr: &str,
property: &str,
value: &str,
important: bool,
) -> Option<String>
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.
Sourcepub fn style_attr_remove_property(
&self,
style_attr: &str,
property: &str,
) -> Option<(String, String)>
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.
Sourcepub fn css_supports_condition(&self, condition: &str) -> bool
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.
Sourcepub fn register_custom_property(
&mut self,
name: &str,
syntax: &str,
inherits: bool,
initial_value: Option<&str>,
) -> RegisterCustomPropertyResult
pub fn register_custom_property( &mut self, name: &str, syntax: &str, inherits: bool, initial_value: Option<&str>, ) -> RegisterCustomPropertyResult
Register a custom property via script (CSS.registerProperty()).
On success all styles are invalidated so that declarations of the
property are re-parsed against the new registration.
Sourcepub fn resolved_style_value(
&self,
node_id: NodeId,
property_name: &str,
) -> String
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.
pub fn scroll_node_by<F>( &mut self, node_id: NodeId, x: f64, y: f64, dispatch_event: F, )
Sourcepub fn scroll_node_by_has_changed<F>(
&mut self,
node_id: NodeId,
x: f64,
y: f64,
dispatch_event: F,
) -> bool
pub fn scroll_node_by_has_changed<F>( &mut self, node_id: NodeId, 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
Sourcepub fn scroll_to(
&mut self,
node_id: NodeId,
x: f64,
y: f64,
behavior: ScrollBehavior,
)
pub fn scroll_to( &mut self, node_id: NodeId, x: f64, y: f64, behavior: ScrollBehavior, )
Scroll an element to the given absolute scroll offset in CSS pixels.
Unlike a user-initiated scroll, a programmatic scroll targets exactly one scroller: scroll the element cannot consume is discarded rather than transferred to an ancestor.
Sourcepub fn scroll_by(
&mut self,
node_id: NodeId,
x: f64,
y: f64,
behavior: ScrollBehavior,
)
pub fn scroll_by( &mut self, node_id: NodeId, x: f64, y: f64, behavior: ScrollBehavior, )
Scroll an element by the given relative offset in CSS pixels.
Sourcepub fn scroll_into_view(
&mut self,
node_id: NodeId,
behavior: ScrollBehavior,
vertical: ScrollLogicalPosition,
horizontal: ScrollLogicalPosition,
)
pub fn scroll_into_view( &mut self, node_id: NodeId, behavior: ScrollBehavior, vertical: ScrollLogicalPosition, horizontal: ScrollLogicalPosition, )
Scroll the viewport so that the given element has the requested alignment in each axis.
Sourcepub fn scroll_to_fragment(&mut self, fragment: &str) -> bool
pub fn scroll_to_fragment(&mut self, fragment: &str) -> bool
Scroll to the element targeted by the given URL fragment (the #... part of a URL).
An empty fragment (or a top fragment that matches no element) scrolls to the top
of the document, matching browser behaviour. Returns true if a scroll target was
found.
Sourcepub fn scroll_to_fragment_smooth(&mut self, fragment: &str) -> bool
pub fn scroll_to_fragment_smooth(&mut self, fragment: &str) -> bool
Like BaseDocument::scroll_to_fragment, but animates the viewport towards the
target instead of jumping instantly. Returns true if a scroll target was found.
pub fn resolve_scroll_animation(&mut self)
pub fn resolve_stylist(&mut self, now: f64)
Sourcepub fn resolve_undisplayed_style(
&self,
node_id: NodeId,
) -> Option<Arc<ComputedValues>>
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.
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 iter_children_mut( &mut self, node_id: NodeId, cb: impl FnMut(NodeId, &mut BaseDocument), )
pub fn iter_subtree_mut( &mut self, node_id: NodeId, cb: impl FnMut(NodeId, &mut BaseDocument), )
pub fn iter_children_and_pseudos_mut( &mut self, node_id: NodeId, cb: impl FnMut(NodeId, &mut BaseDocument), )
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.
Sourcepub fn node_element_ancestors(&self, node_id: NodeId) -> Vec<NodeId>
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.
pub fn maybe_node_element_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.
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