mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Accept argument-less tree pseudo-element selector.
This commit is contained in:
parent
a2182f8dc3
commit
b743d68ccd
3 changed files with 46 additions and 20 deletions
|
@ -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> {
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue