mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Remove intermediate FontFaceDescriptorDeclaration enum.
Have `@font-face` parsing write to `FontFaceRule` directly.
This commit is contained in:
parent
df487197e8
commit
7724bb01a3
1 changed files with 22 additions and 35 deletions
|
@ -108,33 +108,26 @@ impl ToCss for FontFaceRule {
|
||||||
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
/// Note that the prelude parsing code lives in the `stylesheets` module.
|
||||||
pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<FontFaceRule, ()> {
|
-> Result<FontFaceRule, ()> {
|
||||||
let mut family = None;
|
let mut rule = FontFaceRule {
|
||||||
let mut src = None;
|
family: FontFamily::Generic(atom!("")),
|
||||||
let mut iter = DeclarationListParser::new(input, FontFaceRuleParser { context: context });
|
sources: Vec::new(),
|
||||||
while let Some(declaration) = iter.next() {
|
};
|
||||||
match declaration {
|
{
|
||||||
Err(range) => {
|
let parser = FontFaceRuleParser { context: context, rule: &mut rule };
|
||||||
|
let mut iter = DeclarationListParser::new(input, parser);
|
||||||
|
while let Some(declaration) = iter.next() {
|
||||||
|
if let Err(range) = declaration {
|
||||||
let pos = range.start;
|
let pos = range.start;
|
||||||
let message = format!("Unsupported @font-face descriptor declaration: '{}'",
|
let message = format!("Unsupported @font-face descriptor declaration: '{}'",
|
||||||
iter.input.slice(range));
|
iter.input.slice(range));
|
||||||
log_css_error(iter.input, pos, &*message, context);
|
log_css_error(iter.input, pos, &*message, context);
|
||||||
}
|
}
|
||||||
Ok(FontFaceDescriptorDeclaration::Family(value)) => {
|
|
||||||
family = Some(value);
|
|
||||||
}
|
|
||||||
Ok(FontFaceDescriptorDeclaration::Src(value)) => {
|
|
||||||
src = Some(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match (family, src) {
|
if rule.family != FontFamily::Generic(atom!("")) && !rule.sources.is_empty() {
|
||||||
(Some(family), Some(src)) => {
|
Ok(rule)
|
||||||
Ok(FontFaceRule {
|
} else {
|
||||||
family: family,
|
Err(())
|
||||||
sources: src,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => Err(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,40 +164,34 @@ impl iter::Iterator for EffectiveSources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum FontFaceDescriptorDeclaration {
|
|
||||||
Family(FontFamily),
|
|
||||||
Src(Vec<Source>),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct FontFaceRuleParser<'a, 'b: 'a> {
|
struct FontFaceRuleParser<'a, 'b: 'a> {
|
||||||
context: &'a ParserContext<'b>,
|
context: &'a ParserContext<'b>,
|
||||||
|
rule: &'a mut FontFaceRule,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Default methods reject all at rules.
|
/// Default methods reject all at rules.
|
||||||
impl<'a, 'b> AtRuleParser for FontFaceRuleParser<'a, 'b> {
|
impl<'a, 'b> AtRuleParser for FontFaceRuleParser<'a, 'b> {
|
||||||
type Prelude = ();
|
type Prelude = ();
|
||||||
type AtRule = FontFaceDescriptorDeclaration;
|
type AtRule = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
|
impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
|
||||||
type Declaration = FontFaceDescriptorDeclaration;
|
type Declaration = ();
|
||||||
|
|
||||||
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<FontFaceDescriptorDeclaration, ()> {
|
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<(), ()> {
|
||||||
match_ignore_ascii_case! { name,
|
match_ignore_ascii_case! { name,
|
||||||
"font-family" => {
|
"font-family" => {
|
||||||
Ok(FontFaceDescriptorDeclaration::Family(try!(
|
self.rule.family = parse_one_family(input)?;
|
||||||
parse_one_family(input))))
|
|
||||||
},
|
},
|
||||||
"src" => {
|
"src" => {
|
||||||
Ok(FontFaceDescriptorDeclaration::Src(try!(input.parse_comma_separated(|input| {
|
self.rule.sources = input.parse_comma_separated(|input| {
|
||||||
parse_one_src(self.context, input)
|
parse_one_src(self.context, input)
|
||||||
}))))
|
})?;
|
||||||
},
|
},
|
||||||
_ => Err(())
|
_ => return Err(())
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue