From b743d68ccdab72682e3a87ab0254344d8c6498ee Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 20 Oct 2017 14:08:33 +1100 Subject: [PATCH] Accept argument-less tree pseudo-element selector. --- .../generated/pseudo_element_definition.rs | 39 ++++++++++++------- .../gecko/pseudo_element_definition.mako.rs | 20 +++++++--- components/style/gecko/selector_parser.rs | 7 ++++ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/components/style/gecko/generated/pseudo_element_definition.rs b/components/style/gecko/generated/pseudo_element_definition.rs index 83bc1f575c6..2c3e51d703e 100644 --- a/components/style/gecko/generated/pseudo_element_definition.rs +++ b/components/style/gecko/generated/pseudo_element_definition.rs @@ -871,6 +871,26 @@ None (self.atom().as_ptr(), self.pseudo_type()) } + /// Get the argument list of a tree pseudo-element. + #[inline] + pub fn tree_pseudo_args(&self) -> Option<&[Atom]> { + match *self { + PseudoElement::MozTreeColumn(ref args) => Some(args), + PseudoElement::MozTreeRow(ref args) => Some(args), + PseudoElement::MozTreeSeparator(ref args) => Some(args), + PseudoElement::MozTreeCell(ref args) => Some(args), + PseudoElement::MozTreeIndentation(ref args) => Some(args), + PseudoElement::MozTreeLine(ref args) => Some(args), + PseudoElement::MozTreeTwisty(ref args) => Some(args), + PseudoElement::MozTreeImage(ref args) => Some(args), + PseudoElement::MozTreeCellText(ref args) => Some(args), + PseudoElement::MozTreeCheckbox(ref args) => Some(args), + PseudoElement::MozTreeProgressmeter(ref args) => Some(args), + PseudoElement::MozTreeDropFeedback(ref args) => Some(args), + _ => None, + } + } + /// Construct a pseudo-element from an `Atom`. #[inline] pub fn from_atom(atom: &Atom) -> Option { @@ -1768,19 +1788,8 @@ impl ToCss for PseudoElement { PseudoElement::MozSVGForeignContent => dest.write_str(":-moz-svg-foreign-content")?, PseudoElement::MozSVGText => dest.write_str(":-moz-svg-text")?, } - match *self { - PseudoElement::MozTreeColumn(ref args) | - PseudoElement::MozTreeRow(ref args) | - PseudoElement::MozTreeSeparator(ref args) | - PseudoElement::MozTreeCell(ref args) | - PseudoElement::MozTreeIndentation(ref args) | - PseudoElement::MozTreeLine(ref args) | - PseudoElement::MozTreeTwisty(ref args) | - PseudoElement::MozTreeImage(ref args) | - PseudoElement::MozTreeCellText(ref args) | - PseudoElement::MozTreeCheckbox(ref args) | - PseudoElement::MozTreeProgressmeter(ref args) | - PseudoElement::MozTreeDropFeedback(ref args) => { + if let Some(args) = self.tree_pseudo_args() { + if !args.is_empty() { dest.write_char('(')?; let mut iter = args.iter(); if let Some(first) = iter.next() { @@ -1790,9 +1799,9 @@ impl ToCss for PseudoElement { serialize_identifier(&item.to_string(), dest)?; } } - dest.write_char(')') + dest.write_char(')')?; } - _ => Ok(()), } + Ok(()) } } diff --git a/components/style/gecko/pseudo_element_definition.mako.rs b/components/style/gecko/pseudo_element_definition.mako.rs index b7e5a7614aa..3c7f9e592a7 100644 --- a/components/style/gecko/pseudo_element_definition.mako.rs +++ b/components/style/gecko/pseudo_element_definition.mako.rs @@ -147,6 +147,17 @@ impl PseudoElement { (self.atom().as_ptr(), self.pseudo_type()) } + /// Get the argument list of a tree pseudo-element. + #[inline] + pub fn tree_pseudo_args(&self) -> Option<<&[Atom]> { + match *self { + % for pseudo in TREE_PSEUDOS: + PseudoElement::${pseudo.capitalized()}(ref args) => Some(args), + % endfor + _ => None, + } + } + /// Construct a pseudo-element from an `Atom`. #[inline] pub fn from_atom(atom: &Atom) -> Option { @@ -228,9 +239,8 @@ impl ToCss for PseudoElement { ${pseudo_element_variant(pseudo)} => dest.write_str("${pseudo.value}")?, % endfor } - match *self { - ${" |\n ".join("PseudoElement::{}(ref args)".format(pseudo.capitalized()) - for pseudo in TREE_PSEUDOS)} => { + if let Some(args) = self.tree_pseudo_args() { + if !args.is_empty() { dest.write_char('(')?; let mut iter = args.iter(); if let Some(first) = iter.next() { @@ -240,9 +250,9 @@ impl ToCss for PseudoElement { serialize_identifier(&item.to_string(), dest)?; } } - dest.write_char(')') + dest.write_char(')')?; } - _ => Ok(()), } + Ok(()) } } diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index b6d48414fd5..9e4c08f0197 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -379,6 +379,13 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>) -> Result> { PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) + .or_else(|| { + if name.starts_with("-moz-tree-") { + PseudoElement::tree_pseudo_element(&name, Box::new([])) + } else { + None + } + }) .ok_or(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone()))) }