aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko/selector_parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style/gecko/selector_parser.rs')
-rw-r--r--components/style/gecko/selector_parser.rs92
1 files changed, 5 insertions, 87 deletions
diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs
index 22abaf63b67..787ecd5b2cb 100644
--- a/components/style/gecko/selector_parser.rs
+++ b/components/style/gecko/selector_parser.rs
@@ -5,7 +5,6 @@
//! Gecko-specific bits for selector-parsing.
use cssparser::{Parser, ToCss};
-use element_state::{IN_ACTIVE_STATE, IN_FOCUS_STATE, IN_HOVER_STATE};
use element_state::ElementState;
use gecko_bindings::structs::CSSPseudoClassType;
use selector_parser::{SelectorParser, PseudoElementCascadeType};
@@ -132,7 +131,7 @@ impl NonTSPseudoClass {
/// https://drafts.csswg.org/selectors-4/#useraction-pseudos
///
/// We intentionally skip the link-related ones.
- fn is_safe_user_action_state(&self) -> bool {
+ pub fn is_safe_user_action_state(&self) -> bool {
matches!(*self, NonTSPseudoClass::Hover |
NonTSPseudoClass::Active |
NonTSPseudoClass::Focus)
@@ -195,58 +194,6 @@ impl NonTSPseudoClass {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SelectorImpl;
-/// Some subset of pseudo-elements in Gecko are sensitive to some state
-/// selectors.
-///
-/// We store the sensitive states in this struct in order to properly handle
-/// these.
-#[derive(Clone, Debug, PartialEq, Eq, Hash)]
-pub struct PseudoElementSelector {
- pseudo: PseudoElement,
- state: ElementState,
-}
-
-impl PseudoElementSelector {
- /// Returns the pseudo-element this selector represents.
- pub fn pseudo_element(&self) -> &PseudoElement {
- &self.pseudo
- }
-
- /// Returns the pseudo-element selector state.
- pub fn state(&self) -> ElementState {
- self.state
- }
-}
-
-impl ToCss for PseudoElementSelector {
- fn to_css<W>(&self, dest: &mut W) -> fmt::Result
- where W: fmt::Write,
- {
- if cfg!(debug_assertions) {
- let mut state = self.state;
- state.remove(IN_HOVER_STATE | IN_ACTIVE_STATE | IN_FOCUS_STATE);
- assert_eq!(state, ElementState::empty(),
- "Unhandled pseudo-element state selector?");
- }
-
- self.pseudo.to_css(dest)?;
-
- if self.state.contains(IN_HOVER_STATE) {
- dest.write_str(":hover")?
- }
-
- if self.state.contains(IN_ACTIVE_STATE) {
- dest.write_str(":active")?
- }
-
- if self.state.contains(IN_FOCUS_STATE) {
- dest.write_str(":focus")?
- }
-
- Ok(())
- }
-}
-
impl ::selectors::SelectorImpl for SelectorImpl {
type AttrValue = Atom;
type Identifier = Atom;
@@ -257,7 +204,7 @@ impl ::selectors::SelectorImpl for SelectorImpl {
type BorrowedNamespaceUrl = WeakNamespace;
type BorrowedLocalName = WeakAtom;
- type PseudoElementSelector = PseudoElementSelector;
+ type PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass;
}
@@ -319,38 +266,9 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
}
}
- fn parse_pseudo_element(&self, name: Cow<str>, input: &mut Parser) -> Result<PseudoElementSelector, ()> {
- let pseudo =
- match PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) {
- Some(pseudo) => pseudo,
- None => return Err(()),
- };
-
- let state = if pseudo.supports_user_action_state() {
- input.try(|input| {
- let mut state = ElementState::empty();
-
- while !input.is_exhausted() {
- input.expect_colon()?;
- let ident = input.expect_ident()?;
- let pseudo_class = self.parse_non_ts_pseudo_class(ident)?;
-
- if !pseudo_class.is_safe_user_action_state() {
- return Err(())
- }
- state.insert(pseudo_class.state_flag());
- }
-
- Ok(state)
- }).ok()
- } else {
- None
- };
-
- Ok(PseudoElementSelector {
- pseudo: pseudo,
- state: state.unwrap_or(ElementState::empty()),
- })
+ fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {
+ PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
+ .ok_or(())
}
fn default_namespace(&self) -> Option<Namespace> {