diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index db64b18599e..9e753e054b6 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2600,7 +2600,7 @@ pub struct StyleBuilder<'a> { custom_properties: Option>, /// The pseudo-element this style will represent. - pseudo: Option<<&'a PseudoElement>, + pub pseudo: Option<<&'a PseudoElement>, /// Whether we have mutated any reset structs since the the last time /// `clear_modified_reset` was called. This is used to tell whether the diff --git a/components/style/rule_cache.rs b/components/style/rule_cache.rs index 511c7301fba..7862414f530 100644 --- a/components/style/rule_cache.rs +++ b/components/style/rule_cache.rs @@ -9,6 +9,7 @@ use fnv::FnvHashMap; use logical_geometry::WritingMode; use properties::{ComputedValues, StyleBuilder}; use rule_tree::StrongRuleNode; +use selector_parser::PseudoElement; use servo_arc::Arc; use smallvec::SmallVec; use values::computed::NonNegativeLength; @@ -93,6 +94,14 @@ impl RuleCache { return None; } + // A pseudo-element with property restrictions can result in different + // computed values if it's also used for a non-pseudo. + if builder_with_early_props.pseudo + .and_then(|p| p.property_restriction()) + .is_some() { + return None; + } + let rules = match builder_with_early_props.rules { Some(ref rules) => rules, None => return None, @@ -115,6 +124,7 @@ impl RuleCache { pub fn insert_if_possible( &mut self, style: &Arc, + pseudo: Option<&PseudoElement>, conditions: &RuleCacheConditions, ) -> bool { if !conditions.cacheable() { @@ -126,6 +136,12 @@ impl RuleCache { return false; } + // A pseudo-element with property restrictions can result in different + // computed values if it's also used for a non-pseudo. + if pseudo.and_then(|p| p.property_restriction()).is_some() { + return false; + } + let rules = match style.rules { Some(ref r) => r.clone(), None => return false, diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index 8830fd1a45a..1a993e15662 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -574,11 +574,13 @@ where } let implemented_pseudo = self.element.implemented_pseudo_element(); + let pseudo = pseudo.or(implemented_pseudo.as_ref()); + let mut conditions = Default::default(); let values = cascade( self.context.shared.stylist.device(), - pseudo.or(implemented_pseudo.as_ref()), + pseudo, rules.unwrap_or(self.context.shared.stylist.rule_tree().root()), &self.context.shared.guards, parent_style, @@ -595,7 +597,7 @@ where self.context .thread_local .rule_cache - .insert_if_possible(&values, &conditions); + .insert_if_possible(&values, pseudo, &conditions); values }