mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: Make pseudo-elements work with :host.
Imported WebKit's test as a WPT. Bug: 1465291 Reviewed-by: xidorn MozReview-Commit-ID: 19ZThuoqKLW
This commit is contained in:
parent
8d069d127a
commit
8821ad72f4
2 changed files with 35 additions and 28 deletions
|
@ -544,10 +544,26 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
}
|
||||
|
||||
/// Whether this selector is a featureless :host selector, with no
|
||||
/// combinators to the left.
|
||||
/// combinators to the left, and optionally has a pseudo-element to the
|
||||
/// right.
|
||||
#[inline]
|
||||
pub fn is_featureless_host_selector(&self) -> bool {
|
||||
self.iter().is_featureless_host_selector()
|
||||
pub fn is_featureless_host_selector_or_pseudo_element(&self) -> bool {
|
||||
let mut iter = self.iter();
|
||||
if !self.has_pseudo_element() {
|
||||
return iter.is_featureless_host_selector();
|
||||
}
|
||||
|
||||
// Skip the pseudo-element.
|
||||
for _ in &mut iter { }
|
||||
|
||||
match iter.next_sequence() {
|
||||
None => return false,
|
||||
Some(combinator) => {
|
||||
debug_assert_eq!(combinator, Combinator::PseudoElement);
|
||||
}
|
||||
}
|
||||
|
||||
iter.is_featureless_host_selector()
|
||||
}
|
||||
|
||||
/// Returns an iterator over this selector in matching order (right-to-left),
|
||||
|
|
|
@ -1951,14 +1951,9 @@ pub struct CascadeData {
|
|||
/// cascade level.
|
||||
normal_rules: ElementAndPseudoRules,
|
||||
|
||||
/// The `:host` pseudo rules that are the rightmost selector.
|
||||
///
|
||||
/// Note that as of right now these can't affect invalidation in any way,
|
||||
/// until we support the :host(<selector>) notation.
|
||||
///
|
||||
/// Also, note that other engines don't accept stuff like :host::before /
|
||||
/// :host::after, so we don't need to store pseudo rules at all.
|
||||
host_rules: Option<Box<SelectorMap<Rule>>>,
|
||||
/// The `:host` pseudo rules that are the rightmost selector (without
|
||||
/// accounting for pseudo-elements).
|
||||
host_rules: Option<Box<ElementAndPseudoRules>>,
|
||||
|
||||
/// The data coming from ::slotted() pseudo-element rules.
|
||||
///
|
||||
|
@ -2122,11 +2117,7 @@ impl CascadeData {
|
|||
|
||||
#[inline]
|
||||
fn host_rules(&self, pseudo: Option<&PseudoElement>) -> Option<&SelectorMap<Rule>> {
|
||||
if pseudo.is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.host_rules.as_ref().map(|rules| &**rules)
|
||||
self.host_rules.as_ref().and_then(|d| d.rules(pseudo))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -2258,12 +2249,13 @@ impl CascadeData {
|
|||
}
|
||||
}
|
||||
|
||||
if selector.is_featureless_host_selector() {
|
||||
let host_rules = self.host_rules
|
||||
.get_or_insert_with(|| Box::new(Default::default()));
|
||||
host_rules.insert(rule, quirks_mode)?;
|
||||
} else {
|
||||
let rules = if selector.is_slotted() {
|
||||
// NOTE(emilio): It's fine to look at :host and then at
|
||||
// ::slotted(..), since :host::slotted(..) could never
|
||||
// possibly match, as <slot> is not a valid shadow host.
|
||||
let rules = if selector.is_featureless_host_selector_or_pseudo_element() {
|
||||
self.host_rules
|
||||
.get_or_insert_with(|| Box::new(Default::default()))
|
||||
} else if selector.is_slotted() {
|
||||
self.slotted_rules
|
||||
.get_or_insert_with(|| Box::new(Default::default()))
|
||||
} else {
|
||||
|
@ -2272,7 +2264,6 @@ impl CascadeData {
|
|||
|
||||
rules.insert(rule, pseudo_element, quirks_mode)?;
|
||||
}
|
||||
}
|
||||
self.rules_source_order += 1;
|
||||
},
|
||||
CssRule::Import(ref lock) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue