From 0399f359c17565080b777dac8a8ab8e6356cc316 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 6 Jan 2017 21:18:24 +1100 Subject: [PATCH] Add NonTSPseudoClass::is_internal function --- components/style/gecko/selector_parser.rs | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 1c02ed98d28..17650406cb1 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -178,6 +178,27 @@ impl ToCss for NonTSPseudoClass { } impl NonTSPseudoClass { + /// A pseudo-class is internal if it can only be used inside + /// user agent style sheets. + pub fn is_internal(&self) -> bool { + use self::NonTSPseudoClass::*; + match *self { + AnyLink | + Link | + Visited | + Active | + Focus | + Fullscreen | + Hover | + Enabled | + Disabled | + Checked | + Indeterminate | + ReadWrite | + ReadOnly => false, + } + } + /// Get the state flag associated with a pseudo-class, if any. pub fn state_flag(&self) -> ElementState { use element_state::*; @@ -269,7 +290,11 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> { _ => return Err(()) }; - Ok(pseudo_class) + if !pseudo_class.is_internal() || self.in_user_agent_stylesheet() { + Ok(pseudo_class) + } else { + Err(()) + } } fn parse_pseudo_element(&self, name: Cow) -> Result {