pub trait LayoutElement<'dom>:
Copy
+ Debug
+ Send
+ Sync {
type ConcreteStyleElement: DangerousStyleElement<'dom>;
type ConcreteLayoutNode: LayoutNode<'dom>;
Show 19 methods
// Required methods
fn with_pseudo(&self, pseudo: PseudoElement) -> Option<Self>;
fn pseudo_element_chain(&self) -> PseudoElementChain;
fn as_node(&self) -> Self::ConcreteLayoutNode;
unsafe fn dangerous_style_element(self) -> Self::ConcreteStyleElement;
fn initialize_style_and_layout_data<RequestedLayoutDataType: LayoutDataTrait>(
&self,
);
fn unset_snapshot_flags(&self);
fn set_has_snapshot(&self);
fn style_data(self) -> Option<&'dom StyleData>;
fn type_id(&self) -> Option<LayoutNodeType>;
fn local_name(&self) -> &LocalName;
fn attribute(
&self,
namespace: &Namespace,
name: &LocalName,
) -> Option<&AttrValue>;
fn attribute_as_str<'a>(
&'a self,
namespace: &Namespace,
name: &LocalName,
) -> Option<&'a str>;
fn element_data(&self) -> ElementDataRef<'dom>;
fn element_data_mut(&self) -> ElementDataMut<'dom>;
fn style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>;
fn is_shadow_host(&self) -> bool;
fn is_body_element_of_html_element_root(&self) -> bool;
fn is_html_element_in_html_document(&self) -> bool;
fn is_root(&self) -> bool;
}Expand description
A trait that exposes a DOM element to layout. Implementors of this trait must abide by certain safety requirements. Layout will only ever access and mutate each element 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 DangerousStyleElement trait may access parent nodes, which is why
that API is marked as unsafe here. In general DangerousStyleElement should only be used
when interfacing with the stylo and selectors.
Required Associated Types§
Sourcetype ConcreteStyleElement: DangerousStyleElement<'dom>
type ConcreteStyleElement: DangerousStyleElement<'dom>
An associated type that refers to the concrete implementation of DangerousStyleElement
implemented in script.
Sourcetype ConcreteLayoutNode: LayoutNode<'dom>
type ConcreteLayoutNode: LayoutNode<'dom>
An associated type that refers to the concrete implementation of LayoutNode
implemented in script.
Required Methods§
Sourcefn with_pseudo(&self, pseudo: PseudoElement) -> Option<Self>
fn with_pseudo(&self, pseudo: PseudoElement) -> Option<Self>
Creates a new LayoutElement for the same LayoutElement
with a different pseudo-element type.
Returns None if this pseudo doesn’t apply to the given element for one of
the following reasons:
pseudois eager and is not defined in the stylesheet. In this case, there is not reason to process the pseudo element at all.pseudois for::servo-details-contentand it doesn’t apply to this element, either because it isn’t a details or is in the wrong state.
Sourcefn pseudo_element_chain(&self) -> PseudoElementChain
fn pseudo_element_chain(&self) -> PseudoElementChain
Returns the PseudoElementChain for this LayoutElement.
Sourcefn as_node(&self) -> Self::ConcreteLayoutNode
fn as_node(&self) -> Self::ConcreteLayoutNode
Return this LayoutElement as a LayoutNode, preserving the internal
pseudo-element chain.
Sourceunsafe fn dangerous_style_element(self) -> Self::ConcreteStyleElement
unsafe fn dangerous_style_element(self) -> Self::ConcreteStyleElement
Returns access to a version of this LayoutElement that can be used by stylo and selectors. This is dangerous as it allows more access to ancestor nodes that might be in the process of being read or written to in other threads. 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.
Sourcefn initialize_style_and_layout_data<RequestedLayoutDataType: LayoutDataTrait>(
&self,
)
fn initialize_style_and_layout_data<RequestedLayoutDataType: LayoutDataTrait>( &self, )
Initialize this node with empty style and opaque layout data.
Sourcefn unset_snapshot_flags(&self)
fn unset_snapshot_flags(&self)
Unset the snapshot flags on the underlying DOM object for this element.
Sourcefn set_has_snapshot(&self)
fn set_has_snapshot(&self)
Set the snapshot flags on the underlying DOM object for this element.
Sourcefn style_data(self) -> Option<&'dom StyleData>
fn style_data(self) -> Option<&'dom StyleData>
Get the StyleData for this LayoutElement.
Sourcefn type_id(&self) -> Option<LayoutNodeType>
fn type_id(&self) -> Option<LayoutNodeType>
Returns the type ID of this node.
Returns None if this is a pseudo-element; otherwise, returns Some.
Sourcefn local_name(&self) -> &LocalName
fn local_name(&self) -> &LocalName
Get the local name of this element. See https://dom.spec.whatwg.org/#concept-element-local-name.
Sourcefn attribute(
&self,
namespace: &Namespace,
name: &LocalName,
) -> Option<&AttrValue>
fn attribute( &self, namespace: &Namespace, name: &LocalName, ) -> Option<&AttrValue>
Get the attribute with the given namespace and name as an AttrValue if it
exists, otherwise return None.
Sourcefn attribute_as_str<'a>(
&'a self,
namespace: &Namespace,
name: &LocalName,
) -> Option<&'a str>
fn attribute_as_str<'a>( &'a self, namespace: &Namespace, name: &LocalName, ) -> Option<&'a str>
Get the attribute with the given namespace and name as an AttrValue if it
exists and converting the result to a &str, otherwise return None.
Sourcefn element_data(&self) -> ElementDataRef<'dom>
fn element_data(&self) -> ElementDataRef<'dom>
Get a reference to the inner ElementDataRef for this element’s StyleData. This will
panic if the element is unstyled.
Sourcefn element_data_mut(&self) -> ElementDataMut<'dom>
fn element_data_mut(&self) -> ElementDataMut<'dom>
Get a mutable reference to the inner ElementDataRef for this element’s StyleData.
This will panic if the element is unstyled.
Sourcefn style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>
fn style(&self, context: &SharedStyleContext<'_>) -> Arc<ComputedValues>
Returns the computed style for the given element, properly handling pseudo-elements.
§Panics
Calling this method will panic if the element has no style data, whether because styling has not run yet or was not run for this element.
Sourcefn is_shadow_host(&self) -> bool
fn is_shadow_host(&self) -> bool
Returns true if this LayoutElement is a shadow DOM host and false otherwise.
Sourcefn is_body_element_of_html_element_root(&self) -> bool
fn is_body_element_of_html_element_root(&self) -> bool
Returns whether this node is a body element of an HTML element root in an HTML document.
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.
Sourcefn is_html_element_in_html_document(&self) -> bool
fn is_html_element_in_html_document(&self) -> bool
Returns true if this LayoutNode is any kind of HTML element inside an HTML document
and false otherwise.
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.