mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
style: Cleanup generic font-family handling.
To be more similar between Rust and C++. This introduces GenericFontFamily and exposes that plus FontFamilyNameSyntax to C++, using that where appropriate instead of plain uint8_t as we were doing. As a follow-up, as discussed on IRC with Jonathan, we can remove the -moz-fixed family, and turn it just into an alias of Monospace. The only non-trivial change is the MatchType changes, but they're ok I think. The code already assumed at most one CSS generic, and the struct still takes 8 bits. I've verified that the relevant tests are passing (though try is closed). Differential Revision: https://phabricator.services.mozilla.com/D24272
This commit is contained in:
parent
c49a88ec84
commit
2184e3f2e5
7 changed files with 124 additions and 250 deletions
|
@ -683,6 +683,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
#[cfg(feature = "gecko")]
|
||||
fn recompute_default_font_family_type_if_needed(&mut self) {
|
||||
use crate::gecko_bindings::{bindings, structs};
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
|
||||
if !self.seen.contains(LonghandId::XLang) &&
|
||||
!self.seen.contains(LonghandId::FontFamily) {
|
||||
|
@ -697,7 +698,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
// System fonts are all right, and should have the default font type
|
||||
// set to none already, so bail out early.
|
||||
if font.mFont.systemFont {
|
||||
debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, structs::FontFamilyType::eFamily_none);
|
||||
debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, GenericFontFamily::None);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -717,11 +718,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
!use_document_fonts &&
|
||||
matches!(
|
||||
font.mGenericID,
|
||||
structs::kGenericFont_NONE |
|
||||
structs::kGenericFont_fantasy |
|
||||
structs::kGenericFont_cursive
|
||||
GenericFontFamily::None |
|
||||
GenericFontFamily::Fantasy |
|
||||
GenericFontFamily::Cursive
|
||||
) &&
|
||||
default_font_type != structs::FontFamilyType::eFamily_none;
|
||||
default_font_type != GenericFontFamily::None;
|
||||
|
||||
if !prioritize_user_fonts && default_font_type == font.mFont.fontlist.mDefaultFontType {
|
||||
// Nothing to do.
|
||||
|
|
|
@ -1984,20 +1984,20 @@ fn static_assert() {
|
|||
<% impl_font_settings("font_variation_settings", "gfxFontVariation", "VariationValue", "f32", "f32") %>
|
||||
|
||||
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
|
||||
use crate::gecko_bindings::structs::FontFamilyType;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
|
||||
let is_system_font = v.is_system_font;
|
||||
self.gecko.mFont.systemFont = is_system_font;
|
||||
self.gecko.mGenericID = if is_system_font {
|
||||
structs::kGenericFont_NONE
|
||||
GenericFontFamily::None
|
||||
} else {
|
||||
v.families.single_generic().unwrap_or(structs::kGenericFont_NONE)
|
||||
v.families.single_generic().unwrap_or(GenericFontFamily::None)
|
||||
};
|
||||
self.gecko.mFont.fontlist.mFontlist.mBasePtr.set_move(
|
||||
v.families.shared_font_list().clone()
|
||||
);
|
||||
// Fixed-up if needed in Cascade::fixup_font_stuff.
|
||||
self.gecko.mFont.fontlist.mDefaultFontType = FontFamilyType::eFamily_none;
|
||||
self.gecko.mFont.fontlist.mDefaultFontType = GenericFontFamily::None;
|
||||
}
|
||||
|
||||
pub fn copy_font_family_from(&mut self, other: &Self) {
|
||||
|
@ -2011,33 +2011,13 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn clone_font_family(&self) -> longhands::font_family::computed_value::T {
|
||||
use crate::gecko_bindings::structs::FontFamilyType;
|
||||
use crate::values::computed::font::{FontFamily, SingleFontFamily, FontFamilyList};
|
||||
|
||||
let fontlist = &self.gecko.mFont.fontlist;
|
||||
let shared_fontlist = unsafe { fontlist.mFontlist.mBasePtr.to_safe() };
|
||||
|
||||
let families = if shared_fontlist.mNames.is_empty() {
|
||||
let default = fontlist.mDefaultFontType;
|
||||
let default = match default {
|
||||
FontFamilyType::eFamily_serif => {
|
||||
SingleFontFamily::Generic(atom!("serif"))
|
||||
}
|
||||
_ => {
|
||||
// This can break with some combinations of user prefs, see
|
||||
// bug 1442195 for example. It doesn't really matter in this
|
||||
// case...
|
||||
//
|
||||
// FIXME(emilio): Probably should be storing the whole
|
||||
// default font name instead though.
|
||||
debug_assert_eq!(
|
||||
default,
|
||||
FontFamilyType::eFamily_sans_serif,
|
||||
"Default generic should be serif or sans-serif"
|
||||
);
|
||||
SingleFontFamily::Generic(atom!("sans-serif"))
|
||||
}
|
||||
};
|
||||
let default = SingleFontFamily::Generic(fontlist.mDefaultFontType);
|
||||
FontFamilyList::new(Box::new([default]))
|
||||
} else {
|
||||
FontFamilyList::SharedFontList(shared_fontlist)
|
||||
|
|
|
@ -326,7 +326,7 @@ ${helpers.predefined_type(
|
|||
|
||||
use app_units::Au;
|
||||
use cssparser::{Parser, ToCss};
|
||||
use crate::gecko_bindings::structs::FontFamilyType;
|
||||
use crate::values::computed::font::GenericFontFamily;
|
||||
use crate::properties::longhands;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
@ -466,7 +466,7 @@ ${helpers.predefined_type(
|
|||
pub ${name}: longhands::${name}::computed_value::T,
|
||||
% endfor
|
||||
pub system_font: SystemFont,
|
||||
pub default_font_type: FontFamilyType,
|
||||
pub default_font_type: GenericFontFamily,
|
||||
}
|
||||
|
||||
impl SystemFont {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue