Trait style::invalidation::element::element_wrapper::ElementSnapshot
source · pub trait ElementSnapshot: Sized {
// Required methods
fn state(&self) -> Option<ElementState>;
fn has_attrs(&self) -> bool;
fn id_attr(&self) -> Option<&WeakAtom>;
fn has_class(
&self,
name: &AtomIdent,
case_sensitivity: CaseSensitivity,
) -> bool;
fn is_part(&self, name: &AtomIdent) -> bool;
fn imported_part(&self, name: &AtomIdent) -> Option<AtomIdent>;
fn each_class<F>(&self, _: F)
where F: FnMut(&AtomIdent);
fn has_custom_states(&self) -> bool;
fn has_custom_state(&self, state: &AtomIdent) -> bool;
fn each_custom_state<F>(&self, callback: F)
where F: FnMut(&AtomIdent);
fn lang_attr(&self) -> Option<AttrValue>;
// Provided method
fn debug_list_attributes(&self) -> String { ... }
}
Expand description
In order to compute restyle hints, we perform a selector match against a list of partial selectors whose rightmost simple selector may be sensitive to the thing being changed. We do this matching twice, once for the element as it exists now and once for the element as it existed at the time of the last restyle. If the results of the selector match differ, that means that the given partial selector is sensitive to the change, and we compute a restyle hint based on its combinator.
In order to run selector matching against the old element state, we generate a wrapper for the element which claims to have the old state. This is the ElementWrapper logic below.
Gecko does this differently for element states, and passes a mask called mStateMask, which indicates the states that need to be ignored during selector matching. This saves an ElementWrapper allocation and an additional selector match call at the expense of additional complexity inside the selector matching logic. This only works for boolean states though, so we still need to take the ElementWrapper approach for attribute-dependent style. So we do it the same both ways for now to reduce complexity, but it’s worth measuring the performance impact (if any) of the mStateMask approach.
Required Methods§
sourcefn state(&self) -> Option<ElementState>
fn state(&self) -> Option<ElementState>
The state of the snapshot, if any.
sourcefn id_attr(&self) -> Option<&WeakAtom>
fn id_attr(&self) -> Option<&WeakAtom>
The ID attribute per this snapshot. Should only be called if
has_attrs()
returns true.
sourcefn has_class(&self, name: &AtomIdent, case_sensitivity: CaseSensitivity) -> bool
fn has_class(&self, name: &AtomIdent, case_sensitivity: CaseSensitivity) -> bool
Whether this snapshot contains the class name
. Should only be called
if has_attrs()
returns true.
sourcefn is_part(&self, name: &AtomIdent) -> bool
fn is_part(&self, name: &AtomIdent) -> bool
Whether this snapshot represents the part named name
. Should only be
called if has_attrs()
returns true.
sourcefn imported_part(&self, name: &AtomIdent) -> Option<AtomIdent>
fn imported_part(&self, name: &AtomIdent) -> Option<AtomIdent>
See Element::imported_part.
sourcefn each_class<F>(&self, _: F)
fn each_class<F>(&self, _: F)
A callback that should be called for each class of the snapshot. Should
only be called if has_attrs()
returns true.
sourcefn has_custom_states(&self) -> bool
fn has_custom_states(&self) -> bool
If this snapshot contains CustomStateSet information.
sourcefn has_custom_state(&self, state: &AtomIdent) -> bool
fn has_custom_state(&self, state: &AtomIdent) -> bool
A callback that should be called for each CustomState of the snapshot.
sourcefn each_custom_state<F>(&self, callback: F)
fn each_custom_state<F>(&self, callback: F)
A callback that should be called for each CustomState of the snapshot.
Provided Methods§
sourcefn debug_list_attributes(&self) -> String
fn debug_list_attributes(&self) -> String
Gets the attribute information of the snapshot as a string.
Only for debugging purposes.