LayoutNode

Trait LayoutNode 

Source
pub trait LayoutNode<'dom>:
    Copy
    + Debug
    + NodeInfo
    + Send
    + Sync {
    type ConcreteDangerousStyleNode: DangerousStyleNode<'dom>;
    type ConcreteDangerousStyleElement: DangerousStyleElement<'dom>;
    type ConcreteLayoutElement: LayoutElement<'dom>;
    type ChildIterator: Iterator<Item = Self> + Sized;

Show 34 methods // Required methods fn with_pseudo(&self, pseudo_element_type: PseudoElement) -> Option<Self>; fn pseudo_element_chain(&self) -> PseudoElementChain; unsafe fn dangerous_style_node(self) -> Self::ConcreteDangerousStyleNode; unsafe fn dangerous_dom_parent(self) -> Option<Self>; unsafe fn dangerous_flat_tree_parent(self) -> Option<Self>; fn layout_data(&self) -> Option<&'dom GenericLayoutData>; fn is_connected(&self) -> bool; fn opaque(&self) -> OpaqueNode; fn type_id(&self) -> Option<LayoutNodeType>; fn initialize_layout_data<RequestedLayoutDataType: LayoutDataTrait>(&self); fn flat_tree_children(&self) -> LayoutIterator<Self::ChildIterator>; fn dom_children(&self) -> LayoutIterator<Self::ChildIterator>; fn as_html_element(&self) -> Option<Self::ConcreteLayoutElement>; fn as_element(&self) -> Option<Self::ConcreteLayoutElement>; fn style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>; fn parent_style( &self, context: &SharedStyleContext<'_>, ) -> Arc<ComputedValues>; fn selected_style( &self, context: &SharedStyleContext<'_>, ) -> Arc<ComputedValues>; fn text_content(self) -> Cow<'dom, str>; fn selection(&self) -> Option<SharedSelection>; fn image_url(&self) -> Option<ServoUrl>; fn image_density(&self) -> Option<f64>; fn image_data(&self) -> Option<(Option<Image>, Option<ImageMetadata>)>; fn showing_broken_image_icon(&self) -> bool; fn canvas_data(&self) -> Option<HTMLCanvasData>; fn svg_data(&self) -> Option<SVGElementData<'dom>>; fn media_data(&self) -> Option<HTMLMediaData>; fn iframe_browsing_context_id(&self) -> Option<BrowsingContextId>; fn iframe_pipeline_id(&self) -> Option<PipelineId>; fn table_span(&self) -> Option<u32>; fn table_colspan(&self) -> Option<u32>; fn table_rowspan(&self) -> Option<u32>; fn is_single_line_text_input(&self) -> bool; fn is_root_of_user_agent_widget(&self) -> bool; fn set_uses_content_attribute_with_attr( &self, _uses_content_attribute_with_attr: bool, );
}
Expand description

A trait that exposes a DOM nodes to layout. Implementors of this trait must abide by certain safety requirements. Layout will only ever access and mutate each node from a single thread at a time, though children may be used in parallel from other threads. That is why this trait does not allow access to parent nodes, as it would make it easy to cause race conditions and memory errors.

Note that the related DangerousStyleNode trait may access parent nodes, which is why that API is marked as unsafe here. In general DangerousStyleNode should only be used when interfacing with the stylo and selectors.

Required Associated Types§

Source

type ConcreteDangerousStyleNode: DangerousStyleNode<'dom>

The concrete implementation of DangerousStyleNode implemented in script.

Source

type ConcreteDangerousStyleElement: DangerousStyleElement<'dom>

The concrete implementation of DangerousStyleElement implemented in script.

Source

type ConcreteLayoutElement: LayoutElement<'dom>

The concrete implementation of [ConcreteLayoutElement] implemented in script.

Source

type ChildIterator: Iterator<Item = Self> + Sized

The concrete implementation of [ChildIterator] implemented in script.

Required Methods§

Source

fn with_pseudo(&self, pseudo_element_type: PseudoElement) -> Option<Self>

Creates a new LayoutNode for the same LayoutNode with a different pseudo-element type.

Returns None if this pseudo doesn’t apply to the given element for one of the following reasons:

  1. This node is not an element.
  2. pseudo is eager and is not defined in the stylesheet. In this case, there is not reason to process the pseudo element at all.
  3. pseudo is for ::servo-details-content and it doesn’t apply to this element, either because it isn’t a details or is in the wrong state.
Source

fn pseudo_element_chain(&self) -> PseudoElementChain

Returns the PseudoElementChain for this LayoutElement.

Source

unsafe fn dangerous_style_node(self) -> Self::ConcreteDangerousStyleNode

Returns access to a version of this LayoutNode that can be used by stylo and selectors. This is dangerous as it allows more access to ancestors nodes than LayoutNode. This should only be used when handing a node to stylo or selectors.

§Safety

This should only ever be called from the main script thread. It is never okay to explicitly create a node for style while any layout worker threads are running.

Source

unsafe fn dangerous_dom_parent(self) -> Option<Self>

Returns access to the DOM parent node of this node. This does not take into account shadow tree children and slottables. For that use Self::dangerous_flat_tree_parent.

§Safety

This should only ever be called from the main script thread. It is never okay to explicitly access the parent node while any layout worker threads are running.

Source

unsafe fn dangerous_flat_tree_parent(self) -> Option<Self>

