зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #19093 - style: Cleanup font-weight parsing (from cbrewster:font_weight_cleanup); r=emilio
Followup for #19086 Source-Repo: https://github.com/servo/servo Source-Revision: edb2db55b7fd72370a90fc65c5984d6b7e0f792f --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : eedfdd081ad66613fd2c67510f2cb9deaa0a832c
This commit is contained in:
Родитель
ef37c668b8
Коммит
81c85665a4
|
@ -5,10 +5,8 @@
|
|||
//! Computed values for font properties
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
|
||||
use style_traits::ToCss;
|
||||
use values::animated::ToAnimatedValue;
|
||||
use values::computed::{Context, NonNegativeLength, ToComputedValue};
|
||||
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 {
|
||||
/// The actual computed font size.
|
||||
pub fn size(self) -> Au {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#[cfg(feature = "gecko")]
|
||||
use Atom;
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, Token};
|
||||
use parser::{Parse, ParserContext};
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
use std::fmt;
|
||||
|
@ -58,19 +58,24 @@ impl FontWeight {
|
|||
}
|
||||
|
||||
impl Parse for FontWeight {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<FontWeight, ParseError<'i>> {
|
||||
let result = input.try(|input| {
|
||||
let ident = input.expect_ident().map_err(|_| ())?;
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"normal" => Ok(FontWeight::Normal),
|
||||
"bold" => Ok(FontWeight::Bold),
|
||||
"bolder" => Ok(FontWeight::Bolder),
|
||||
"lighter" => Ok(FontWeight::Lighter),
|
||||
_ => Err(())
|
||||
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<FontWeight, ParseError<'i>> {
|
||||
let result = match *input.next()? {
|
||||
Token::Ident(ref ident) => {
|
||||
match_ignore_ascii_case! { ident,
|
||||
"normal" => Ok(FontWeight::Normal),
|
||||
"bold" => Ok(FontWeight::Bold),
|
||||
"bolder" => Ok(FontWeight::Bolder),
|
||||
"lighter" => Ok(FontWeight::Lighter),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
});
|
||||
result.or_else(|_| computed::FontWeight::parse(context, input).map(FontWeight::Weight))
|
||||
Token::Number { int_value: Some(value), .. } => {
|
||||
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::Normal => computed::FontWeight::normal(),
|
||||
FontWeight::Bold => computed::FontWeight::bold(),
|
||||
FontWeight::Bolder =>
|
||||
context.builder.get_parent_font().clone_font_weight().bolder(),
|
||||
FontWeight::Lighter =>
|
||||
context.builder.get_parent_font().clone_font_weight().lighter(),
|
||||
FontWeight::Bolder => {
|
||||
context.builder.get_parent_font().clone_font_weight().bolder()
|
||||
},
|
||||
FontWeight::Lighter => {
|
||||
context.builder.get_parent_font().clone_font_weight().lighter()
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
FontWeight::System(_) =>
|
||||
context.cached_system_font.as_ref().unwrap().font_weight.clone(),
|
||||
FontWeight::System(_) => {
|
||||
context.cached_system_font.as_ref().unwrap().font_weight.clone()
|
||||
},
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
FontWeight::System(_) =>
|
||||
unreachable!(),
|
||||
FontWeight::System(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче