Auto merge of #18244 - kahsieh:master, r=Manishearth

stylo: Update CSS fallback font when lang changes

r=manishearth in BugZilla.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix [Bug 1367860](https://bugzilla.mozilla.org/show_bug.cgi?id=1367860).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18244)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-25 17:30:22 -05:00 committed by GitHub
commit 2136dd2bb7
3 changed files with 28 additions and 17 deletions

View file

@ -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.mFont.systemFont = true;
self.gecko.mGenericID = structs::kGenericFont_NONE; 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) { 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_bindings::structs::FontFamilyType;
use gecko_string_cache::Atom; 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| { self.gecko.mFont.fontlist.mFontlist.iter().map(|gecko_font_family_name| {
match gecko_font_family_name.mType { match gecko_font_family_name.mType {
FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")), FontFamilyType::eFamily_serif => FontFamily::Generic(atom!("serif")),

View file

@ -2491,11 +2491,13 @@ ${helpers.single_keyword("-moz-math-variant",
use app_units::Au; use app_units::Au;
use cssparser::{Parser, ToCss}; use cssparser::{Parser, ToCss};
use gecko_bindings::structs::FontFamilyType;
use properties::longhands; use properties::longhands;
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use style_traits::ParseError; use style_traits::ParseError;
use values::computed::{ToComputedValue, Context}; use values::computed::{ToComputedValue, Context};
<% <%
system_fonts = """caption icon menu message-box small-caption status-bar system_fonts = """caption icon menu message-box small-caption status-bar
-moz-window -moz-document -moz-workspace -moz-desktop -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_feature_settings: longhands::font_feature_settings::get_initial_value(),
font_variant_alternates: longhands::font_variant_alternates::get_initial_value(), font_variant_alternates: longhands::font_variant_alternates::get_initial_value(),
system_font: *self, system_font: *self,
default_font_type: system.fontlist.mDefaultFontType,
}; };
unsafe { bindings::Gecko_nsFont_Destroy(&mut system); } unsafe { bindings::Gecko_nsFont_Destroy(&mut system); }
ret ret
@ -2615,6 +2618,7 @@ ${helpers.single_keyword("-moz-math-variant",
pub ${name}: longhands::${name}::computed_value::T, pub ${name}: longhands::${name}::computed_value::T,
% endfor % endfor
pub system_font: SystemFont, pub system_font: SystemFont,
pub default_font_type: FontFamilyType,
} }
impl SystemFont { impl SystemFont {

View file

@ -3331,20 +3331,15 @@ where
} }
} }
// In case of just the language changing, the parent could have had no generic, let pres_context = context.builder.device.pres_context();
// which Gecko just does regular cascading with. Do the same. let gecko_font = context.builder.mutate_font().gecko_mut();
// This can only happen in the case where the language changed but the family did not gecko_font.mGenericID = generic;
if generic != structs::kGenericFont_NONE { unsafe {
let pres_context = context.builder.device.pres_context(); bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric(
let gecko_font = context.builder.mutate_font().gecko_mut(); gecko_font,
gecko_font.mGenericID = generic; pres_context,
unsafe { generic,
bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( );
gecko_font,
pres_context,
generic,
);
}
} }
} }
% endif % endif
@ -3371,7 +3366,9 @@ where
let device = context.builder.device; let device = context.builder.device;
if let PropertyDeclaration::FontFamily(ref val) = **declaration { if let PropertyDeclaration::FontFamily(ref val) = **declaration {
if val.get_system().is_some() { 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 { } else {
context.builder.mutate_font().fixup_none_generic(device); context.builder.mutate_font().fixup_none_generic(device);
} }