From 1e5806610b47beb0344b73e45144f334e8be3e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 27 May 2023 07:05:23 +0200 Subject: [PATCH] style: Don't consider system-ui valid for user font prioritization Since the user can't configure it, at least from the UI (we could add UI for it but it's unclear it'd be worth it). Differential Revision: https://phabricator.services.mozilla.com/D125182 --- components/style/properties/cascade.rs | 7 +----- components/style/values/computed/font.rs | 27 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) 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, } });