Struct script::dom::document::Document

source ·
pub struct Document {
Show 94 fields node: Node, document_or_shadow_root: DocumentOrShadowRoot, window: Dom<Window>, implementation: MutNullableDom<DOMImplementation>, content_type: Mime, last_modified: Option<String>, encoding: Cell<&'static Encoding>, has_browsing_context: bool, is_html_document: bool, activity: Cell<DocumentActivity>, url: DomRefCell<ServoUrl>, quirks_mode: Cell<QuirksMode>, id_map: DomRefCell<HashMap<Atom, Vec<Dom<Element>>>>, name_map: DomRefCell<HashMap<Atom, Vec<Dom<Element>>>>, tag_map: DomRefCell<HashMap<LocalName, Dom<HTMLCollection>>>, tagns_map: DomRefCell<HashMap<QualName, Dom<HTMLCollection>>>, classes_map: DomRefCell<HashMap<Vec<Atom>, Dom<HTMLCollection>>>, images: MutNullableDom<HTMLCollection>, embeds: MutNullableDom<HTMLCollection>, links: MutNullableDom<HTMLCollection>, forms: MutNullableDom<HTMLCollection>, scripts: MutNullableDom<HTMLCollection>, anchors: MutNullableDom<HTMLCollection>, applets: MutNullableDom<HTMLCollection>, style_shared_lock: StyleSharedRwLock, stylesheets: DomRefCell<DocumentStylesheetSet<StyleSheetInDocument>>, stylesheet_list: MutNullableDom<StyleSheetList>, ready_state: Cell<DocumentReadyState>, domcontentloaded_dispatched: Cell<bool>, focus_transaction: DomRefCell<FocusTransaction>, focused: MutNullableDom<Element>, current_script: MutNullableDom<HTMLScriptElement>, pending_parsing_blocking_script: DomRefCell<Option<PendingScript>>, script_blocking_stylesheets_count: Cell<u32>, deferred_scripts: PendingInOrderScriptVec, asap_in_order_scripts_list: PendingInOrderScriptVec, asap_scripts_set: DomRefCell<Vec<Dom<HTMLScriptElement>>>, scripting_enabled: bool, animation_frame_ident: Cell<u32>, animation_frame_list: DomRefCell<Vec<(u32, Option<AnimationFrameCallback>)>>, running_animation_callbacks: Cell<bool>, loader: DomRefCell<DocumentLoader>, current_parser: MutNullableDom<ServoParser>, reflow_timeout: Cell<Option<u64>>, base_element: MutNullableDom<HTMLBaseElement>, appropriate_template_contents_owner_document: MutNullableDom<Document>, pending_restyles: DomRefCell<HashMap<Dom<Element>, PendingRestyle>>, needs_paint: Cell<bool>, active_touch_points: DomRefCell<Vec<Dom<Touch>>>, dom_loading: Cell<u64>, dom_interactive: Cell<u64>, dom_content_loaded_event_start: Cell<u64>, dom_content_loaded_event_end: Cell<u64>, dom_complete: Cell<u64>, top_level_dom_complete: Cell<u64>, load_event_start: Cell<u64>, load_event_end: Cell<u64>, unload_event_start: Cell<u64>, unload_event_end: Cell<u64>, https_state: Cell<HttpsState>, origin: MutableOrigin, referrer_policy: Cell<Option<ReferrerPolicy>>, referrer: Option<String>, target_element: MutNullableDom<Element>, last_click_info: DomRefCell<Option<(Instant, Point2D<f32>)>>, ignore_destructive_writes_counter: Cell<u32>, ignore_opens_during_unload_counter: Cell<u32>, spurious_animation_frames: Cell<u8>, dom_count: Cell<u32>, fullscreen_element: MutNullableDom<Element>, form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>, interactive_time: DomRefCell<InteractiveMetrics>, tti_window: DomRefCell<InteractiveWindow>, canceller: FetchCanceller, throw_on_dynamic_markup_insertion_counter: Cell<u64>, page_showing: Cell<bool>, salvageable: Cell<bool>, active_parser_was_aborted: Cell<bool>, fired_unload: Cell<bool>, responsive_images: DomRefCell<Vec<Dom<HTMLImageElement>>>, redirect_count: Cell<u16>, script_and_layout_blockers: Cell<u32>, delayed_tasks: DomRefCell<Vec<Box<dyn TaskBox>>>, completely_loaded: Cell<bool>, shadow_roots: DomRefCell<HashSet<Dom<ShadowRoot>>>, shadow_roots_styles_changed: Cell<bool>, media_controls: DomRefCell<HashMap<String, Dom<ShadowRoot>>>, dirty_webgl_contexts: DomRefCell<HashMap<WebGLContextId, Dom<WebGLRenderingContext>>>, dirty_webgpu_contexts: DomRefCell<HashMap<WebGPUContextId, Dom<GPUCanvasContext>>>, csp_list: DomRefCell<Option<CspList>>, selection: MutNullableDom<Selection>, animation_timeline: DomRefCell<AnimationTimeline>, animations: DomRefCell<Animations>, dirty_root: MutNullableDom<Element>,
Expand description


node: Nodedocument_or_shadow_root: DocumentOrShadowRootwindow: Dom<Window>implementation: MutNullableDom<DOMImplementation>content_type: Mimelast_modified: Option<String>encoding: Cell<&'static Encoding>has_browsing_context: boolis_html_document: boolactivity: Cell<DocumentActivity>url: DomRefCell<ServoUrl>quirks_mode: Cell<QuirksMode>id_map: DomRefCell<HashMap<Atom, Vec<Dom<Element>>>>

Caches for the getElement methods

name_map: DomRefCell<HashMap<Atom, Vec<Dom<Element>>>>tag_map: DomRefCell<HashMap<LocalName, Dom<HTMLCollection>>>tagns_map: DomRefCell<HashMap<QualName, Dom<HTMLCollection>>>classes_map: DomRefCell<HashMap<Vec<Atom>, Dom<HTMLCollection>>>images: MutNullableDom<HTMLCollection>embeds: MutNullableDom<HTMLCollection>links: MutNullableDom<HTMLCollection>forms: MutNullableDom<HTMLCollection>scripts: MutNullableDom<HTMLCollection>anchors: MutNullableDom<HTMLCollection>applets: MutNullableDom<HTMLCollection>style_shared_lock: StyleSharedRwLock

Lock use for style attributes and author-origin stylesheet objects in this document. Can be acquired once for accessing many objects.

stylesheets: DomRefCell<DocumentStylesheetSet<StyleSheetInDocument>>

List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed.

stylesheet_list: MutNullableDom<StyleSheetList>ready_state: Cell<DocumentReadyState>domcontentloaded_dispatched: Cell<bool>

Whether the DOMContentLoaded event has already been dispatched.

focus_transaction: DomRefCell<FocusTransaction>

The state of this document’s focus transaction.

focused: MutNullableDom<Element>

The element that currently has the document focus context.

current_script: MutNullableDom<HTMLScriptElement>

The script element that is currently executing.

pending_parsing_blocking_script: DomRefCell<Option<PendingScript>>script_blocking_stylesheets_count: Cell<u32>

Number of stylesheets that block executing the next parser-inserted script

deferred_scripts: PendingInOrderScriptVec

asap_in_order_scripts_list: PendingInOrderScriptVecasap_scripts_set: DomRefCell<Vec<Dom<HTMLScriptElement>>>scripting_enabled: bool True if scripting is enabled for all scripts in this document

animation_frame_ident: Cell<u32>animation_frame_list: DomRefCell<Vec<(u32, Option<AnimationFrameCallback>)>>running_animation_callbacks: Cell<bool>

Whether we’re in the process of running animation callbacks.

Tracking this is not necessary for correctness. Instead, it is an optimization to avoid sending needless ChangeRunningAnimationsState messages to the compositor.

loader: DomRefCell<DocumentLoader>

Tracks all outstanding loads related to this document.

current_parser: MutNullableDom<ServoParser>

The current active HTML parser, to allow resuming after interruptions.

reflow_timeout: Cell<Option<u64>>

When we should kick off a reflow. This happens during parsing.

base_element: MutNullableDom<HTMLBaseElement>

The cached first base element with an href attribute.

appropriate_template_contents_owner_document: MutNullableDom<Document>

This field is set to the document itself for inert documents.

pending_restyles: DomRefCell<HashMap<Dom<Element>, PendingRestyle>>

Information on elements needing restyle to ship over to the layout thread when the time comes.

needs_paint: Cell<bool>

This flag will be true if layout suppressed a reflow attempt that was needed in order for the page to be painted.

active_touch_points: DomRefCell<Vec<Dom<Touch>>>dom_loading: Cell<u64>dom_interactive: Cell<u64>dom_content_loaded_event_start: Cell<u64>dom_content_loaded_event_end: Cell<u64>dom_complete: Cell<u64>top_level_dom_complete: Cell<u64>load_event_start: Cell<u64>load_event_end: Cell<u64>unload_event_start: Cell<u64>unload_event_end: Cell<u64>https_state: Cell<HttpsState>origin: MutableOrigin

The document’s origin.

referrer_policy: Cell<Option<ReferrerPolicy>>

referrer: Option<String>target_element: MutNullableDom<Element>last_click_info: DomRefCell<Option<(Instant, Point2D<f32>)>>ignore_destructive_writes_counter: Cell<u32>ignore_opens_during_unload_counter: Cell<u32>spurious_animation_frames: Cell<u8>

The number of spurious requestAnimationFrame() requests we’ve received.

A rAF request is considered spurious if nothing was actually reflowed.

dom_count: Cell<u32>

Track the total number of elements in this DOM’s tree. This is sent to the layout thread every time a reflow is done; layout uses this to determine if the gains from parallel layout will be worth the overhead.

See also:

fullscreen_element: MutNullableDom<Element>

Entry node for fullscreen.

form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>

Map from ID to set of form control elements that have that ID as their ‘form’ content attribute. Used to reset form controls whenever any element with the same ID as the form attribute is inserted or removed from the document. See

interactive_time: DomRefCell<InteractiveMetrics>tti_window: DomRefCell<InteractiveWindow>canceller: FetchCanceller

RAII canceller for Fetch

throw_on_dynamic_markup_insertion_counter: Cell<u64>

page_showing: Cell<bool>

salvageable: Cell<bool>

Whether the document is salvageable.

active_parser_was_aborted: Cell<bool>

Whether the document was aborted with an active parser

fired_unload: Cell<bool>

Whether the unload event has already been fired.

responsive_images: DomRefCell<Vec<Dom<HTMLImageElement>>>

List of responsive images

redirect_count: Cell<u16>

Number of redirects for the document load

script_and_layout_blockers: Cell<u32>

Number of outstanding requests to prevent JS or layout from running.

delayed_tasks: DomRefCell<Vec<Box<dyn TaskBox>>>

List of tasks to execute as soon as last script/layout blocker is removed.

completely_loaded: Cell<bool>

shadow_roots: DomRefCell<HashSet<Dom<ShadowRoot>>>

Set of shadow roots connected to the document tree.

shadow_roots_styles_changed: Cell<bool>

Whether any of the shadow roots need the stylesheets flushed.

media_controls: DomRefCell<HashMap<String, Dom<ShadowRoot>>>

List of registered media controls. We need to keep this list to allow the media controls to access the “privileged” document.servoGetMediaControls(id) API, where id needs to match any of the registered ShadowRoots hosting the media controls UI.

dirty_webgl_contexts: DomRefCell<HashMap<WebGLContextId, Dom<WebGLRenderingContext>>>

List of all WebGL context IDs that need flushing.

dirty_webgpu_contexts: DomRefCell<HashMap<WebGPUContextId, Dom<GPUCanvasContext>>>

List of all WebGPU context IDs that need flushing.

csp_list: DomRefCell<Option<CspList>>

selection: MutNullableDom<Selection>

animation_timeline: DomRefCell<AnimationTimeline>

A timeline for animations which is used for synchronizing animations.

animations: DomRefCell<Animations>

Animations for this Document

dirty_root: MutNullableDom<Element>

The nearest inclusive ancestors to all the nodes that require a restyle.


Returns the first base element in the DOM that has an href attribute.

Refresh the cached first base element in the DOM.

This is called by bind_to_tree when a node is added to the DOM. The internal count is used by layout to determine whether to be sequential or parallel. (it’s sequential for small DOMs)

This is called by unbind_from_tree when a node is removed from the DOM.

Reflows and disarms the timer if the reflow timer has expired.

Schedules a reflow to be kicked off at the given timeout (in time::precise_time_ns() units). This reflow happens even if the event loop is busy. This is used to display initial page content during parsing.

Remove any existing association between the provided id and any elements in this document.

Associate an element present in this document with the provided id.

Remove any existing association between the provided name and any elements in this document.

Associate an element present in this document with the provided name.

Attempt to find a named element in this page’s document.

Scroll to the target element, and when we do not find a target and the fragment is empty or “top”, scroll to the top.

Return whether scripting is enabled or not

Return the element that currently has focus.

Initiate a new round of checking for elements requesting focus. The last element to call request_focus before commit_focus_transaction is called will receive focus.

Request that the given element receive focus once the current transaction is complete. If None is passed, then whatever element is currently focused will no longer be focused once the transaction is complete.

Reassign the focus context to the element that last requested focus during this transaction, or none if no elements requested it.

Handles any updates when the document’s title has changed.

Sends this document’s title to the constellation.

The entry point for all key processing for web content step 22.d. step 5. step 22.d. step 5. step 22.c. step 3. step 22.d. step 3.

Iterate over all iframes in the document.

Find an iframe element in the document.

check tti for this document if it’s been 10s since this doc encountered a task over 50ms, then we consider the main thread available and try to set tti

Prevent any JS or layout from running until the corresponding call to remove_script_and_layout_blocker. Used to isolate periods in which the DOM is in an unstable state and should not be exposed to arbitrary web content. Any attempts to invoke content JS or query layout during that time will trigger a panic. add_delayed_task will cause the provided task to be executed as soon as the last blocker is removed.

Terminate the period in which JS or layout is disallowed from running. If no further blockers remain, any delayed tasks in the queue will be executed in queue order until the queue is empty.

Enqueue a task to run as soon as any JS and layout blockers are removed.

Assert that the DOM is in a state that will allow running content JS or performing a layout operation.

Return a reference to the per-document shared lock used in stylesheets.

Flushes the stylesheet list, and returns whether any stylesheet changed.

Returns a Device suitable for media query evaluation.

FIXME(emilio): This really needs to be somehow more in sync with layout. Feels like a hack.

Whether we’ve seen so many spurious animation frames (i.e. animation frames that didn’t mutate the DOM) that we’ve decided to fall back to fake ones.

Add a stylesheet owned by owner to the list of document sheets, in the correct tree position.

Remove a stylesheet owned by owner from the list of document sheets.


pub(crate) fn update_animations_post_reflow(&self)

Trait Implementations

Check whether a DOM object implements one of its deriving interfaces.
Cast a DOM object upwards to one of the interfaces it derives from.
Cast a DOM object downwards to one of the interfaces it might implement.
Returns the receiver’s reflector.
Returns the global scope of the realm that the DomObject was created in.
Function pointer to the general wrap function type

This is used in a type assertion to ensure that the source and webidls agree as to what the parent type is

Returns whether the given DOM class derives that interface.
Trace self.
Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself. Read more
Initializes the Reflector
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Convert self to a JSVal. JSAPI failure causes a panic.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more