Stylo: match both ::placehoder & ::moz-placeholder for placeholder pseudo-elements.

This commit is contained in:
cku 2017-05-23 23:51:20 +08:00
parent 84c1f904cb
commit 6143e95d74
5 changed files with 22 additions and 4 deletions

View file

@ -102,6 +102,15 @@ impl PseudoElement {
pub fn is_precomputed(&self) -> bool { pub fn is_precomputed(&self) -> bool {
self.is_anon_box() 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 { impl ToCss for PseudoElement {

View file

@ -1368,7 +1368,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
// match the proper pseudo-element, given how we rulehash the stuff // match the proper pseudo-element, given how we rulehash the stuff
// based on the pseudo. // based on the pseudo.
match self.implemented_pseudo_element() { match self.implemented_pseudo_element() {
Some(ref pseudo) => pseudo == pseudo_element, Some(ref pseudo) => *pseudo == pseudo_element.canonical(),
None => false, None => false,
} }
} }

View file

@ -684,6 +684,8 @@ pub trait MatchMethods : TElement {
{ {
let implemented_pseudo = self.implemented_pseudo_element(); let implemented_pseudo = self.implemented_pseudo_element();
if let Some(ref pseudo) = implemented_pseudo { 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 pseudo.is_eager() {
// If it's an eager element-backed pseudo, just grab the matched // If it's an eager element-backed pseudo, just grab the matched
// rules from the parent, and update animations. // rules from the parent, and update animations.

View file

@ -152,6 +152,12 @@ impl PseudoElement {
PseudoElement::ServoInlineAbsolute => PseudoElementCascadeType::Precomputed, 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. /// A non tree-structural pseudo-class.

View file

@ -477,7 +477,7 @@ impl Stylist {
{ {
let map = if let Some(pseudo) = selector.pseudo_element() { let map = if let Some(pseudo) = selector.pseudo_element() {
self.pseudos_map self.pseudos_map
.entry(pseudo.clone()) .entry(pseudo.canonical())
.or_insert_with(PerPseudoElementSelectorMap::new) .or_insert_with(PerPseudoElementSelectorMap::new)
.borrow_for_origin(&stylesheet.origin) .borrow_for_origin(&stylesheet.origin)
} else { } else {
@ -669,8 +669,9 @@ impl Stylist {
-> Option<StrongRuleNode> -> Option<StrongRuleNode>
where E: TElement where E: TElement
{ {
let pseudo = pseudo.canonical();
debug_assert!(pseudo.is_lazy()); debug_assert!(pseudo.is_lazy());
if self.pseudos_map.get(pseudo).is_none() { if self.pseudos_map.get(&pseudo).is_none() {
return None return None
} }
@ -702,7 +703,7 @@ impl Stylist {
let mut matching_context = let mut matching_context =
MatchingContext::new(MatchingMode::ForStatelessPseudoElement, None); MatchingContext::new(MatchingMode::ForStatelessPseudoElement, None);
self.push_applicable_declarations(element, self.push_applicable_declarations(element,
Some(pseudo), Some(&pseudo),
None, None,
None, None,
AnimationRules(None, None), AnimationRules(None, None),