diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index e3f919cc56e..b64ff4c6349 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -916,12 +916,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // we have a generic family to actually replace it with. let prioritize_user_fonts = !use_document_fonts && default_font_type != GenericFontFamily::None && - matches!( - generic, - GenericFontFamily::None | - GenericFontFamily::Fantasy | - GenericFontFamily::Cursive - ); + !generic.valid_for_user_font_prioritization(); if !prioritize_user_fonts && default_font_type == font.mFont.family.families.fallback { // Nothing to do. diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index e2b29f61d5e..0306c88cb0f 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -439,6 +439,25 @@ pub enum GenericFontFamily { MozEmoji, } +impl GenericFontFamily { + /// When we disallow websites to override fonts, we ignore some generic + /// families that the website might specify, since they're not configured by + /// the user. See bug 789788 and bug 1730098. + pub (crate) fn valid_for_user_font_prioritization(self) -> bool { + match self { + Self::None | + Self::Fantasy | + Self::Cursive | + Self::SystemUi | + Self::MozEmoji => false, + + Self::Serif | + Self::SansSerif | + Self::Monospace => true, + } + } +} + impl Parse for SingleFontFamily { /// Parse a font-family value. fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -579,14 +598,14 @@ impl FontFamilyList { self.list = crate::ArcSlice::from_iter(new_list.into_iter()); } - /// If there's a generic font family on the list (which isn't cursive or - /// fantasy), then move it to the front of the list. Otherwise, prepend the - /// default generic. + /// If there's a generic font family on the list which is suitable for user + /// font prioritization, then move it to the front of the list. Otherwise, + /// prepend the default generic. #[cfg(feature = "gecko")] pub (crate) fn prioritize_first_generic_or_prepend(&mut self, generic: GenericFontFamily) { let index_of_first_generic = self.iter().position(|f| { match *f { - SingleFontFamily::Generic(f) => f != GenericFontFamily::Cursive && f != GenericFontFamily::Fantasy, + SingleFontFamily::Generic(f) => f.valid_for_user_font_prioritization(), _ => false, } });