diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 8e8bae7a5aa..8735f238906 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2169,9 +2169,10 @@ fn static_assert() { } } - pub fn fixup_system(&mut self) { + pub fn fixup_system(&mut self, default_font_type: structs::FontFamilyType) { self.gecko.mFont.systemFont = true; self.gecko.mGenericID = structs::kGenericFont_NONE; + self.gecko.mFont.fontlist.mDefaultFontType = default_font_type; } pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { @@ -2223,7 +2224,16 @@ fn static_assert() { use gecko_bindings::structs::FontFamilyType; use gecko_string_cache::Atom; - ::properties::longhands::font_family::computed_value::T( + if self.gecko.mFont.fontlist.mFontlist.is_empty() { + let default = match self.gecko.mFont.fontlist.mDefaultFontType { + FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")), + FontFamilyType::eFamily_sans_serif => FontFamily::Generic(atom!("sans-serif")), + _ => panic!("Default generic must be serif or sans-serif"), + }; + return longhands::font_family::computed_value::T(vec![default]); + } + + longhands::font_family::computed_value::T( self.gecko.mFont.fontlist.mFontlist.iter().map(|gecko_font_family_name| { match gecko_font_family_name.mType { FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")), diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index ea318ae731d..e4d257d02a6 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -2491,11 +2491,13 @@ ${helpers.single_keyword("-moz-math-variant", use app_units::Au; use cssparser::{Parser, ToCss}; + use gecko_bindings::structs::FontFamilyType; use properties::longhands; use std::fmt; use std::hash::{Hash, Hasher}; use style_traits::ParseError; use values::computed::{ToComputedValue, Context}; + <% system_fonts = """caption icon menu message-box small-caption status-bar -moz-window -moz-document -moz-workspace -moz-desktop @@ -2584,6 +2586,7 @@ ${helpers.single_keyword("-moz-math-variant", font_feature_settings: longhands::font_feature_settings::get_initial_value(), font_variant_alternates: longhands::font_variant_alternates::get_initial_value(), system_font: *self, + default_font_type: system.fontlist.mDefaultFontType, }; unsafe { bindings::Gecko_nsFont_Destroy(&mut system); } ret @@ -2615,6 +2618,7 @@ ${helpers.single_keyword("-moz-math-variant", pub ${name}: longhands::${name}::computed_value::T, % endfor pub system_font: SystemFont, + pub default_font_type: FontFamilyType, } impl SystemFont { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 8a3f91bb079..d008515fc8b 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3331,20 +3331,15 @@ where } } - // In case of just the language changing, the parent could have had no generic, - // which Gecko just does regular cascading with. Do the same. - // This can only happen in the case where the language changed but the family did not - if generic != structs::kGenericFont_NONE { - let pres_context = context.builder.device.pres_context(); - let gecko_font = context.builder.mutate_font().gecko_mut(); - gecko_font.mGenericID = generic; - unsafe { - bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( - gecko_font, - pres_context, - generic, - ); - } + let pres_context = context.builder.device.pres_context(); + let gecko_font = context.builder.mutate_font().gecko_mut(); + gecko_font.mGenericID = generic; + unsafe { + bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( + gecko_font, + pres_context, + generic, + ); } } % endif @@ -3371,7 +3366,9 @@ where let device = context.builder.device; if let PropertyDeclaration::FontFamily(ref val) = **declaration { if val.get_system().is_some() { - context.builder.mutate_font().fixup_system(); + let default = context.cached_system_font + .as_ref().unwrap().default_font_type; + context.builder.mutate_font().fixup_system(default); } else { context.builder.mutate_font().fixup_none_generic(device); }