stylo: Special-case initial-computation of font-size

MozReview-Commit-ID: Ff6kt8RLChI
This commit is contained in:
Manish Goregaokar 2017-03-17 19:48:20 -07:00 committed by Manish Goregaokar
parent fddddc9711
commit 3139a90386
4 changed files with 67 additions and 13 deletions

View file

@ -80,6 +80,7 @@ pub struct ComputedValues {
shareable: bool,
pub writing_mode: WritingMode,
pub root_font_size: Au,
pub font_size_keyword: Option<longhands::font_size::KeywordSize>,
}
impl ComputedValues {
@ -89,6 +90,7 @@ impl ComputedValues {
shareable: parent.shareable,
writing_mode: parent.writing_mode,
root_font_size: parent.root_font_size,
font_size_keyword: parent.font_size_keyword,
% for style_struct in data.style_structs:
% if style_struct.inherited:
${style_struct.ident}: parent.${style_struct.ident}.clone(),
@ -103,6 +105,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.style_structs:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
@ -112,6 +115,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.style_structs:
${style_struct.ident}: ${style_struct.ident},
% endfor
@ -124,6 +128,7 @@ impl ComputedValues {
shareable: true,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
font_size_keyword: Some(Default::default()),
% for style_struct in data.style_structs:
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
% endfor

View file

@ -266,6 +266,13 @@
match *value {
DeclaredValue::Value(ref specified_value) => {
let computed = specified_value.to_computed_value(context);
% if property.ident == "font_size":
if let longhands::font_size::SpecifiedValue::Keyword(kw) = **specified_value {
context.mutate_style().font_size_keyword = Some(kw);
} else {
context.mutate_style().font_size_keyword = None;
}
% endif
% if property.has_uncacheable_values:
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.set_${property.ident}(computed, cacheable ${maybe_wm});
@ -280,12 +287,22 @@
CSSWideKeyword::Unset |
% endif
CSSWideKeyword::Initial => {
// We assume that it's faster to use copy_*_from rather than
// set_*(get_initial_value());
let initial_struct = default_style
.get_${data.current_style_struct.name_lower}();
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(initial_struct ${maybe_wm});
% if property.ident == "font_size":
// font-size's default ("medium") does not always
// compute to the same value and depends on the font
let computed = longhands::font_size::get_initial_specified_value()
.to_computed_value(context);
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.set_font_size(computed);
context.mutate_style().font_size_keyword = Some(Default::default());
% else:
// We assume that it's faster to use copy_*_from rather than
// set_*(get_initial_value());
let initial_struct = default_style
.get_${data.current_style_struct.name_lower}();
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(initial_struct ${maybe_wm});
% endif
},
% if data.current_style_struct.inherited:
CSSWideKeyword::Unset |
@ -300,6 +317,10 @@
inherited_style.get_${data.current_style_struct.name_lower}();
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
% if property.ident == "font_size":
context.mutate_style().font_size_keyword =
context.inherited_style.font_size_keyword;
% endif
}
}
}

View file

@ -465,6 +465,12 @@ ${helpers.single_keyword("font-variant-caps",
}
}
impl Default for KeywordSize {
fn default() -> Self {
Medium
}
}
impl ToCss for KeywordSize {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(match *self {

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
@ -2075,6 +2082,14 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
{
continue
}
<% maybe_to_physical = ".to_physical(writing_mode)" if category_to_cascade_now != "early" else "" %>
let physical_longhand_id = longhand_id ${maybe_to_physical};
if seen.contains(physical_longhand_id) {
continue
}
seen.insert(physical_longhand_id);
% if category_to_cascade_now == "early":
if LonghandId::FontSize == longhand_id {
font_size = Some(declaration);
@ -2086,13 +2101,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
}
% endif
<% maybe_to_physical = ".to_physical(writing_mode)" if category_to_cascade_now != "early" else "" %>
let physical_longhand_id = longhand_id ${maybe_to_physical};
if seen.contains(physical_longhand_id) {
continue
}
seen.insert(physical_longhand_id);
let discriminant = longhand_id as usize;
(CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
@ -2135,6 +2143,20 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
&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