mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
stylo: Special-case initial-computation of font-size
MozReview-Commit-ID: Ff6kt8RLChI
This commit is contained in:
parent
fddddc9711
commit
3139a90386
4 changed files with 67 additions and 13 deletions
|
@ -80,6 +80,7 @@ pub struct ComputedValues {
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
pub root_font_size: Au,
|
pub root_font_size: Au,
|
||||||
|
pub font_size_keyword: Option<longhands::font_size::KeywordSize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputedValues {
|
impl ComputedValues {
|
||||||
|
@ -89,6 +90,7 @@ impl ComputedValues {
|
||||||
shareable: parent.shareable,
|
shareable: parent.shareable,
|
||||||
writing_mode: parent.writing_mode,
|
writing_mode: parent.writing_mode,
|
||||||
root_font_size: parent.root_font_size,
|
root_font_size: parent.root_font_size,
|
||||||
|
font_size_keyword: parent.font_size_keyword,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
% if style_struct.inherited:
|
% if style_struct.inherited:
|
||||||
${style_struct.ident}: parent.${style_struct.ident}.clone(),
|
${style_struct.ident}: parent.${style_struct.ident}.clone(),
|
||||||
|
@ -103,6 +105,7 @@ impl ComputedValues {
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
root_font_size: Au,
|
root_font_size: Au,
|
||||||
|
font_size_keyword: Option<longhands::font_size::KeywordSize>,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -112,6 +115,7 @@ impl ComputedValues {
|
||||||
shareable: shareable,
|
shareable: shareable,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
root_font_size: root_font_size,
|
root_font_size: root_font_size,
|
||||||
|
font_size_keyword: font_size_keyword,
|
||||||
% for style_struct in data.style_structs:
|
% for style_struct in data.style_structs:
|
||||||
${style_struct.ident}: ${style_struct.ident},
|
${style_struct.ident}: ${style_struct.ident},
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -124,6 +128,7 @@ impl ComputedValues {
|
||||||
shareable: true,
|
shareable: true,
|
||||||
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||||
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also 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:
|
% for style_struct in data.style_structs:
|
||||||
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
|
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
|
||||||
% endfor
|
% endfor
|
||||||
|
|
|
@ -266,6 +266,13 @@
|
||||||
match *value {
|
match *value {
|
||||||
DeclaredValue::Value(ref specified_value) => {
|
DeclaredValue::Value(ref specified_value) => {
|
||||||
let computed = specified_value.to_computed_value(context);
|
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:
|
% if property.has_uncacheable_values:
|
||||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||||
.set_${property.ident}(computed, cacheable ${maybe_wm});
|
.set_${property.ident}(computed, cacheable ${maybe_wm});
|
||||||
|
@ -280,12 +287,22 @@
|
||||||
CSSWideKeyword::Unset |
|
CSSWideKeyword::Unset |
|
||||||
% endif
|
% endif
|
||||||
CSSWideKeyword::Initial => {
|
CSSWideKeyword::Initial => {
|
||||||
// We assume that it's faster to use copy_*_from rather than
|
% if property.ident == "font_size":
|
||||||
// set_*(get_initial_value());
|
// font-size's default ("medium") does not always
|
||||||
let initial_struct = default_style
|
// compute to the same value and depends on the font
|
||||||
.get_${data.current_style_struct.name_lower}();
|
let computed = longhands::font_size::get_initial_specified_value()
|
||||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
.to_computed_value(context);
|
||||||
.copy_${property.ident}_from(initial_struct ${maybe_wm});
|
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:
|
% if data.current_style_struct.inherited:
|
||||||
CSSWideKeyword::Unset |
|
CSSWideKeyword::Unset |
|
||||||
|
@ -300,6 +317,10 @@
|
||||||
inherited_style.get_${data.current_style_struct.name_lower}();
|
inherited_style.get_${data.current_style_struct.name_lower}();
|
||||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||||
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
|
.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,6 +465,12 @@ ${helpers.single_keyword("font-variant-caps",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for KeywordSize {
|
||||||
|
fn default() -> Self {
|
||||||
|
Medium
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToCss for KeywordSize {
|
impl ToCss for KeywordSize {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
dest.write_str(match *self {
|
dest.write_str(match *self {
|
||||||
|
|
|
@ -1502,6 +1502,8 @@ pub struct ComputedValues {
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
/// The root element's computed font size.
|
/// The root element's computed font size.
|
||||||
pub root_font_size: Au,
|
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")]
|
#[cfg(feature = "servo")]
|
||||||
|
@ -1511,6 +1513,7 @@ impl ComputedValues {
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
root_font_size: Au,
|
root_font_size: Au,
|
||||||
|
font_size_keyword: Option<longhands::font_size::KeywordSize>,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -1520,6 +1523,7 @@ impl ComputedValues {
|
||||||
shareable: shareable,
|
shareable: shareable,
|
||||||
writing_mode: writing_mode,
|
writing_mode: writing_mode,
|
||||||
root_font_size: root_font_size,
|
root_font_size: root_font_size,
|
||||||
|
font_size_keyword: font_size_keyword,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
${style_struct.ident}: ${style_struct.ident},
|
${style_struct.ident}: ${style_struct.ident},
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -1843,6 +1847,7 @@ mod lazy_static_module {
|
||||||
shareable: true,
|
shareable: true,
|
||||||
writing_mode: WritingMode::empty(),
|
writing_mode: WritingMode::empty(),
|
||||||
root_font_size: longhands::font_size::get_initial_value(),
|
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),
|
flags.contains(SHAREABLE),
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
inherited_style.root_font_size,
|
inherited_style.root_font_size,
|
||||||
|
inherited_style.font_size_keyword,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
% if style_struct.inherited:
|
% if style_struct.inherited:
|
||||||
inherited_style.clone_${style_struct.name_lower}(),
|
inherited_style.clone_${style_struct.name_lower}(),
|
||||||
|
@ -1998,6 +2004,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
flags.contains(SHAREABLE),
|
flags.contains(SHAREABLE),
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
inherited_style.root_font_size,
|
inherited_style.root_font_size,
|
||||||
|
inherited_style.font_size_keyword,
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
inherited_style.clone_${style_struct.name_lower}(),
|
inherited_style.clone_${style_struct.name_lower}(),
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -2075,6 +2082,14 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
{
|
{
|
||||||
continue
|
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 category_to_cascade_now == "early":
|
||||||
if LonghandId::FontSize == longhand_id {
|
if LonghandId::FontSize == longhand_id {
|
||||||
font_size = Some(declaration);
|
font_size = Some(declaration);
|
||||||
|
@ -2086,13 +2101,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
}
|
}
|
||||||
% endif
|
% 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;
|
let discriminant = longhand_id as usize;
|
||||||
(CASCADE_PROPERTY[discriminant])(declaration,
|
(CASCADE_PROPERTY[discriminant])(declaration,
|
||||||
inherited_style,
|
inherited_style,
|
||||||
|
@ -2135,6 +2143,20 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
&mut cacheable,
|
&mut cacheable,
|
||||||
&mut cascade_info,
|
&mut cascade_info,
|
||||||
error_reporter);
|
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
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue