From 6143e95d74066154d8237aec326642abe3b0b239 Mon Sep 17 00:00:00 2001 From: cku Date: Tue, 23 May 2017 23:51:20 +0800 Subject: [PATCH] Stylo: match both ::placehoder & ::moz-placeholder for placeholder pseudo-elements. --- components/style/gecko/pseudo_element.rs | 9 +++++++++ components/style/gecko/wrapper.rs | 2 +- components/style/matching.rs | 2 ++ components/style/servo/selector_parser.rs | 6 ++++++ components/style/stylist.rs | 7 ++++--- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/style/gecko/pseudo_element.rs b/components/style/gecko/pseudo_element.rs index 93da2b589d0..8d60781e027 100644 --- a/components/style/gecko/pseudo_element.rs +++ b/components/style/gecko/pseudo_element.rs @@ -102,6 +102,15 @@ impl PseudoElement { pub fn is_precomputed(&self) -> bool { self.is_anon_box() } + + /// Covert non-canonical pseudo-element to canonical one, and keep a + /// canonical one as it is. + pub fn canonical(&self) -> PseudoElement { + match *self { + PseudoElement::MozPlaceholder => PseudoElement::Placeholder, + _ => self.clone(), + } + } } impl ToCss for PseudoElement { diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index e043ff57223..07631f7824a 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1368,7 +1368,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { // match the proper pseudo-element, given how we rulehash the stuff // based on the pseudo. match self.implemented_pseudo_element() { - Some(ref pseudo) => pseudo == pseudo_element, + Some(ref pseudo) => *pseudo == pseudo_element.canonical(), None => false, } } diff --git a/components/style/matching.rs b/components/style/matching.rs index e0a8e4ec755..ecc62cf145b 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -684,6 +684,8 @@ pub trait MatchMethods : TElement { { let implemented_pseudo = self.implemented_pseudo_element(); if let Some(ref pseudo) = implemented_pseudo { + // We don't expect to match against a non-canonical pseudo-element. + debug_assert_eq!(*pseudo, pseudo.canonical()); if pseudo.is_eager() { // If it's an eager element-backed pseudo, just grab the matched // rules from the parent, and update animations. diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index fdc14b11e29..1cae314ddec 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -152,6 +152,12 @@ impl PseudoElement { PseudoElement::ServoInlineAbsolute => PseudoElementCascadeType::Precomputed, } } + + /// Covert non-canonical pseudo-element to canonical one, and keep a + /// canonical one as it is. + pub fn canonical(&self) -> PseudoElement { + self.clone() + } } /// A non tree-structural pseudo-class. diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 3189defd7b1..e80f40b3d19 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -477,7 +477,7 @@ impl Stylist { { let map = if let Some(pseudo) = selector.pseudo_element() { self.pseudos_map - .entry(pseudo.clone()) + .entry(pseudo.canonical()) .or_insert_with(PerPseudoElementSelectorMap::new) .borrow_for_origin(&stylesheet.origin) } else { @@ -669,8 +669,9 @@ impl Stylist { -> Option where E: TElement { + let pseudo = pseudo.canonical(); debug_assert!(pseudo.is_lazy()); - if self.pseudos_map.get(pseudo).is_none() { + if self.pseudos_map.get(&pseudo).is_none() { return None } @@ -702,7 +703,7 @@ impl Stylist { let mut matching_context = MatchingContext::new(MatchingMode::ForStatelessPseudoElement, None); self.push_applicable_declarations(element, - Some(pseudo), + Some(&pseudo), None, None, AnimationRules(None, None),