diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2017-05-18 13:12:27 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-05-18 18:16:24 +0200 |
commit | 96a23d9b73860fd0bc4fa089de1d4ca074654adc (patch) | |
tree | 4cf2cbe539e9208d56977b1b93a3a42a25cb0fb9 | |
parent | a0886213b69f4fdc348a6d76baeb07b2559e6f18 (diff) | |
download | servo-96a23d9b73860fd0bc4fa089de1d4ca074654adc.tar.gz servo-96a23d9b73860fd0bc4fa089de1d4ca074654adc.zip |
stylo: Bug 1355345 - Support font-display descriptor in @font-face rule
-rw-r--r-- | components/style/font_face.rs | 16 | ||||
-rw-r--r-- | components/style/gecko/rules.rs | 14 |
2 files changed, 28 insertions, 2 deletions
diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 4eb79690c91..4c953c3b028 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -72,6 +72,17 @@ impl ToCss for UrlSource { } } +/// A font-display value for a @font-face rule. +/// The font-display descriptor determines how a font face is displayed based +/// on whether and when it is downloaded and ready to use. +define_css_keyword_enum!(FontDisplay: + "auto" => Auto, + "block" => Block, + "swap" => Swap, + "fallback" => Fallback, + "optional" => Optional); +add_impls_for_keyword_enum!(FontDisplay); + /// Parse the block inside a `@font-face` rule. /// /// Note that the prelude parsing code lives in the `stylesheets` module. @@ -332,6 +343,9 @@ font_face_descriptors! { /// The stretch of this font face "font-stretch" stretch / mStretch: font_stretch::T = font_stretch::T::normal, + /// The display of this font face + "font-display" display / mDisplay: FontDisplay = FontDisplay::Auto, + /// The ranges of code points outside of which this font face should not be used. "unicode-range" unicode_range / mUnicodeRange: Vec<UnicodeRange> = vec![ UnicodeRange { start: 0, end: 0x10FFFF } @@ -342,7 +356,7 @@ font_face_descriptors! { font_feature_settings::T::Normal }, - // FIXME: add font-language-override, and font-display. + // FIXME: add font-language-override. ] } diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index aceb4aec5e9..80aa7a7acb2 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -9,7 +9,7 @@ use computed_values::{font_feature_settings, font_stretch, font_style, font_weig use computed_values::font_family::FamilyName; use counter_style; use cssparser::UnicodeRange; -use font_face::{FontFaceRuleData, Source}; +use font_face::{FontFaceRuleData, Source, FontDisplay}; use gecko_bindings::bindings; use gecko_bindings::structs::{self, nsCSSFontFaceRule, nsCSSValue}; use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule}; @@ -137,6 +137,18 @@ impl ToNsCssValue for Vec<UnicodeRange> { } } +impl ToNsCssValue for FontDisplay { + fn convert(self, nscssvalue: &mut nsCSSValue) { + nscssvalue.set_enum(match self { + FontDisplay::Auto => structs::NS_FONT_DISPLAY_AUTO, + FontDisplay::Block => structs::NS_FONT_DISPLAY_BLOCK, + FontDisplay::Swap => structs::NS_FONT_DISPLAY_SWAP, + FontDisplay::Fallback => structs::NS_FONT_DISPLAY_FALLBACK, + FontDisplay::Optional => structs::NS_FONT_DISPLAY_OPTIONAL, + } as i32) + } +} + impl From<FontFaceRuleData> for FontFaceRule { fn from(data: FontFaceRuleData) -> FontFaceRule { let mut result = unsafe { |