pub trait TElement: Eq + PartialEq + Debug + Hash + Sized + Copy + Clone + SelectorsElement<Impl = SelectorImpl> {
type ConcreteNode: TNode<ConcreteElement = Self>;
type TraversalChildrenIterator: Iterator<Item = Self::ConcreteNode>;
Show 71 methods
// Required methods
fn unopaque(opaque: OpaqueElement) -> Self;
fn as_node(&self) -> Self::ConcreteNode;
fn traversal_children(
&self,
) -> LayoutIterator<Self::TraversalChildrenIterator> ⓘ;
fn is_html_element(&self) -> bool;
fn is_mathml_element(&self) -> bool;
fn is_svg_element(&self) -> bool;
fn style_attribute(
&self,
) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>;
fn animation_rule(
&self,
_: &SharedStyleContext<'_>,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>>;
fn transition_rule(
&self,
context: &SharedStyleContext<'_>,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>>;
fn state(&self) -> ElementState;
fn has_part_attr(&self) -> bool;
fn exports_any_part(&self) -> bool;
fn id(&self) -> Option<&WeakAtom>;
fn each_class<F>(&self, callback: F)
where F: FnMut(&AtomIdent);
fn each_custom_state<F>(&self, callback: F)
where F: FnMut(&AtomIdent);
fn each_attr_name<F>(&self, callback: F)
where F: FnMut(&LocalName);
fn has_dirty_descendants(&self) -> bool;
fn has_snapshot(&self) -> bool;
fn handled_snapshot(&self) -> bool;
unsafe fn set_handled_snapshot(&self);
unsafe fn set_dirty_descendants(&self);
unsafe fn unset_dirty_descendants(&self);
fn store_children_to_process(&self, n: isize);
fn did_process_child(&self) -> isize;
unsafe fn ensure_data(&self) -> AtomicRefMut<'_, ElementData>;
unsafe fn clear_data(&self);
fn has_data(&self) -> bool;
fn borrow_data(&self) -> Option<AtomicRef<'_, ElementData>>;
fn mutate_data(&self) -> Option<AtomicRefMut<'_, ElementData>>;
fn skip_item_display_fixup(&self) -> bool;
fn may_have_animations(&self) -> bool;
fn has_animations(&self, context: &SharedStyleContext<'_>) -> bool;
fn has_css_animations(
&self,
context: &SharedStyleContext<'_>,
pseudo_element: Option<PseudoElement>,
) -> bool;
fn has_css_transitions(
&self,
context: &SharedStyleContext<'_>,
pseudo_element: Option<PseudoElement>,
) -> bool;
fn shadow_root(
&self,
) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>;
fn containing_shadow(
&self,
) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>;
fn lang_attr(&self) -> Option<AttrValue>;
fn match_element_lang(
&self,
override_lang: Option<Option<AttrValue>>,
value: &Lang,
) -> bool;
fn is_html_document_body_element(&self) -> bool;
fn synthesize_presentational_hints_for_legacy_attributes<V>(
&self,
visited_handling: VisitedHandlingMode,
hints: &mut V,
)
where V: Push<ApplicableDeclarationBlock>;
fn local_name(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedLocalName;
fn namespace(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedNamespaceUrl;
fn query_container_size(&self, display: &Display) -> Size2D<Option<Au>>;
fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool;
fn relative_selector_search_direction(&self) -> ElementSelectorFlags;
// Provided methods
fn owner_doc_matches_for_testing(&self, _: &Device) -> bool { ... }
fn matches_user_and_content_rules(&self) -> bool { ... }
fn traversal_parent(&self) -> Option<Self> { ... }
fn inheritance_parent(&self) -> Option<Self> { ... }
fn before_pseudo_element(&self) -> Option<Self> { ... }
fn after_pseudo_element(&self) -> Option<Self> { ... }
fn marker_pseudo_element(&self) -> Option<Self> { ... }
fn each_anonymous_content_child<F>(&self, _f: F)
where F: FnMut(Self) { ... }
fn is_xul_element(&self) -> bool { ... }
fn slotted_nodes(&self) -> &[Self::ConcreteNode] { ... }
fn unset_dirty_style_attribute(&self) { ... }
fn smil_override(
&self,
) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>> { ... }
fn animation_declarations(
&self,
context: &SharedStyleContext<'_>,
) -> AnimationDeclarations { ... }
fn each_part<F>(&self, _callback: F)
where F: FnMut(&AtomIdent) { ... }
fn each_exported_part<F>(&self, _name: &AtomIdent, _callback: F)
where F: FnMut(&AtomIdent) { ... }
fn may_generate_pseudo(
&self,
pseudo: &PseudoElement,
_primary_style: &ComputedValues,
) -> bool { ... }
fn has_current_styles(&self, data: &ElementData) -> bool { ... }
fn has_animation_only_dirty_descendants(&self) -> bool { ... }
unsafe fn set_animation_only_dirty_descendants(&self) { ... }
unsafe fn unset_animation_only_dirty_descendants(&self) { ... }
unsafe fn clear_descendant_bits(&self) { ... }
fn is_visited_link(&self) -> bool { ... }
fn implemented_pseudo_element(&self) -> Option<PseudoElement> { ... }
fn has_animation_restyle_hints(&self) -> bool { ... }
fn rule_hash_target(&self) -> Self { ... }
fn each_applicable_non_document_style_rule_data<'a, F>(&self, f: F) -> bool
where Self: 'a,
F: FnMut(&'a CascadeData, Self) { ... }
}
Expand description
The element trait, the main abstraction the style crate acts over.
Required Associated Types§
sourcetype ConcreteNode: TNode<ConcreteElement = Self>
type ConcreteNode: TNode<ConcreteElement = Self>
The concrete node type.
sourcetype TraversalChildrenIterator: Iterator<Item = Self::ConcreteNode>
type TraversalChildrenIterator: Iterator<Item = Self::ConcreteNode>
A concrete children iterator type in order to iterate over the Node
s.
TODO(emilio): We should eventually replace this with the impl Trait
syntax.
Required Methods§
sourcefn unopaque(opaque: OpaqueElement) -> Self
fn unopaque(opaque: OpaqueElement) -> Self
Convert an opaque element back into the element.
sourcefn as_node(&self) -> Self::ConcreteNode
fn as_node(&self) -> Self::ConcreteNode
Get this element as a node.
sourcefn traversal_children(&self) -> LayoutIterator<Self::TraversalChildrenIterator> ⓘ
fn traversal_children(&self) -> LayoutIterator<Self::TraversalChildrenIterator> ⓘ
Get this node’s children from the perspective of a restyle traversal.
sourcefn is_html_element(&self) -> bool
fn is_html_element(&self) -> bool
Return whether this element is an element in the HTML namespace.
sourcefn is_mathml_element(&self) -> bool
fn is_mathml_element(&self) -> bool
Return whether this element is an element in the MathML namespace.
sourcefn is_svg_element(&self) -> bool
fn is_svg_element(&self) -> bool
Return whether this element is an element in the SVG namespace.
sourcefn style_attribute(
&self,
) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>
fn style_attribute( &self, ) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>
Get this element’s style attribute.
sourcefn animation_rule(
&self,
_: &SharedStyleContext<'_>,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>>
fn animation_rule( &self, _: &SharedStyleContext<'_>, ) -> Option<Arc<Locked<PropertyDeclarationBlock>>>
Get this element’s animation rule.
sourcefn transition_rule(
&self,
context: &SharedStyleContext<'_>,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>>
fn transition_rule( &self, context: &SharedStyleContext<'_>, ) -> Option<Arc<Locked<PropertyDeclarationBlock>>>
Get this element’s transition rule.
sourcefn state(&self) -> ElementState
fn state(&self) -> ElementState
Get this element’s state, for non-tree-structural pseudos.
sourcefn has_part_attr(&self) -> bool
fn has_part_attr(&self) -> bool
Returns whether this element has a part
attribute.
sourcefn exports_any_part(&self) -> bool
fn exports_any_part(&self) -> bool
Returns whether this element exports any part from its shadow tree.
sourcefn each_class<F>(&self, callback: F)
fn each_class<F>(&self, callback: F)
Internal iterator for the classes of this element.
sourcefn each_custom_state<F>(&self, callback: F)
fn each_custom_state<F>(&self, callback: F)
Internal iterator for the classes of this element.
sourcefn each_attr_name<F>(&self, callback: F)
fn each_attr_name<F>(&self, callback: F)
Internal iterator for the attribute names of this element.
sourcefn has_dirty_descendants(&self) -> bool
fn has_dirty_descendants(&self) -> bool
Returns true if this element may have a descendant needing style processing.
Note that we cannot guarantee the existence of such an element, because it may have been removed from the DOM between marking it for restyle and the actual restyle traversal.
sourcefn has_snapshot(&self) -> bool
fn has_snapshot(&self) -> bool
Returns whether state or attributes that may change style have changed on the element, and thus whether the element has been snapshotted to do restyle hint computation.
sourcefn handled_snapshot(&self) -> bool
fn handled_snapshot(&self) -> bool
Returns whether the current snapshot if present has been handled.
sourceunsafe fn set_handled_snapshot(&self)
unsafe fn set_handled_snapshot(&self)
Flags this element as having handled already its snapshot.
sourceunsafe fn set_dirty_descendants(&self)
unsafe fn set_dirty_descendants(&self)
Flag that this element has a descendant for style processing.
Only safe to call with exclusive access to the element.
sourceunsafe fn unset_dirty_descendants(&self)
unsafe fn unset_dirty_descendants(&self)
Flag that this element has no descendant for style processing.
Only safe to call with exclusive access to the element.
sourcefn store_children_to_process(&self, n: isize)
fn store_children_to_process(&self, n: isize)
Atomically stores the number of children of this node that we will need to process during bottom-up traversal.
sourcefn did_process_child(&self) -> isize
fn did_process_child(&self) -> isize
Atomically notes that a child has been processed during bottom-up traversal. Returns the number of children left to process.
sourceunsafe fn ensure_data(&self) -> AtomicRefMut<'_, ElementData>
unsafe fn ensure_data(&self) -> AtomicRefMut<'_, ElementData>
Gets a reference to the ElementData container, or creates one.
Unsafe because it can race to allocate and leak if not used with exclusive access to the element.
sourceunsafe fn clear_data(&self)
unsafe fn clear_data(&self)
Clears the element data reference, if any.
Unsafe following the same reasoning as ensure_data.
sourcefn borrow_data(&self) -> Option<AtomicRef<'_, ElementData>>
fn borrow_data(&self) -> Option<AtomicRef<'_, ElementData>>
Immutably borrows the ElementData.
sourcefn mutate_data(&self) -> Option<AtomicRefMut<'_, ElementData>>
fn mutate_data(&self) -> Option<AtomicRefMut<'_, ElementData>>
Mutably borrows the ElementData.
sourcefn skip_item_display_fixup(&self) -> bool
fn skip_item_display_fixup(&self) -> bool
Whether we should skip any root- or item-based display property blockification on this element. (This function exists so that Gecko native anonymous content can opt out of this style fixup.)
sourcefn may_have_animations(&self) -> bool
fn may_have_animations(&self) -> bool
In Gecko, element has a flag that represents the element may have any type of animations or not to bail out animation stuff early. Whereas Servo doesn’t have such flag.
sourcefn has_animations(&self, context: &SharedStyleContext<'_>) -> bool
fn has_animations(&self, context: &SharedStyleContext<'_>) -> bool
Returns true if the element has relevant animations. Relevant animations are those animations that are affecting the element’s style or are scheduled to do so in the future.
sourcefn has_css_animations(
&self,
context: &SharedStyleContext<'_>,
pseudo_element: Option<PseudoElement>,
) -> bool
fn has_css_animations( &self, context: &SharedStyleContext<'_>, pseudo_element: Option<PseudoElement>, ) -> bool
Returns true if the element has a CSS animation. The context
and pseudo_element
arguments are only used by Servo, since it stores animations globally and pseudo-elements
are not in the DOM.
sourcefn has_css_transitions(
&self,
context: &SharedStyleContext<'_>,
pseudo_element: Option<PseudoElement>,
) -> bool
fn has_css_transitions( &self, context: &SharedStyleContext<'_>, pseudo_element: Option<PseudoElement>, ) -> bool
Returns true if the element has a CSS transition (including running transitions and
completed transitions). The context
and pseudo_element
arguments are only used
by Servo, since it stores animations globally and pseudo-elements are not in the DOM.
sourcefn shadow_root(
&self,
) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>
fn shadow_root( &self, ) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>
The shadow root this element is a host of.
sourcefn containing_shadow(
&self,
) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>
fn containing_shadow( &self, ) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>
The shadow root which roots the subtree this element is contained in.
sourcefn lang_attr(&self) -> Option<AttrValue>
fn lang_attr(&self) -> Option<AttrValue>
Returns the value of the xml:lang=""
attribute (or, if appropriate,
the lang=""
attribute) on this element.
sourcefn match_element_lang(
&self,
override_lang: Option<Option<AttrValue>>,
value: &Lang,
) -> bool
fn match_element_lang( &self, override_lang: Option<Option<AttrValue>>, value: &Lang, ) -> bool
Returns whether this element’s language matches the language tag
value
. If override_lang
is not None
, it specifies the value
of the xml:lang=""
or lang=""
attribute to use in place of
looking at the element and its ancestors. (This argument is used
to implement matching of :lang()
against snapshots.)
sourcefn is_html_document_body_element(&self) -> bool
fn is_html_document_body_element(&self) -> bool
Returns whether this element is the main body element of the HTML document it is on.
sourcefn synthesize_presentational_hints_for_legacy_attributes<V>(
&self,
visited_handling: VisitedHandlingMode,
hints: &mut V,
)where
V: Push<ApplicableDeclarationBlock>,
fn synthesize_presentational_hints_for_legacy_attributes<V>(
&self,
visited_handling: VisitedHandlingMode,
hints: &mut V,
)where
V: Push<ApplicableDeclarationBlock>,
Generate the proper applicable declarations due to presentational hints,
and insert them into hints
.
sourcefn local_name(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedLocalName
fn local_name(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedLocalName
Returns element’s local name.
sourcefn namespace(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedNamespaceUrl
fn namespace(&self) -> &<SelectorImpl as SelectorImpl>::BorrowedNamespaceUrl
Returns element’s namespace.
sourcefn query_container_size(&self, display: &Display) -> Size2D<Option<Au>>
fn query_container_size(&self, display: &Display) -> Size2D<Option<Au>>
Returns the size of the element to be used in container size queries. This will usually be the size of the content area of the primary box, but can be None if there is no box or if some axis lacks size containment.
sourcefn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool
fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool
Returns true if the element has all of specified selector flags.
sourcefn relative_selector_search_direction(&self) -> ElementSelectorFlags
fn relative_selector_search_direction(&self) -> ElementSelectorFlags
Returns the search direction for relative selector invalidation, if it is on the search path.
Provided Methods§
sourcefn owner_doc_matches_for_testing(&self, _: &Device) -> bool
fn owner_doc_matches_for_testing(&self, _: &Device) -> bool
A debug-only check that the device’s owner doc matches the actual doc we’re the root of.
Otherwise we may set document-level state incorrectly, like the root font-size used for rem units.
sourcefn matches_user_and_content_rules(&self) -> bool
fn matches_user_and_content_rules(&self) -> bool
Whether this element should match user and content rules.
We use this for Native Anonymous Content in Gecko.
sourcefn traversal_parent(&self) -> Option<Self>
fn traversal_parent(&self) -> Option<Self>
Get this node’s parent element from the perspective of a restyle traversal.
sourcefn inheritance_parent(&self) -> Option<Self>
fn inheritance_parent(&self) -> Option<Self>
Returns the parent element we should inherit from.
This is pretty much always the parent element itself, except in the case of Gecko’s Native Anonymous Content, which uses the traversal parent (i.e. the flattened tree parent) and which also may need to find the closest non-NAC ancestor.
sourcefn before_pseudo_element(&self) -> Option<Self>
fn before_pseudo_element(&self) -> Option<Self>
The ::before pseudo-element of this element, if it exists.
sourcefn after_pseudo_element(&self) -> Option<Self>
fn after_pseudo_element(&self) -> Option<Self>
The ::after pseudo-element of this element, if it exists.
sourcefn marker_pseudo_element(&self) -> Option<Self>
fn marker_pseudo_element(&self) -> Option<Self>
The ::marker pseudo-element of this element, if it exists.
sourcefn each_anonymous_content_child<F>(&self, _f: F)where
F: FnMut(Self),
fn each_anonymous_content_child<F>(&self, _f: F)where
F: FnMut(Self),
Execute f
for each anonymous content child (apart from ::before and
::after) whose originating element is self
.
sourcefn is_xul_element(&self) -> bool
fn is_xul_element(&self) -> bool
Return whether this element is an element in the XUL namespace.
sourcefn slotted_nodes(&self) -> &[Self::ConcreteNode]
fn slotted_nodes(&self) -> &[Self::ConcreteNode]
Return the list of slotted nodes of this node.
sourcefn unset_dirty_style_attribute(&self)
fn unset_dirty_style_attribute(&self)
Unset the style attribute’s dirty bit. Servo doesn’t need to manage ditry bit for style attribute.
sourcefn smil_override(
&self,
) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>
fn smil_override( &self, ) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>
Get this element’s SMIL override declarations.
sourcefn animation_declarations(
&self,
context: &SharedStyleContext<'_>,
) -> AnimationDeclarations
fn animation_declarations( &self, context: &SharedStyleContext<'_>, ) -> AnimationDeclarations
Get the combined animation and transition rules.
FIXME(emilio): Is this really useful?
sourcefn each_exported_part<F>(&self, _name: &AtomIdent, _callback: F)
fn each_exported_part<F>(&self, _name: &AtomIdent, _callback: F)
Internal iterator for the part names that this element exports for a given part name.
sourcefn may_generate_pseudo(
&self,
pseudo: &PseudoElement,
_primary_style: &ComputedValues,
) -> bool
fn may_generate_pseudo( &self, pseudo: &PseudoElement, _primary_style: &ComputedValues, ) -> bool
Whether a given element may generate a pseudo-element.
This is useful to avoid computing, for example, pseudo styles for
::-first-line
or ::-first-letter
, when we know it won’t affect us.
TODO(emilio, bz): actually implement the logic for it.
sourcefn has_current_styles(&self, data: &ElementData) -> bool
fn has_current_styles(&self, data: &ElementData) -> bool
Returns whether the element’s styles are up-to-date after traversal (i.e. in post traversal).
sourcefn has_animation_only_dirty_descendants(&self) -> bool
fn has_animation_only_dirty_descendants(&self) -> bool
Similar to the dirty_descendants but for representing a descendant of the element needs to be updated in animation-only traversal.
sourceunsafe fn set_animation_only_dirty_descendants(&self)
unsafe fn set_animation_only_dirty_descendants(&self)
Flag that this element has a descendant for animation-only restyle processing.
Only safe to call with exclusive access to the element.
sourceunsafe fn unset_animation_only_dirty_descendants(&self)
unsafe fn unset_animation_only_dirty_descendants(&self)
Flag that this element has no descendant for animation-only restyle processing.
Only safe to call with exclusive access to the element.
sourceunsafe fn clear_descendant_bits(&self)
unsafe fn clear_descendant_bits(&self)
Clear all bits related describing the dirtiness of descendants.
In Gecko, this corresponds to the regular dirty descendants bit, the animation-only dirty descendants bit, and the lazy frame construction descendants bit.
sourcefn is_visited_link(&self) -> bool
fn is_visited_link(&self) -> bool
Returns true if this element is a visited link.
Servo doesn’t support visited styles yet.
sourcefn implemented_pseudo_element(&self) -> Option<PseudoElement>
fn implemented_pseudo_element(&self) -> Option<PseudoElement>
Returns the pseudo-element implemented by this element, if any.
Gecko traverses pseudo-elements during the style traversal, and we need to know this so we can properly grab the pseudo-element style from the parent element.
Note that we still need to compute the pseudo-elements before-hand, given otherwise we don’t know if we need to create an element or not.
Servo doesn’t have to deal with this.
sourcefn has_animation_restyle_hints(&self) -> bool
fn has_animation_restyle_hints(&self) -> bool
Returns true if the element has animation restyle hints.
sourcefn rule_hash_target(&self) -> Self
fn rule_hash_target(&self) -> Self
Return the element which we can use to look up rules in the selector maps.
This is always the element itself, except in the case where we are an element-backed pseudo-element, in which case we return the originating element.
sourcefn each_applicable_non_document_style_rule_data<'a, F>(&self, f: F) -> boolwhere
Self: 'a,
F: FnMut(&'a CascadeData, Self),
fn each_applicable_non_document_style_rule_data<'a, F>(&self, f: F) -> boolwhere
Self: 'a,
F: FnMut(&'a CascadeData, Self),
Executes the callback for each applicable style rule data which isn’t the main document’s data (which stores UA / author rules).
The element passed to the callback is the containing shadow host for the data if it comes from Shadow DOM.
Returns whether normal document author rules should apply.
TODO(emilio): We could separate the invalidation data for elements matching in other scopes to avoid over-invalidation.