diff --git a/servo/components/style/font_face.rs b/servo/components/style/font_face.rs index 24204efc1311..52cebcb9dc2f 100644 --- a/servo/components/style/font_face.rs +++ b/servo/components/style/font_face.rs @@ -194,7 +194,7 @@ impl FontStretchRange { fn compute_stretch(s: &FontStretch) -> f32 { match *s { FontStretch::Keyword(ref kw) => kw.compute().0, - FontStretch::Stretch(ref p) => p.get(), + FontStretch::Stretch(ref p) => p.0.get(), FontStretch::System(..) => unreachable!(), } } diff --git a/servo/components/style/properties/shorthands/font.mako.rs b/servo/components/style/properties/shorthands/font.mako.rs index 176164c4b1e6..2ed36ae88a5f 100644 --- a/servo/components/style/properties/shorthands/font.mako.rs +++ b/servo/components/style/properties/shorthands/font.mako.rs @@ -197,7 +197,7 @@ let font_stretch = match *self.font_stretch { FontStretch::Keyword(kw) => kw, FontStretch::Stretch(percentage) => { - match FontStretchKeyword::from_percentage(percentage.get()) { + match FontStretchKeyword::from_percentage(percentage.0.get()) { Some(kw) => kw, None => return Ok(()), } diff --git a/servo/components/style/values/specified/font.rs b/servo/components/style/values/specified/font.rs index 5f45d81d83dd..77626e7c4875 100644 --- a/servo/components/style/values/specified/font.rs +++ b/servo/components/style/values/specified/font.rs @@ -17,7 +17,7 @@ use crate::values::generics::font::{self as generics, FeatureTagValue, FontSetti use crate::values::generics::NonNegative; use crate::values::specified::length::{FontBaseSize, AU_PER_PT, AU_PER_PX}; use crate::values::specified::{AllowQuirks, Angle, Integer, LengthPercentage}; -use crate::values::specified::{NoCalcLength, NonNegativeNumber, Number, Percentage}; +use crate::values::specified::{NoCalcLength, NonNegativeNumber, Number, NonNegativePercentage}; use crate::values::CustomIdent; use crate::Atom; use cssparser::{Parser, Token}; @@ -357,13 +357,11 @@ impl ToComputedValue for FontStyle { /// A value for the `font-stretch` property. /// /// https://drafts.csswg.org/css-fonts-4/#font-stretch-prop -/// -/// TODO(emilio): We could derive Parse if we had NonNegativePercentage. #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] +#[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] #[repr(u8)] pub enum FontStretch { - Stretch(Percentage), + Stretch(NonNegativePercentage), Keyword(FontStretchKeyword), #[css(skip)] System(SystemFont), @@ -450,32 +448,13 @@ impl FontStretch { system_font_methods!(FontStretch, font_stretch); } -impl Parse for FontStretch { - fn parse<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - // From https://drafts.csswg.org/css-fonts-4/#font-stretch-prop: - // - // Values less than 0% are not allowed and are treated as parse - // errors. - if let Ok(percentage) = - input.try_parse(|input| Percentage::parse_non_negative(context, input)) - { - return Ok(FontStretch::Stretch(percentage)); - } - - Ok(FontStretch::Keyword(FontStretchKeyword::parse(input)?)) - } -} - impl ToComputedValue for FontStretch { type ComputedValue = computed::FontStretch; fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { FontStretch::Stretch(ref percentage) => { - computed::FontStretch(NonNegative(percentage.to_computed_value(context))) + computed::FontStretch(percentage.to_computed_value(context)) }, FontStretch::Keyword(ref kw) => computed::FontStretch(NonNegative(kw.compute())), FontStretch::System(_) => self.compute_system(context), @@ -483,7 +462,7 @@ impl ToComputedValue for FontStretch { } fn from_computed_value(computed: &Self::ComputedValue) -> Self { - FontStretch::Stretch(Percentage::from_computed_value(&(computed.0).0)) + FontStretch::Stretch(NonNegativePercentage::from_computed_value(&NonNegative((computed.0).0))) } } diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 443633301b3b..13b4ec297cda 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -6747,7 +6747,7 @@ pub unsafe extern "C" fn Servo_ParseFontShorthandForMatching( *stretch = match font.font_stretch { FontStretch::Keyword(ref k) => k.compute().0, - FontStretch::Stretch(ref p) => p.get(), + FontStretch::Stretch(ref p) => p.0.get(), FontStretch::System(_) => return false, };