Returns access to the flat tree parent node of this node. This takes into account shadow tree children and slottables. For that use Self::dangerous_flat_tree_parent.

§Safety

This should only ever be called from the main script thread. It is never okay to explicitly access the parent node while any layout worker threads are running.

Source

fn layout_data(&self) -> Option<&'dom GenericLayoutData>

Get the layout data of this node, attempting to downcast it to the desired type. Returns None if there is no layout data or it isn’t of the desired type.

Source

fn is_connected(&self) -> bool

Returns whether the node is connected.

Source

fn opaque(&self) -> OpaqueNode

Converts self into an OpaqueNode.

Source

fn type_id(&self) -> Option<LayoutNodeType>

Returns the type ID of this node. Returns None if this is a pseudo-element; otherwise, returns Some.

Source

fn initialize_layout_data<RequestedLayoutDataType: LayoutDataTrait>(&self)

Initialize this node with empty opaque layout data.

Source

fn flat_tree_children(&self) -> LayoutIterator<Self::ChildIterator>

Returns an iterator over this node’s children in the flat tree. This takes into account shadow tree children and slottables.

Source

fn dom_children(&self) -> LayoutIterator<Self::ChildIterator>

Returns an iterator over this node’s children in the DOM. This does not take shadow roots and assigned slottables into account. For that use Self::flat_tree_children.

Source

fn as_html_element(&self) -> Option<Self::ConcreteLayoutElement>

Returns a LayoutElement if this is an element in the HTML namespace, None otherwise.

Source

fn as_element(&self) -> Option<Self::ConcreteLayoutElement>

Returns a LayoutElement if this is an element.

Source

fn style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>

Returns the computed style for the given node, properly handling pseudo-elements. For elements this returns their style and for other nodes, this returns the style of the parent element, if one exists.

§Panics
  • Calling this method will panic it is an element has no style data, whether because styling has not run yet or was not run for this element.
  • Calling this method will panic if it is a non-element node without a parent element.
Source

fn parent_style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>

Returns the style for a text node. This is computed on the fly from the parent style to avoid traversing text nodes in the style system.

§Safety

Note that this does require accessing the parent, which this interface technically forbids. But accessing the parent is only unsafe insofar as it can be used to reach siblings and cousins. A simple immutable borrow of the parent data is fine, since the bottom-up traversal will not process the parent until all the children have been processed.

§Panics
  • Calling this method will panic if the parent element has no style data, whether because styling has not run yet or was not run for this element.
  • Calling this method will panic if it is a non-element node without a parent element.
Source

fn selected_style( &self, context: &SharedStyleContext<'_>, ) -> Arc<ComputedValues>

Returns the computed :selected style for the given node, properly handling pseudo-elements. For elements this returns their style and for other nodes, this returns the style of the parent element, if one exists.

§Panics
  • Calling this method will panic it is an element has no style data, whether because styling has not run yet or was not run for this element.
  • Calling this method will panic if it is a non-element node without a parent element.
Source

fn text_content(self) -> Cow<'dom, str>

Get the text content of this node, if it is a text node.

§Panics

This method will panic if called on a node that is not a DOM text node.

Source

fn selection(&self) -> Option<SharedSelection>

If this node manages a selection, this returns the shared selection for the node.

Source

fn image_url(&self) -> Option<ServoUrl>

If this is an image element, returns its URL. If this is not an image element, fails.

Source

fn image_density(&self) -> Option<f64>

If this is an image element, returns its current-pixel-density. If this is not an image element, fails.

Source

fn image_data(&self) -> Option<(Option<Image>, Option<ImageMetadata>)>

If this is an image element, returns its image data. Otherwise, returns None.

Source

fn showing_broken_image_icon(&self) -> bool

Whether or not this is an image element that is showing a broken image icon.

Source

fn canvas_data(&self) -> Option<HTMLCanvasData>

Return the [HTMLCanvas] data for this node, if it is a canvas.

Source

fn svg_data(&self) -> Option<SVGElementData<'dom>>

Return the SVGElementData for this node, if it is an SVG subtree.

Source

fn media_data(&self) -> Option<HTMLMediaData>

Return the HTMLMediaData for this node, if it is a media element.

Source

fn iframe_browsing_context_id(&self) -> Option<BrowsingContextId>

If this node is an iframe element, returns its browsing context ID. If this node is not an iframe element, fails. Returns None if there is no nested browsing context.

Source

fn iframe_pipeline_id(&self) -> Option<PipelineId>

If this node is an iframe element, returns its pipeline ID. If this node is not an iframe element, fails. Returns None if there is no nested browsing context.

Source

fn table_span(&self) -> Option<u32>

Return the table span property if it is an element that supports it.

Source

fn table_colspan(&self) -> Option<u32>

Return the table colspan property if it is an element that supports it.

Source

fn table_rowspan(&self) -> Option<u32>

Return the table rowspan property if it is an element that supports it.

Source

fn is_single_line_text_input(&self) -> bool

Whether this is a container for the text within a single-line text input. This is used to solve the special case of line height for a text entry widget. https://html.spec.whatwg.org/multipage/#the-input-element-as-a-text-entry-widget

Source

fn is_root_of_user_agent_widget(&self) -> bool

Whether or not this LayoutNode is in a user agent widget shadow DOM.

Source

fn set_uses_content_attribute_with_attr( &self, _uses_content_attribute_with_attr: bool, )

Set whether or not this node has an active pseudo-element style with a content attribute that uses attr.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§