style: Make all font-metrics-affecting properties cascade early.

And make font-size computation work on the whole font of the parent, not just
accounting for the parent's font-size.

Differential Revision: https://phabricator.services.mozilla.com/D20656
This commit is contained in:
Emilio Cobos Álvarez 2019-03-18 16:27:54 +00:00
parent aa5ea337da
commit d3f254d2e4
4 changed files with 36 additions and 38 deletions

View file

@ -58,10 +58,8 @@ use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use crate::global_style_data::GLOBAL_STYLE_DATA;
use crate::hash::FxHashMap;
use crate::invalidation::element::restyle_hints::RestyleHint;
use crate::logical_geometry::WritingMode;
use crate::media_queries::Device;
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
use crate::properties::style_structs::Font;
use crate::properties::{ComputedValues, LonghandId};
use crate::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock};
use crate::rule_tree::CascadeLevel as ServoCascadeLevel;
@ -69,6 +67,7 @@ use crate::selector_parser::{AttrValue, HorizontalDirection, Lang};
use crate::shared_lock::Locked;
use crate::string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use crate::stylist::CascadeData;
use crate::values::specified::length::FontBaseSize;
use crate::CaseSensitivityExt;
use app_units::Au;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
@ -1023,37 +1022,48 @@ impl FontMetricsProvider for GeckoFontMetricsProvider {
}
fn get_size(&self, font_name: &Atom, font_family: u8) -> Au {
use crate::gecko_bindings::bindings::Gecko_GetBaseSize;
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);
}
let sizes = unsafe { Gecko_GetBaseSize(font_name.as_ptr()) };
let sizes = unsafe { bindings::Gecko_GetBaseSize(font_name.as_ptr()) };
cache.push((font_name.clone(), sizes));
sizes.size_for_generic(font_family)
}
fn query(
&self,
font: &Font,
font_size: Au,
wm: WritingMode,
in_media_query: bool,
device: &Device,
context: &crate::values::computed::Context,
base_size: FontBaseSize,
) -> FontMetricsQueryResult {
use crate::gecko_bindings::bindings::Gecko_GetFontMetrics;
let pc = match device.pres_context() {
let pc = match context.device().pres_context() {
Some(pc) => pc,
None => return FontMetricsQueryResult::NotAvailable,
};
let size = base_size.resolve(context);
let style = context.style();
let (wm, font) = match base_size {
FontBaseSize::CurrentStyle => {
(style.writing_mode, style.get_font())
},
// These are only used for font-size computation, and the first is
// really dubious...
FontBaseSize::InheritedStyleButStripEmUnits |
FontBaseSize::InheritedStyle => {
(*style.inherited_writing_mode(), style.get_parent_font())
},
};
let gecko_metrics = unsafe {
Gecko_GetFontMetrics(
bindings::Gecko_GetFontMetrics(
pc,
wm.is_vertical() && !wm.is_sideways(),
font.gecko(),
font_size.0,
size.0,
// we don't use the user font set in a media query
!in_media_query,
!context.in_media_query,
)
};
let metrics = FontMetrics {