Struct style::stylist::Stylist

source ·
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 Rules and sorted into SelectorMaps 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.

§author_data_cache: CascadeDataCache<CascadeData>

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.

§author_styles_enabled: AuthorStylesEnabled

Whether author styles are enabled.

§rule_tree: RuleTree

The rule tree, that stores the results of selector matching.

§script_custom_properties: ScriptRegistry§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

source

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().

source

pub fn cascade_data(&self) -> &DocumentCascadeData

Returns the document cascade data.

source

pub fn author_styles_enabled(&self) -> AuthorStylesEnabled

Returns whether author styles are enabled or not.

source

pub fn iter_origins(&self) -> DocumentCascadeDataIter<'_>

Iterate through all the cascade datas from the document.

source

pub fn remove_unique_author_data_cache_entries(&mut self)

Does what the name says, to prevent author_data_cache to grow without bound.

source

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

source

pub fn get_custom_property_initial_values(&self) -> &ComputedCustomProperties

Returns custom properties with their registered initial values.

source

pub fn get_custom_property_initial_values_flags(&self) -> ComputedValueFlags

Returns flags set from computing the registered custom property initial values.

source

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

source

pub fn rebuild_author_data<S>( &mut self, old_data: &CascadeData, collection: SheetCollectionFlusher<'_, S>, guard: &SharedRwLockReadGuard<'_>, ) -> Result<Option<Arc<CascadeData>>, AllocErr>
where S: StylesheetInDocument + PartialEq + 'static,

Rebuilds (if needed) the CascadeData given a sheet collection.

source

pub fn iter_extra_data_origins(&self) -> ExtraStyleDataIterator<'_>

Iterate over the extra data in origin order.

source

pub fn iter_extra_data_origins_rev(&self) -> ExtraStyleDataIterator<'_>

Iterate over the extra data in reverse origin order.

source

pub fn num_selectors(&self) -> usize

Returns the number of selectors.

source

pub fn num_declarations(&self) -> usize

Returns the number of declarations.

source

pub fn num_rebuilds(&self) -> usize

Returns the number of times the stylist has been rebuilt.

source

pub fn num_revalidation_selectors(&self) -> usize

Returns the number of revalidation_selectors.

source

pub fn num_invalidations(&self) -> usize

Returns the number of entries in invalidation maps.

source

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.

source

pub fn flush<E>( &mut self, guards: &StylesheetGuards<'_>, document_element: Option<E>, snapshots: Option<&SnapshotMap>, ) -> bool
where E: TElement,

Flush the list of stylesheets if they changed, ensuring the stylist is up-to-date.

source

pub fn insert_stylesheet_before( &mut self, sheet: StylistSheet, before_sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )

Insert a given stylesheet before another stylesheet in the document.

source

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.

source

pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled)

Sets whether author style is enabled or not.

source

pub fn stylesheets_have_changed(&self) -> bool

Returns whether we’ve recorded any stylesheet change so far.

source

pub fn append_stylesheet( &mut self, sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )

Appends a new stylesheet to the current set.

source

pub fn remove_stylesheet( &mut self, sheet: StylistSheet, guard: &SharedRwLockReadGuard<'_>, )

Remove a given stylesheet to the current set.

source

pub fn rule_changed( &mut self, sheet: &StylistSheet, rule: &CssRule, guard: &SharedRwLockReadGuard<'_>, change_kind: RuleChangeKind, )

Notify of a change of a given rule.

source

pub fn sheet_count(&self, origin: Origin) -> usize

Appends a new stylesheet to the current set.

source

pub fn sheet_at(&self, origin: Origin, index: usize) -> Option<&StylistSheet>

Appends a new stylesheet to the current set.

source

pub fn any_applicable_rule_data<E, F>(&self, element: E, f: F) -> bool
where E: TElement, F: FnMut(&CascadeData) -> bool,

Returns whether for any of the applicable style rule data a given condition is true.

source

pub fn for_each_cascade_data_with_scope<'a, E, F>(&'a self, element: E, f: F)
where E: TElement + 'a, F: FnMut(&'a CascadeData, Option<E>),

Execute callback for all applicable style rule data.

source

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.

source

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.

source

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.

source

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.

source

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

source

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.

source

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.

source

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

source

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.

source

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.

source

pub fn quirks_mode(&self) -> QuirksMode

Returns the Quirks Mode of the document.

source

pub fn set_quirks_mode(&mut self, quirks_mode: QuirksMode)

Sets the quirks mode of the document.

source

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.

source

pub fn may_have_rules_for_id<E>(&self, id: &WeakAtom, element: E) -> bool
where E: TElement,

Given an id, returns whether there might be any rules for that id in any of our rule maps.

source

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.

source

pub fn match_revalidation_selectors<E>( &self, element: E, bloom: Option<&BloomFilter>, selector_caches: &mut SelectorCaches, needs_selector_flags: NeedsSelectorFlags, ) -> RevalidationResult
where E: TElement,

Computes the match results of a given element against the set of revalidation selectors.

source

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.

source

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.

source

pub fn device(&self) -> &Device

Accessor for a shared reference to the device.

source

pub fn device_mut(&mut self) -> &mut Device

Accessor for a mutable reference to the device.

source

pub fn rule_tree(&self) -> &RuleTree

Accessor for a shared reference to the rule tree.

source

pub fn custom_property_script_registry(&self) -> &CustomPropertyScriptRegistry

Returns the script-registered custom property registry.

source

pub fn custom_property_script_registry_mut( &mut self, ) -> &mut CustomPropertyScriptRegistry

Returns the script-registered custom property registry, as a mutable ref.

source

pub fn shutdown()

Shutdown the static data that this module stores.

Trait Implementations§

source§

impl MallocSizeOf for Stylist

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> MaybeBoxed<Box<T>> for T

source§

fn maybe_boxed(self) -> Box<T>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T