mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add pseudo_element_variant helper function to simplify some code.
This commit is contained in:
parent
2649d0332a
commit
832c4c4079
1 changed files with 15 additions and 8 deletions
|
@ -23,6 +23,10 @@ pub const EAGER_PSEUDOS: [PseudoElement; EAGER_PSEUDO_COUNT] = [
|
||||||
% endfor
|
% endfor
|
||||||
];
|
];
|
||||||
|
|
||||||
|
<%def name="pseudo_element_variant(pseudo)">
|
||||||
|
PseudoElement::${pseudo.capitalized()}
|
||||||
|
</%def>
|
||||||
|
|
||||||
impl PseudoElement {
|
impl PseudoElement {
|
||||||
/// Executes a closure with each simple (not functional)
|
/// Executes a closure with each simple (not functional)
|
||||||
/// pseudo-element as an argument.
|
/// pseudo-element as an argument.
|
||||||
|
@ -30,7 +34,7 @@ impl PseudoElement {
|
||||||
where F: FnMut(Self),
|
where F: FnMut(Self),
|
||||||
{
|
{
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
fun(PseudoElement::${pseudo.capitalized()});
|
fun(${pseudo_element_variant(pseudo)});
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ impl PseudoElement {
|
||||||
pub fn atom(&self) -> Atom {
|
pub fn atom(&self) -> Atom {
|
||||||
match *self {
|
match *self {
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
PseudoElement::${pseudo.capitalized()} => atom!("${pseudo.value}"),
|
${pseudo_element_variant(pseudo)} => atom!("${pseudo.value}"),
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +53,11 @@ impl PseudoElement {
|
||||||
fn is_anon_box(&self) -> bool {
|
fn is_anon_box(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
PseudoElement::${pseudo.capitalized()} => ${str(pseudo.is_anon_box()).lower()},
|
% if pseudo.is_anon_box():
|
||||||
|
${pseudo_element_variant(pseudo)} => true,
|
||||||
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +73,7 @@ impl PseudoElement {
|
||||||
pub fn flags(&self) -> u32 {
|
pub fn flags(&self) -> u32 {
|
||||||
match *self {
|
match *self {
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
PseudoElement::${pseudo.capitalized()} =>
|
${pseudo_element_variant(pseudo)} =>
|
||||||
% if pseudo.is_anon_box():
|
% if pseudo.is_anon_box():
|
||||||
structs::CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY,
|
structs::CSS_PSEUDO_ELEMENT_UA_SHEET_ONLY,
|
||||||
% else:
|
% else:
|
||||||
|
@ -83,7 +90,7 @@ impl PseudoElement {
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
% if not pseudo.is_anon_box():
|
% if not pseudo.is_anon_box():
|
||||||
CSSPseudoElementType::${pseudo.original_ident} => {
|
CSSPseudoElementType::${pseudo.original_ident} => {
|
||||||
Some(PseudoElement::${pseudo.capitalized()})
|
Some(${pseudo_element_variant(pseudo)})
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -97,7 +104,7 @@ impl PseudoElement {
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
% if pseudo.is_anon_box():
|
% if pseudo.is_anon_box():
|
||||||
if atom == &atom!("${pseudo.value}") {
|
if atom == &atom!("${pseudo.value}") {
|
||||||
return Some(PseudoElement::${pseudo.capitalized()});
|
return Some(${pseudo_element_variant(pseudo)});
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -116,9 +123,9 @@ impl PseudoElement {
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
|
||||||
% for pseudo in PSEUDOS:
|
% for pseudo in PSEUDOS:
|
||||||
if in_ua_stylesheet || PseudoElement::${pseudo.capitalized()}.exposed_in_non_ua_sheets() {
|
if in_ua_stylesheet || ${pseudo_element_variant(pseudo)}.exposed_in_non_ua_sheets() {
|
||||||
if s.eq_ignore_ascii_case("${pseudo.value[1:]}") {
|
if s.eq_ignore_ascii_case("${pseudo.value[1:]}") {
|
||||||
return Some(PseudoElement::${pseudo.capitalized()})
|
return Some(${pseudo_element_variant(pseudo)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue