style: Use less Au in font code.

Font code is the only thing that was using Au in the style system without
interfacing with Gecko, and there was no real reason for it to do so.

This slightly simplifies the code.

Differential Revision: https://phabricator.services.mozilla.com/D57248
This commit is contained in:
Emilio Cobos Álvarez 2019-12-15 20:15:29 +01:00
parent 4cd8813a81
commit a541046147
13 changed files with 62 additions and 89 deletions

View file

@ -11,10 +11,9 @@ use crate::gecko_bindings::structs;
use crate::media_queries::MediaType;
use crate::properties::ComputedValues;
use crate::string_cache::Atom;
use crate::values::computed::font::FontSize;
use crate::values::specified::font::FONT_MEDIUM_PX;
use crate::values::{CustomIdent, KeyframesName};
use app_units::Au;
use app_units::AU_PER_PX;
use app_units::{Au, AU_PER_PX};
use cssparser::RGBA;
use euclid::default::Size2D;
use euclid::Scale;
@ -87,7 +86,7 @@ impl Device {
document,
default_values: ComputedValues::default_values(doc),
// FIXME(bz): Seems dubious?
root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
root_font_size: AtomicIsize::new(Au::from_px(FONT_MEDIUM_PX as i32).0 as isize),
body_text_color: AtomicUsize::new(prefs.mDefaultColor as usize),
used_root_font_size: AtomicBool::new(false),
used_viewport_size: AtomicBool::new(false),
@ -139,8 +138,7 @@ impl Device {
/// Set the font size of the root element (for rem)
pub fn set_root_font_size(&self, size: Au) {
self.root_font_size
.store(size.0 as isize, Ordering::Relaxed)
self.root_font_size.store(size.0 as isize, Ordering::Relaxed)
}
/// Sets the body text color for the "inherit color from body" quirk.

View file

@ -68,6 +68,7 @@ use crate::shared_lock::Locked;
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use crate::stylist::CascadeData;
use crate::values::computed::font::GenericFontFamily;
use crate::values::computed::Length;
use crate::values::specified::length::FontBaseSize;
use crate::CaseSensitivityExt;
use app_units::Au;
@ -929,7 +930,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
GeckoFontMetricsProvider::new()
}
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> Au {
fn get_size(&self, font_name: &Atom, font_family: GenericFontFamily) -> Length {
let mut cache = self.font_size_cache.borrow_mut();
if let Some(sizes) = cache.iter().find(|el| el.0 == *font_name) {
return sizes.1.size_for_generic(font_family);
@ -950,7 +951,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
None => return Default::default(),
};
let size = base_size.resolve(context);
let size = Au::from(base_size.resolve(context));
let style = context.style();
let (wm, font) = match base_size {
@ -977,9 +978,9 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
)
};
FontMetrics {
x_height: Some(Au(gecko_metrics.mXSize)),
x_height: Some(Au(gecko_metrics.mXSize).into()),
zero_advance_measure: if gecko_metrics.mChSize >= 0 {
Some(Au(gecko_metrics.mChSize))
Some(Au(gecko_metrics.mChSize).into())
} else {
None
},
@ -988,7 +989,7 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
}
impl structs::FontSizePrefs {
fn size_for_generic(&self, font_family: GenericFontFamily) -> Au {
fn size_for_generic(&self, font_family: GenericFontFamily) -> Length {
Au(match font_family {
GenericFontFamily::None => self.mDefaultVariableSize,
GenericFontFamily::Serif => self.mDefaultSerifSize,
@ -999,7 +1000,7 @@ impl structs::FontSizePrefs {
GenericFontFamily::MozEmoji => unreachable!(
"Should never get here, since this doesn't (yet) appear on font family"
),
})
}).into()
}
}