diff options
author | Manish Goregaokar <manishearth@gmail.com> | 2017-06-06 17:09:08 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2017-06-07 09:39:58 -0700 |
commit | 6dbca89ff511e2c6f37a605b22ce54df07515d4d (patch) | |
tree | 13ea0334991d1a6dd13c285034fa546415d60cac | |
parent | 7e273d6c9b86d6ffbf216e84ae7326976888e5ef (diff) | |
download | servo-6dbca89ff511e2c6f37a605b22ce54df07515d4d.tar.gz servo-6dbca89ff511e2c6f37a605b22ce54df07515d4d.zip |
stylo: Refactor generic font handling into a method
-rw-r--r-- | components/style/properties/gecko.mako.rs | 27 | ||||
-rw-r--r-- | components/style/properties/longhand/font.mako.rs | 42 |
2 files changed, 46 insertions, 23 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index fa2bac3f618..989243c9af2 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -221,6 +221,9 @@ impl ${style_struct.gecko_struct_name} { pub fn gecko(&self) -> &${style_struct.gecko_ffi_name} { &self.gecko } + pub fn gecko_mut(&mut self) -> &mut ${style_struct.gecko_ffi_name} { + &mut self.gecko + } } </%def> @@ -1587,7 +1590,6 @@ fn static_assert() { pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { use properties::longhands::font_family::computed_value::FontFamily; - use gecko_bindings::structs::FontFamilyType; let list = &mut self.gecko.mFont.fontlist; unsafe { Gecko_FontFamilyList_Clear(list); } @@ -1600,28 +1602,7 @@ fn static_assert() { unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), f.quoted); } } FontFamily::Generic(ref name) => { - let (family_type, generic) = - if name == &atom!("serif") { - (FontFamilyType::eFamily_serif, - structs::kGenericFont_serif) - } else if name == &atom!("sans-serif") { - (FontFamilyType::eFamily_sans_serif, - structs::kGenericFont_sans_serif) - } else if name == &atom!("cursive") { - (FontFamilyType::eFamily_cursive, - structs::kGenericFont_cursive) - } else if name == &atom!("fantasy") { - (FontFamilyType::eFamily_fantasy, - structs::kGenericFont_fantasy) - } else if name == &atom!("monospace") { - (FontFamilyType::eFamily_monospace, - structs::kGenericFont_monospace) - } else if name == &atom!("-moz-fixed") { - (FontFamilyType::eFamily_moz_fixed, - structs::kGenericFont_moz_fixed) - } else { - panic!("Unknown generic font family") - }; + let (family_type, generic) = FontFamily::generic(name); if v.0.len() == 1 { self.gecko.mGenericID = generic; } diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 2c491a1630a..cd513fe0613 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -191,6 +191,33 @@ quoted: false, })) } + + #[cfg(feature = "gecko")] + /// Return the generic ID for a given generic font name + pub fn generic(name: &Atom) -> (::gecko_bindings::structs::FontFamilyType, u8) { + use gecko_bindings::structs::{self, FontFamilyType}; + if *name == atom!("serif") { + (FontFamilyType::eFamily_serif, + structs::kGenericFont_serif) + } else if *name == atom!("sans-serif") { + (FontFamilyType::eFamily_sans_serif, + structs::kGenericFont_sans_serif) + } else if *name == atom!("cursive") { + (FontFamilyType::eFamily_cursive, + structs::kGenericFont_cursive) + } else if *name == atom!("fantasy") { + (FontFamilyType::eFamily_fantasy, + structs::kGenericFont_fantasy) + } else if *name == atom!("monospace") { + (FontFamilyType::eFamily_monospace, + structs::kGenericFont_monospace) + } else if *name == atom!("-moz-fixed") { + (FontFamilyType::eFamily_moz_fixed, + structs::kGenericFont_moz_fixed) + } else { + panic!("Unknown generic {}", name); + } + } } impl ToCss for FamilyName { @@ -260,6 +287,21 @@ System(SystemFont), } + #[cfg(feature = "gecko")] + impl SpecifiedValue { + /// Return the generic ID if it is a single generic font + pub fn single_generic(&self) -> Option<u8> { + if let SpecifiedValue::Values(ref values) = *self { + if values.len() == 1 { + if let FontFamily::Generic(ref name) = values[0] { + return Some(FontFamily::generic(name).1); + } + } + } + None + } + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; fn to_computed_value(&self, _cx: &Context) -> Self::ComputedValue { |