Skip to content

Commit

Permalink
Accept argument-less tree pseudo-element selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Oct 20, 2017
1 parent a2182f8 commit b743d68
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
39 changes: 24 additions & 15 deletions components/style/gecko/generated/pseudo_element_definition.rs
Expand Up @@ -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<Self> {
Expand Down Expand Up @@ -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() {
Expand All @@ -1790,9 +1799,9 @@ impl ToCss for PseudoElement {
serialize_identifier(&item.to_string(), dest)?;
}
}
dest.write_char(')')
dest.write_char(')')?;
}
_ => Ok(()),
}
Ok(())
}
}
20 changes: 15 additions & 5 deletions components/style/gecko/pseudo_element_definition.mako.rs
Expand Up @@ -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<Self> {
Expand Down Expand Up @@ -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() {
Expand All @@ -240,9 +250,9 @@ impl ToCss for PseudoElement {
serialize_identifier(&item.to_string(), dest)?;
}
}
dest.write_char(')')
dest.write_char(')')?;
}
_ => Ok(()),
}
Ok(())
}
}
7 changes: 7 additions & 0 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -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, ParseError<'i>> {
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())))
}

Expand Down

0 comments on commit b743d68

Please sign in to comment.