pub struct Stylist {
device: Device,
stylesheets: StylistStylesheetSet,
author_data_cache: CascadeDataCache<CascadeData>,
quirks_mode: QuirksMode,
cascade_data: DocumentCascadeData,
author_styles_enabled: AuthorStylesEnabled,
rule_tree: RuleTree,
script_custom_properties: ScriptRegistry,
initial_values_for_custom_properties: ComputedCustomProperties,
initial_values_for_custom_properties_flags: ComputedValueFlags,
num_rebuilds: usize,
}
Expand description
This structure holds all the selectors and device characteristics
for a given document. The selectors are converted into Rule
s
and sorted into SelectorMap
s keyed off stylesheet origin and
pseudo-element (see CascadeData
).
This structure is effectively created once per pipeline, in the LayoutThread corresponding to that pipeline.
Fields§
§device: Device
Device that the stylist is currently evaluating against.
This field deserves a bigger comment due to the different use that Gecko and Servo give to it (that we should eventually unify).
With Gecko, the device is never changed. Gecko manually tracks whether the device data should be reconstructed, and “resets” the state of the device.
On Servo, on the other hand, the device is a really cheap representation
that is recreated each time some constraint changes and calling
set_device
.
stylesheets: StylistStylesheetSet
The list of stylesheets.
A cache of CascadeDatas for AuthorStylesheetSets (i.e., shadow DOM).
quirks_mode: QuirksMode
If true, the quirks-mode stylesheet is applied.
cascade_data: DocumentCascadeData
Selector maps for all of the style sheets in the stylist, after evalutaing media rules against the current device, split out per cascade level.
Whether author styles are enabled.
rule_tree: RuleTree
The rule tree, that stores the results of selector matching.
script_custom_properties: ScriptRegistry
The set of registered custom properties from script. https://drafts.css-houdini.org/css-properties-values-api-1/#dom-window-registeredpropertyset-slot
initial_values_for_custom_properties: ComputedCustomProperties
Initial values for registered custom properties.
initial_values_for_custom_properties_flags: ComputedValueFlags
Flags set from computing registered custom property initial values.
num_rebuilds: usize
The total number of times the stylist has been rebuilt.
Implementations§
source§impl Stylist
impl Stylist
sourcepub fn new(device: Device, quirks_mode: QuirksMode) -> Self
pub fn new(device: Device, quirks_mode: QuirksMode) -> Self
Construct a new Stylist
, using given Device
and QuirksMode
.
If more members are added here, think about whether they should
be reset in clear().
sourcepub fn cascade_data(&self) -> &DocumentCascadeData
pub fn cascade_data(&self) -> &DocumentCascadeData
Returns the document cascade data.
Returns whether author styles are enabled or not.
sourcepub fn iter_origins(&self) -> DocumentCascadeDataIter<'_> ⓘ
pub fn iter_origins(&self) -> DocumentCascadeDataIter<'_> ⓘ
Iterate through all the cascade datas from the document.
Does what the name says, to prevent author_data_cache to grow without bound.
sourcepub fn get_custom_property_registration(
&self,
name: &Atom,
) -> &PropertyRegistrationData
pub fn get_custom_property_registration( &self, name: &Atom, ) -> &PropertyRegistrationData
Returns the custom property registration for this property’s name. https://drafts.css-houdini.org/css-properties-values-api-1/#determining-registration
sourcepub fn get_custom_property_initial_values(&self) -> &ComputedCustomProperties
pub fn get_custom_property_initial_values(&self) -> &ComputedCustomProperties
Returns custom properties with their registered initial values.
sourcepub fn get_custom_property_initial_values_flags(&self) -> ComputedValueFlags
pub fn get_custom_property_initial_values_flags(&self) -> ComputedValueFlags
Returns flags set from computing the registered custom property initial values.
sourcepub fn rebuild_initial_values_for_custom_properties(&mut self)
pub fn rebuild_initial_values_for_custom_properties(&mut self)
Rebuild custom properties with their registered initial values. https://drafts.css-houdini.org/css-properties-values-api-1/#determining-registration
Rebuilds (if needed) the CascadeData given a sheet collection.
sourcepub fn iter_extra_data_origins(&self) -> ExtraStyleDataIterator<'_> ⓘ
pub fn iter_extra_data_origins(&self) -> ExtraStyleDataIterator<'_> ⓘ
Iterate over the extra data in origin order.
sourcepub fn iter_extra_data_origins_rev(&self) -> ExtraStyleDataIterator<'_> ⓘ
pub fn iter_extra_data_origins_rev(&self) -> ExtraStyleDataIterator<'_> ⓘ
Iterate over the extra data in reverse origin order.
sourcepub fn num_selectors(&self) -> usize
pub fn num_selectors(&self) -> usize
Returns the number of selectors.
sourcepub fn num_declarations(&self) -> usize
pub fn num_declarations(&self) -> usize
Returns the number of declarations.
sourcepub fn num_rebuilds(&self) -> usize
pub fn num_rebuilds(&self) -> usize
Returns the number of times the stylist has been rebuilt.
sourcepub fn num_revalidation_selectors(&self) -> usize
pub fn num_revalidation_selectors(&self) -> usize
Returns the number of revalidation_selectors.
sourcepub fn num_invalidations(&self) -> usize
pub fn num_invalidations(&self) -> usize
Returns the number of entries in invalidation maps.
sourcepub fn has_document_state_dependency(&self, state: DocumentState) -> bool
pub fn has_document_state_dependency(&self, state: DocumentState) -> bool
Returns whether the given DocumentState bit is relied upon by a selector of some rule.
sourcepub fn flush<E>(
&mut self,
guards: &StylesheetGuards<'_>,
document_element: Option<E>,
snapshots: Option<&SnapshotMap>,
) -> boolwhere
E: TElement,
pub fn flush<E>(
&mut self,
guards: &StylesheetGuards<'_>,
document_element: Option<E>,
snapshots: Option<&SnapshotMap>,
) -> boolwhere
E: TElement,
Flush the list of stylesheets if they changed, ensuring the stylist is up-to-date.
sourcepub fn insert_stylesheet_before(
&mut self,
sheet: StylistSheet,
before_sheet: StylistSheet,
guard: &SharedRwLockReadGuard<'_>,
)
pub fn insert_stylesheet_before( &mut self, sheet: StylistSheet, before_sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )
Insert a given stylesheet before another stylesheet in the document.
sourcepub fn force_stylesheet_origins_dirty(&mut self, origins: OriginSet)
pub fn force_stylesheet_origins_dirty(&mut self, origins: OriginSet)
Marks a given stylesheet origin as dirty, due to, for example, changes in the declarations that affect a given rule.
FIXME(emilio): Eventually it’d be nice for this to become more fine-grained.
Sets whether author style is enabled or not.
sourcepub fn stylesheets_have_changed(&self) -> bool
pub fn stylesheets_have_changed(&self) -> bool
Returns whether we’ve recorded any stylesheet change so far.
sourcepub fn append_stylesheet(
&mut self,
sheet: StylistSheet,
guard: &SharedRwLockReadGuard<'_>,
)
pub fn append_stylesheet( &mut self, sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )
Appends a new stylesheet to the current set.
sourcepub fn remove_stylesheet(
&mut self,
sheet: StylistSheet,
guard: &SharedRwLockReadGuard<'_>,
)
pub fn remove_stylesheet( &mut self, sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )
Remove a given stylesheet to the current set.
sourcepub fn rule_changed(
&mut self,
sheet: &StylistSheet,
rule: &CssRule,
guard: &SharedRwLockReadGuard<'_>,
change_kind: RuleChangeKind,
)
pub fn rule_changed( &mut self, sheet: &StylistSheet, rule: &CssRule, guard: &SharedRwLockReadGuard<'_>, change_kind: RuleChangeKind, )
Notify of a change of a given rule.
sourcepub fn sheet_count(&self, origin: Origin) -> usize
pub fn sheet_count(&self, origin: Origin) -> usize
Appends a new stylesheet to the current set.
sourcepub fn sheet_at(&self, origin: Origin, index: usize) -> Option<&StylistSheet>
pub fn sheet_at(&self, origin: Origin, index: usize) -> Option<&StylistSheet>
Appends a new stylesheet to the current set.
sourcepub fn any_applicable_rule_data<E, F>(&self, element: E, f: F) -> bool
pub fn any_applicable_rule_data<E, F>(&self, element: E, f: F) -> bool
Returns whether for any of the applicable style rule data a given condition is true.
sourcepub fn for_each_cascade_data_with_scope<'a, E, F>(&'a self, element: E, f: F)
pub fn for_each_cascade_data_with_scope<'a, E, F>(&'a self, element: E, f: F)
Execute callback for all applicable style rule data.
sourcepub fn precomputed_values_for_pseudo<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent: Option<&ComputedValues>,
) -> Arc<ComputedValues>where
E: TElement,
pub fn precomputed_values_for_pseudo<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent: Option<&ComputedValues>,
) -> Arc<ComputedValues>where
E: TElement,
Computes the style for a given “precomputed” pseudo-element, taking the universal rules and applying them.
sourcepub fn precomputed_values_for_pseudo_with_rule_node<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent: Option<&ComputedValues>,
rules: StrongRuleNode,
) -> Arc<ComputedValues>where
E: TElement,
pub fn precomputed_values_for_pseudo_with_rule_node<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent: Option<&ComputedValues>,
rules: StrongRuleNode,
) -> Arc<ComputedValues>where
E: TElement,
Computes the style for a given “precomputed” pseudo-element with given rule node.
TODO(emilio): The type parameter could go away with a void type implementing TElement.
sourcepub fn rule_node_for_precomputed_pseudo(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
extra_declarations: Vec<ApplicableDeclarationBlock>,
) -> StrongRuleNode
pub fn rule_node_for_precomputed_pseudo( &self, guards: &StylesheetGuards<'_>, pseudo: &PseudoElement, extra_declarations: Vec<ApplicableDeclarationBlock>, ) -> StrongRuleNode
Returns the rule node for a given precomputed pseudo-element.
If we want to include extra declarations to this precomputed pseudo-element, we can provide a vector of ApplicableDeclarationBlocks to extra_declarations. This is useful for @page rules.
sourcepub fn style_for_anonymous<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent_style: &ComputedValues,
) -> Arc<ComputedValues>where
E: TElement,
pub fn style_for_anonymous<E>(
&self,
guards: &StylesheetGuards<'_>,
pseudo: &PseudoElement,
parent_style: &ComputedValues,
) -> Arc<ComputedValues>where
E: TElement,
Returns the style for an anonymous box of the given type.
TODO(emilio): The type parameter could go away with a void type implementing TElement.
sourcepub fn lazily_compute_pseudo_element_style<E>(
&self,
guards: &StylesheetGuards<'_>,
element: E,
pseudo: &PseudoElement,
rule_inclusion: RuleInclusion,
originating_element_style: &ComputedValues,
is_probe: bool,
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
) -> Option<Arc<ComputedValues>>where
E: TElement,
pub fn lazily_compute_pseudo_element_style<E>(
&self,
guards: &StylesheetGuards<'_>,
element: E,
pseudo: &PseudoElement,
rule_inclusion: RuleInclusion,
originating_element_style: &ComputedValues,
is_probe: bool,
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
) -> Option<Arc<ComputedValues>>where
E: TElement,
Computes a pseudo-element style lazily during layout.
This can only be done for a certain set of pseudo-elements, like :selection.
Check the documentation on lazy pseudo-elements in docs/components/style.md
sourcepub fn compute_pseudo_element_style_with_inputs<E>(
&self,
inputs: CascadeInputs,
pseudo: &PseudoElement,
guards: &StylesheetGuards<'_>,
parent_style: Option<&ComputedValues>,
element: Option<E>,
) -> Arc<ComputedValues>where
E: TElement,
pub fn compute_pseudo_element_style_with_inputs<E>(
&self,
inputs: CascadeInputs,
pseudo: &PseudoElement,
guards: &StylesheetGuards<'_>,
parent_style: Option<&ComputedValues>,
element: Option<E>,
) -> Arc<ComputedValues>where
E: TElement,
Computes a pseudo-element style lazily using the given CascadeInputs. This can be used for truly lazy pseudo-elements or to avoid redoing selector matching for eager pseudo-elements when we need to recompute their style with a new parent style.
sourcepub fn cascade_style_and_visited<E>(
&self,
element: Option<E>,
pseudo: Option<&PseudoElement>,
inputs: CascadeInputs,
guards: &StylesheetGuards<'_>,
parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
first_line_reparenting: FirstLineReparenting<'_>,
rule_cache: Option<&RuleCache>,
rule_cache_conditions: &mut RuleCacheConditions,
) -> Arc<ComputedValues>where
E: TElement,
pub fn cascade_style_and_visited<E>(
&self,
element: Option<E>,
pseudo: Option<&PseudoElement>,
inputs: CascadeInputs,
guards: &StylesheetGuards<'_>,
parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
first_line_reparenting: FirstLineReparenting<'_>,
rule_cache: Option<&RuleCache>,
rule_cache_conditions: &mut RuleCacheConditions,
) -> Arc<ComputedValues>where
E: TElement,
Computes a style using the given CascadeInputs. This can be used to compute a style any time we know what rules apply and just need to use the given parent styles.
parent_style is the style to inherit from for properties affected by first-line ancestors.
parent_style_ignoring_first_line is the style to inherit from for properties not affected by first-line ancestors.
layout_parent_style is the style used for some property fixups. It’s the style of the nearest ancestor with a layout box.
sourcefn lazy_pseudo_rules<E>(
&self,
guards: &StylesheetGuards<'_>,
element: E,
originating_element_style: &ComputedValues,
pseudo: &PseudoElement,
is_probe: bool,
rule_inclusion: RuleInclusion,
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
) -> Option<CascadeInputs>where
E: TElement,
fn lazy_pseudo_rules<E>(
&self,
guards: &StylesheetGuards<'_>,
element: E,
originating_element_style: &ComputedValues,
pseudo: &PseudoElement,
is_probe: bool,
rule_inclusion: RuleInclusion,
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
) -> Option<CascadeInputs>where
E: TElement,
Computes the cascade inputs for a lazily-cascaded pseudo-element.
See the documentation on lazy pseudo-elements in docs/components/style.md
sourcepub fn set_device(
&mut self,
device: Device,
guards: &StylesheetGuards<'_>,
) -> OriginSet
pub fn set_device( &mut self, device: Device, guards: &StylesheetGuards<'_>, ) -> OriginSet
Set a given device, which may change the styles that apply to the document.
Returns the sheet origins that were actually affected.
This means that we may need to rebuild style data even if the stylesheets haven’t changed.
Also, the device that arrives here may need to take the viewport rules into account.
sourcepub fn media_features_change_changed_style(
&self,
guards: &StylesheetGuards<'_>,
device: &Device,
) -> OriginSet
pub fn media_features_change_changed_style( &self, guards: &StylesheetGuards<'_>, device: &Device, ) -> OriginSet
Returns whether, given a media feature change, any previously-applicable
style has become non-applicable, or vice-versa for each origin, using
device
.
sourcepub fn quirks_mode(&self) -> QuirksMode
pub fn quirks_mode(&self) -> QuirksMode
Returns the Quirks Mode of the document.
sourcepub fn set_quirks_mode(&mut self, quirks_mode: QuirksMode)
pub fn set_quirks_mode(&mut self, quirks_mode: QuirksMode)
Sets the quirks mode of the document.
sourcepub fn push_applicable_declarations<E>(
&self,
element: E,
pseudo_element: Option<&PseudoElement>,
style_attribute: Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>,
animation_declarations: AnimationDeclarations,
rule_inclusion: RuleInclusion,
applicable_declarations: &mut ApplicableDeclarationList,
context: &mut MatchingContext<'_, E::Impl>,
)where
E: TElement,
pub fn push_applicable_declarations<E>(
&self,
element: E,
pseudo_element: Option<&PseudoElement>,
style_attribute: Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>,
animation_declarations: AnimationDeclarations,
rule_inclusion: RuleInclusion,
applicable_declarations: &mut ApplicableDeclarationList,
context: &mut MatchingContext<'_, E::Impl>,
)where
E: TElement,
Returns the applicable CSS declarations for the given element.
sourcepub fn may_have_rules_for_id<E>(&self, id: &WeakAtom, element: E) -> boolwhere
E: TElement,
pub fn may_have_rules_for_id<E>(&self, id: &WeakAtom, element: E) -> boolwhere
E: TElement,
Given an id, returns whether there might be any rules for that id in any of our rule maps.
sourcepub fn get_animation<'a, E>(
&'a self,
name: &Atom,
element: E,
) -> Option<&'a KeyframesAnimation>where
E: TElement + 'a,
pub fn get_animation<'a, E>(
&'a self,
name: &Atom,
element: E,
) -> Option<&'a KeyframesAnimation>where
E: TElement + 'a,
Returns the registered @keyframes
animation for the specified name.
sourcepub fn match_revalidation_selectors<E>(
&self,
element: E,
bloom: Option<&BloomFilter>,
selector_caches: &mut SelectorCaches,
needs_selector_flags: NeedsSelectorFlags,
) -> RevalidationResultwhere
E: TElement,
pub fn match_revalidation_selectors<E>(
&self,
element: E,
bloom: Option<&BloomFilter>,
selector_caches: &mut SelectorCaches,
needs_selector_flags: NeedsSelectorFlags,
) -> RevalidationResultwhere
E: TElement,
Computes the match results of a given element against the set of revalidation selectors.
sourcepub fn revalidate_scopes<E: TElement>(
&self,
element: &E,
selector_caches: &mut SelectorCaches,
needs_selector_flags: NeedsSelectorFlags,
) -> ScopeRevalidationResult
pub fn revalidate_scopes<E: TElement>( &self, element: &E, selector_caches: &mut SelectorCaches, needs_selector_flags: NeedsSelectorFlags, ) -> ScopeRevalidationResult
Computes currently active scopes for the given element for revalidation purposes.
sourcepub fn compute_for_declarations<E>(
&self,
guards: &StylesheetGuards<'_>,
parent_style: &ComputedValues,
declarations: Arc<Locked<PropertyDeclarationBlock>>,
) -> Arc<ComputedValues>where
E: TElement,
pub fn compute_for_declarations<E>(
&self,
guards: &StylesheetGuards<'_>,
parent_style: &ComputedValues,
declarations: Arc<Locked<PropertyDeclarationBlock>>,
) -> Arc<ComputedValues>where
E: TElement,
Computes styles for a given declaration with parent_style.
FIXME(emilio): the lack of pseudo / cascade flags look quite dubious, hopefully this is only used for some canvas font stuff.
TODO(emilio): The type parameter can go away when https://github.com/rust-lang/rust/issues/35121 is fixed.
sourcepub fn device_mut(&mut self) -> &mut Device
pub fn device_mut(&mut self) -> &mut Device
Accessor for a mutable reference to the device.
sourcepub fn custom_property_script_registry(&self) -> &CustomPropertyScriptRegistry
pub fn custom_property_script_registry(&self) -> &CustomPropertyScriptRegistry
Returns the script-registered custom property registry.
sourcepub fn custom_property_script_registry_mut(
&mut self,
) -> &mut CustomPropertyScriptRegistry
pub fn custom_property_script_registry_mut( &mut self, ) -> &mut CustomPropertyScriptRegistry
Returns the script-registered custom property registry, as a mutable ref.
Trait Implementations§
source§impl MallocSizeOf for Stylist
impl MallocSizeOf for Stylist
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !Freeze for Stylist
impl !RefUnwindSafe for Stylist
impl !Send for Stylist
impl Sync for Stylist
impl Unpin for Stylist
impl !UnwindSafe for Stylist
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more