Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Update CSS fallback font when lang changes #18244

Merged
merged 1 commit into from Aug 26, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Update CSS fallback font when lang changes

  • Loading branch information
kahsieh committed Aug 25, 2017
commit cfa98a3ab6f838e785a4f5a718f8d9378d3a0415
@@ -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")),
@@ -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 {
@@ -3330,20 +3330,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
@@ -3370,7 +3365,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);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.