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
This commit is contained in:
Emilio Cobos Álvarez 2023-05-27 07:05:23 +02:00 committed by Oriol Brufau
parent 7108be870d
commit 1e5806610b
2 changed files with 24 additions and 10 deletions

View file

@ -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.

View file

@ -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<Self, ParseError<'i>> {
@ -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,
}
});