mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Cleanup font-weight parsing.
This commit is contained in:
parent
1e0fd7da30
commit
f37859375e
2 changed files with 29 additions and 32 deletions
|
@ -5,10 +5,8 @@
|
||||||
//! Computed values for font properties
|
//! Computed values for font properties
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::Parser;
|
|
||||||
use parser::{Parse, ParserContext};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
|
use style_traits::ToCss;
|
||||||
use values::animated::ToAnimatedValue;
|
use values::animated::ToAnimatedValue;
|
||||||
use values::computed::{Context, NonNegativeLength, ToComputedValue};
|
use values::computed::{Context, NonNegativeLength, ToComputedValue};
|
||||||
use values::specified::font as specified;
|
use values::specified::font as specified;
|
||||||
|
@ -136,14 +134,6 @@ impl FontWeight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for FontWeight {
|
|
||||||
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>)
|
|
||||||
-> Result<FontWeight, ParseError<'i>> {
|
|
||||||
FontWeight::from_int(input.expect_integer()?)
|
|
||||||
.map_err(|_| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FontSize {
|
impl FontSize {
|
||||||
/// The actual computed font size.
|
/// The actual computed font size.
|
||||||
pub fn size(self) -> Au {
|
pub fn size(self) -> Au {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use Atom;
|
use Atom;
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::Parser;
|
use cssparser::{Parser, Token};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::longhands::system_font::SystemFont;
|
use properties::longhands::system_font::SystemFont;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -58,19 +58,24 @@ impl FontWeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for FontWeight {
|
impl Parse for FontWeight {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<FontWeight, ParseError<'i>> {
|
||||||
-> Result<FontWeight, ParseError<'i>> {
|
let result = match *input.next()? {
|
||||||
let result = input.try(|input| {
|
Token::Ident(ref ident) => {
|
||||||
let ident = input.expect_ident().map_err(|_| ())?;
|
match_ignore_ascii_case! { ident,
|
||||||
match_ignore_ascii_case! { &ident,
|
"normal" => Ok(FontWeight::Normal),
|
||||||
"normal" => Ok(FontWeight::Normal),
|
"bold" => Ok(FontWeight::Bold),
|
||||||
"bold" => Ok(FontWeight::Bold),
|
"bolder" => Ok(FontWeight::Bolder),
|
||||||
"bolder" => Ok(FontWeight::Bolder),
|
"lighter" => Ok(FontWeight::Lighter),
|
||||||
"lighter" => Ok(FontWeight::Lighter),
|
_ => Err(()),
|
||||||
_ => Err(())
|
}
|
||||||
}
|
}
|
||||||
});
|
Token::Number { int_value: Some(value), .. } => {
|
||||||
result.or_else(|_| computed::FontWeight::parse(context, input).map(FontWeight::Weight))
|
computed::FontWeight::from_int(value).map(FontWeight::Weight)
|
||||||
|
},
|
||||||
|
_ => Err(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
result.map_err(|_| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +88,18 @@ impl ToComputedValue for FontWeight {
|
||||||
FontWeight::Weight(weight) => weight,
|
FontWeight::Weight(weight) => weight,
|
||||||
FontWeight::Normal => computed::FontWeight::normal(),
|
FontWeight::Normal => computed::FontWeight::normal(),
|
||||||
FontWeight::Bold => computed::FontWeight::bold(),
|
FontWeight::Bold => computed::FontWeight::bold(),
|
||||||
FontWeight::Bolder =>
|
FontWeight::Bolder => {
|
||||||
context.builder.get_parent_font().clone_font_weight().bolder(),
|
context.builder.get_parent_font().clone_font_weight().bolder()
|
||||||
FontWeight::Lighter =>
|
},
|
||||||
context.builder.get_parent_font().clone_font_weight().lighter(),
|
FontWeight::Lighter => {
|
||||||
|
context.builder.get_parent_font().clone_font_weight().lighter()
|
||||||
|
},
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
FontWeight::System(_) =>
|
FontWeight::System(_) => {
|
||||||
context.cached_system_font.as_ref().unwrap().font_weight.clone(),
|
context.cached_system_font.as_ref().unwrap().font_weight.clone()
|
||||||
|
},
|
||||||
#[cfg(not(feature = "gecko"))]
|
#[cfg(not(feature = "gecko"))]
|
||||||
FontWeight::System(_) =>
|
FontWeight::System(_) => unreachable!(),
|
||||||
unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue