Struct style::selector_map::SelectorMap
source · pub struct SelectorMap<T: 'static> {
pub root: SmallVec<[T; 1]>,
pub id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
pub class_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>,
pub local_name_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>,
pub attribute_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>,
pub namespace_hash: PrecomputedHashMap<Namespace, SmallVec<[T; 1]>>,
pub rare_pseudo_classes: SmallVec<[T; 1]>,
pub other: SmallVec<[T; 1]>,
pub count: usize,
}
Expand description
Map element data to selector-providing objects for which the last simple selector starts with them.
e.g., “p > img” would go into the set of selectors corresponding to the element “img” “a .foo .bar.baz” would go into the set of selectors corresponding to the class “bar”
Because we match selectors right-to-left (i.e., moving up the tree from an element), we need to compare the last simple selector in the selector with the element.
So, if an element has ID “id1” and classes “foo” and “bar”, then all the rules it matches will have their last simple selector starting either with “#id1” or with “.foo” or with “.bar”.
Hence, the union of the rules keyed on each of element’s classes, ID, element name, etc. will contain the Selectors that actually match that element.
We use a 1-entry SmallVec to avoid a separate heap allocation in the case where we only have one entry, which is quite common. See measurements in:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1363789#c5
- https://bugzilla.mozilla.org/show_bug.cgi?id=681755
TODO: Tune the initial capacity of the HashMap
Fields§
§root: SmallVec<[T; 1]>
Rules that have :root
selectors.
id_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>
A hash from an ID to rules which contain that ID selector.
class_hash: MaybeCaseInsensitiveHashMap<Atom, SmallVec<[T; 1]>>
A hash from a class name to rules which contain that class selector.
local_name_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>
A hash from local name to rules which contain that local name selector.
attribute_hash: PrecomputedHashMap<LocalName, SmallVec<[T; 1]>>
A hash from attributes to rules which contain that attribute selector.
namespace_hash: PrecomputedHashMap<Namespace, SmallVec<[T; 1]>>
A hash from namespace to rules which contain that namespace selector.
rare_pseudo_classes: SmallVec<[T; 1]>
Rules for pseudo-states that are rare but have global selectors.
other: SmallVec<[T; 1]>
All other rules.
count: usize
The number of entries in this map.
Implementations§
source§impl<T> SelectorMap<T>
impl<T> SelectorMap<T>
sourcepub fn shrink_if_needed(&mut self)
pub fn shrink_if_needed(&mut self)
Shrink the capacity of the map if needed.
source§impl SelectorMap<Rule>
impl SelectorMap<Rule>
sourcepub fn get_all_matching_rules<E>(
&self,
element: E,
rule_hash_target: E,
matching_rules_list: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist,
)where
E: TElement,
pub fn get_all_matching_rules<E>(
&self,
element: E,
rule_hash_target: E,
matching_rules_list: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist,
)where
E: TElement,
Append to rule_list
all Rules in self
that match element.
Extract matching rules as per element’s ID, classes, tag name, etc.. Sort the Rules at the end to maintain cascading order.
sourcepub(crate) fn get_matching_rules<E>(
element: E,
rules: &[Rule],
matching_rules: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist,
)where
E: TElement,
pub(crate) fn get_matching_rules<E>(
element: E,
rules: &[Rule],
matching_rules: &mut ApplicableDeclarationList,
matching_context: &mut MatchingContext<'_, E::Impl>,
cascade_level: CascadeLevel,
cascade_data: &CascadeData,
stylist: &Stylist,
)where
E: TElement,
Adds rules in rules
that match element
to the matching_rules
list.
source§impl<T: SelectorMapEntry> SelectorMap<T>
impl<T: SelectorMapEntry> SelectorMap<T>
sourcepub fn insert(
&mut self,
entry: T,
quirks_mode: QuirksMode,
) -> Result<(), AllocErr>
pub fn insert( &mut self, entry: T, quirks_mode: QuirksMode, ) -> Result<(), AllocErr>
Inserts an entry into the correct bucket(s).
sourcepub fn lookup<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
relevant_attributes: Option<&mut RelevantAttributes>,
f: F,
) -> bool
pub fn lookup<'a, E, F>( &'a self, element: E, quirks_mode: QuirksMode, relevant_attributes: Option<&mut RelevantAttributes>, f: F, ) -> bool
Looks up entries by id, class, local name, namespace, and other (in order).
Each entry is passed to the callback, which returns true to continue iterating entries, or false to terminate the lookup.
Returns false if the callback ever returns false.
FIXME(bholley) This overlaps with SelectorMap
fn lookup_with_state<'a, E, F>( &'a self, element: E, element_state: ElementState, quirks_mode: QuirksMode, relevant_attributes: Option<&mut RelevantAttributes>, f: F, ) -> bool
sourcepub fn lookup_with_additional<'a, E, F>(
&'a self,
element: E,
quirks_mode: QuirksMode,
additional_id: Option<&WeakAtom>,
additional_classes: &[Atom],
additional_states: ElementState,
f: F,
) -> bool
pub fn lookup_with_additional<'a, E, F>( &'a self, element: E, quirks_mode: QuirksMode, additional_id: Option<&WeakAtom>, additional_classes: &[Atom], additional_states: ElementState, f: F, ) -> bool
Performs a normal lookup, and also looks up entries for the passed-in id and classes.
Each entry is passed to the callback, which returns true to continue iterating entries, or false to terminate the lookup.
Returns false if the callback ever returns false.
Trait Implementations§
source§impl<T: Clone + 'static> Clone for SelectorMap<T>
impl<T: Clone + 'static> Clone for SelectorMap<T>
source§fn clone(&self) -> SelectorMap<T>
fn clone(&self) -> SelectorMap<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug + 'static> Debug for SelectorMap<T>
impl<T: Debug + 'static> Debug for SelectorMap<T>
source§impl<T: 'static> Default for SelectorMap<T>
impl<T: 'static> Default for SelectorMap<T>
source§impl<T> MallocSizeOf for SelectorMap<T>where
T: MallocSizeOf + 'static,
impl<T> MallocSizeOf for SelectorMap<T>where
T: MallocSizeOf + 'static,
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl<T> Freeze for SelectorMap<T>where
T: Freeze,
impl<T> RefUnwindSafe for SelectorMap<T>where
T: RefUnwindSafe,
impl<T> Send for SelectorMap<T>where
T: Send,
impl<T> Sync for SelectorMap<T>where
T: Sync,
impl<T> Unpin for SelectorMap<T>where
T: Unpin,
impl<T> UnwindSafe for SelectorMap<T>where
T: RefUnwindSafe + UnwindSafe,
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