mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 23:05:42 +00:00
Bug 1681691 - Convert the font-stretch descriptor to use NonNegativePercentage. r=emilio
Depends on D109285 Differential Revision: https://phabricator.services.mozilla.com/D109286
This commit is contained in:
parent
bc2b113e81
commit
54906f738a
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
@ -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(()),
|
||||
}
|
||||
|
@ -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<Self, ParseError<'i>> {
|
||||
// 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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user