style: Update font-style to css-fonts-4.

Bug: 1455358
Reviewed-by: xidorn
MozReview-Commit-ID: 1Nq5DyCjaZe
This commit is contained in:
Emilio Cobos Álvarez 2018-04-19 20:38:08 +02:00
parent f7636e6662
commit 32d4da8a99
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
11 changed files with 361 additions and 63 deletions

View file

@ -21,7 +21,7 @@ use std::slice;
use style_traits::{CssWriter, ParseError, ToCss};
use values::CSSFloat;
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::{Context, Integer, NonNegativeLength, Number, ToComputedValue};
use values::computed::{Angle, Context, Integer, NonNegativeLength, Number, ToComputedValue};
use values::generics::font::{FeatureTagValue, FontSettings};
use values::generics::font::{KeywordInfo as GenericKeywordInfo, VariationValue};
use values::specified::font::{self as specified, MIN_FONT_WEIGHT, MAX_FONT_WEIGHT};
@ -838,3 +838,68 @@ impl ToComputedValue for specified::MozScriptLevel {
specified::MozScriptLevel::MozAbsolute(*other as i32)
}
}
/// The computed value of `font-style`.
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
PartialEq)]
#[allow(missing_docs)]
pub enum FontStyle {
#[animation(error)]
Normal,
#[animation(error)]
Italic,
// FIXME(emilio): This needs to clamp really.
Oblique(Angle),
}
impl ToAnimatedZero for FontStyle {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
use num_traits::Zero;
Ok(FontStyle::Oblique(Angle::zero()))
}
}
impl FontStyle {
/// The default angle for font-style: oblique. This is 20deg per spec:
///
/// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
pub fn default_angle() -> Angle {
Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES)
}
/// Get the font style from Gecko's nsFont struct.
#[cfg(feature = "gecko")]
pub fn from_gecko(kw: u8) -> Self {
use gecko_bindings::structs;
match kw as u32 {
structs::NS_STYLE_FONT_STYLE_NORMAL => FontStyle::Normal,
structs::NS_STYLE_FONT_STYLE_ITALIC => FontStyle::Italic,
// FIXME(emilio): Grab the angle when we honor it :)
structs::NS_STYLE_FONT_STYLE_OBLIQUE => FontStyle::Oblique(Self::default_angle()),
_ => unreachable!("Unknown font style"),
}
}
}
impl ToCss for FontStyle {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match *self {
FontStyle::Normal => dest.write_str("normal"),
FontStyle::Italic => dest.write_str("italic"),
FontStyle::Oblique(ref angle) => {
dest.write_str("oblique")?;
if *angle != Self::default_angle() {
dest.write_char(' ')?;
angle.to_css(dest)?;
}
Ok(())
}
}
}
}

View file

@ -40,7 +40,7 @@ pub use self::background::{BackgroundRepeat, BackgroundSize};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontVariantAlternates, FontWeight};
pub use self::font::{FontFamily, FontLanguageOverride, FontVariantEastAsian, FontVariationSettings};
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle, FontVariantEastAsian, FontVariationSettings};
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};