mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
style: Store ::slotted rules separately on the cascade data, since they may cross the shadow boundary.
MozReview-Commit-ID: EY9nK3169vv
This commit is contained in:
parent
b26f3280d2
commit
5115cbd1c0
4 changed files with 161 additions and 51 deletions
|
@ -98,13 +98,21 @@ impl<Impl: SelectorImpl> SelectorBuilder<Impl> {
|
|||
|
||||
/// Consumes the builder, producing a Selector.
|
||||
#[inline(always)]
|
||||
pub fn build(&mut self, parsed_pseudo: bool) -> ThinArc<SpecificityAndFlags, Component<Impl>> {
|
||||
pub fn build(
|
||||
&mut self,
|
||||
parsed_pseudo: bool,
|
||||
parsed_slotted: bool,
|
||||
) -> ThinArc<SpecificityAndFlags, Component<Impl>> {
|
||||
// Compute the specificity and flags.
|
||||
let mut spec = SpecificityAndFlags(specificity(self.simple_selectors.iter()));
|
||||
if parsed_pseudo {
|
||||
spec.0 |= HAS_PSEUDO_BIT;
|
||||
}
|
||||
|
||||
if parsed_slotted {
|
||||
spec.0 |= HAS_SLOTTED_BIT;
|
||||
}
|
||||
|
||||
self.build_with_specificity_and_flags(spec)
|
||||
}
|
||||
|
||||
|
@ -188,18 +196,28 @@ fn split_from_end<T>(s: &[T], at: usize) -> (&[T], &[T]) {
|
|||
}
|
||||
|
||||
pub const HAS_PSEUDO_BIT: u32 = 1 << 30;
|
||||
pub const HAS_SLOTTED_BIT: u32 = 1 << 31;
|
||||
|
||||
/// We use ten bits for each specificity kind (id, class, element), and the two
|
||||
/// high bits for the pseudo and slotted flags.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct SpecificityAndFlags(pub u32);
|
||||
|
||||
impl SpecificityAndFlags {
|
||||
#[inline]
|
||||
pub fn specificity(&self) -> u32 {
|
||||
self.0 & !HAS_PSEUDO_BIT
|
||||
self.0 & !(HAS_PSEUDO_BIT | HAS_SLOTTED_BIT)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_pseudo_element(&self) -> bool {
|
||||
(self.0 & HAS_PSEUDO_BIT) != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_slotted(&self) -> bool {
|
||||
(self.0 & HAS_SLOTTED_BIT) != 0
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_10BIT: u32 = (1u32 << 10) - 1;
|
||||
|
|
|
@ -445,14 +445,22 @@ pub fn namespace_empty_string<Impl: SelectorImpl>() -> Impl::NamespaceUrl {
|
|||
pub struct Selector<Impl: SelectorImpl>(ThinArc<SpecificityAndFlags, Component<Impl>>);
|
||||
|
||||
impl<Impl: SelectorImpl> Selector<Impl> {
|
||||
#[inline]
|
||||
pub fn specificity(&self) -> u32 {
|
||||
self.0.header.header.specificity()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_pseudo_element(&self) -> bool {
|
||||
self.0.header.header.has_pseudo_element()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_slotted(&self) -> bool {
|
||||
self.0.header.header.is_slotted()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn pseudo_element(&self) -> Option<&Impl::PseudoElement> {
|
||||
if !self.has_pseudo_element() {
|
||||
return None
|
||||
|
@ -1219,7 +1227,7 @@ where
|
|||
builder.push_combinator(combinator);
|
||||
}
|
||||
|
||||
Ok(Selector(builder.build(has_pseudo_element)))
|
||||
Ok(Selector(builder.build(has_pseudo_element, slotted)))
|
||||
}
|
||||
|
||||
impl<Impl: SelectorImpl> Selector<Impl> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue