Auto merge of #16122 - Manishearth:stylo-font-size, r=heycam

stylo: Handle font-size keywords correctly

r=heycam https://bugzilla.mozilla.org/show_bug.cgi?id=1341775

<!-- 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/16122)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-24 12:30:10 -07:00 committed by GitHub
commit 1584bbd3ec
9 changed files with 238 additions and 33 deletions

View file

@ -1502,6 +1502,8 @@ pub struct ComputedValues {
pub writing_mode: WritingMode,
/// The root element's computed font size.
pub root_font_size: Au,
/// The keyword behind the current font-size property, if any
pub font_size_keyword: Option<longhands::font_size::KeywordSize>,
}
#[cfg(feature = "servo")]
@ -1511,6 +1513,7 @@ impl ComputedValues {
shareable: bool,
writing_mode: WritingMode,
root_font_size: Au,
font_size_keyword: Option<longhands::font_size::KeywordSize>,
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
@ -1520,6 +1523,7 @@ impl ComputedValues {
shareable: shareable,
writing_mode: writing_mode,
root_font_size: root_font_size,
font_size_keyword: font_size_keyword,
% for style_struct in data.active_style_structs():
${style_struct.ident}: ${style_struct.ident},
% endfor
@ -1843,6 +1847,7 @@ mod lazy_static_module {
shareable: true,
writing_mode: WritingMode::empty(),
root_font_size: longhands::font_size::get_initial_value(),
font_size_keyword: Some(Default::default()),
};
}
}
@ -1985,6 +1990,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
flags.contains(SHAREABLE),
WritingMode::empty(),
inherited_style.root_font_size,
inherited_style.font_size_keyword,
% for style_struct in data.active_style_structs():
% if style_struct.inherited:
inherited_style.clone_${style_struct.name_lower}(),
@ -1998,6 +2004,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
flags.contains(SHAREABLE),
WritingMode::empty(),
inherited_style.root_font_size,
inherited_style.font_size_keyword,
% for style_struct in data.active_style_structs():
inherited_style.clone_${style_struct.name_lower}(),
% endfor
@ -2030,6 +2037,13 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
// To improve i-cache behavior, we outline the individual functions and use
// virtual dispatch instead.
% for category_to_cascade_now in ["early", "other"]:
% if category_to_cascade_now == "early":
// Pull these out so that we can
// compute them in a specific order without
// introducing more iterations
let mut font_size = None;
let mut font_family = None;
% endif
for declaration in iter_declarations() {
let longhand_id = match declaration.id() {
PropertyDeclarationId::Longhand(id) => id,
@ -2076,6 +2090,17 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
}
seen.insert(physical_longhand_id);
% if category_to_cascade_now == "early":
if LonghandId::FontSize == longhand_id {
font_size = Some(declaration);
continue;
}
if LonghandId::FontFamily == longhand_id {
font_family = Some(declaration);
continue;
}
% endif
let discriminant = longhand_id as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
@ -2088,6 +2113,51 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
% if category_to_cascade_now == "early":
let writing_mode = get_writing_mode(context.style.get_inheritedbox());
context.style.writing_mode = writing_mode;
// It is important that font_size is computed before
// the late properties (for em units), but after font-family
// (for the base-font-size dependence for default and keyword font-sizes)
// Additionally, when we support system fonts they will have to be
// computed early, and *before* font_family, so I'm including
// font_family here preemptively instead of keeping it within
// the early properties.
//
// To avoid an extra iteration, we just pull out the property
// during the early iteration and cascade them in order
// after it.
if let Some(declaration) = font_family {
let discriminant = LonghandId::FontFamily as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
default_style,
&mut context,
&mut cacheable,
&mut cascade_info,
error_reporter);
}
if let Some(declaration) = font_size {
let discriminant = LonghandId::FontSize as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
default_style,
&mut context,
&mut cacheable,
&mut cascade_info,
error_reporter);
} else if let Some(kw) = inherited_style.font_size_keyword {
// Font size keywords will inherit as keywords and be recomputed
// each time.
let discriminant = LonghandId::FontSize as usize;
let size = PropertyDeclaration::FontSize(
longhands::font_size::SpecifiedValue::Keyword(kw)
);
(CASCADE_PROPERTY[discriminant])(&size,
inherited_style,
default_style,
&mut context,
&mut cacheable,
&mut cascade_info,
error_reporter);
}
% endif
% endfor