Skip to content

Commit

Permalink
Merge per-property substitute_variables* functions into one.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 13, 2017
1 parent 3d3c196 commit 34c5a21
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 242 deletions.
181 changes: 86 additions & 95 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -315,115 +315,106 @@
context: &mut computed::Context,
cacheable: &mut bool,
cascade_info: &mut Option<<&mut CascadeInfo>) {
let declared_value = match *declaration {
let value = match *declaration {
PropertyDeclaration::${property.camel_case}(ref value) => {
DeclaredValue::Value(value)
},
PropertyDeclaration::CSSWideKeyword(id, value) => {
debug_assert!(id == LonghandId::${property.camel_case});
DeclaredValue::CSSWideKeyword(value)
},
PropertyDeclaration::WithVariables(id, ref value) => {
debug_assert!(id == LonghandId::${property.camel_case});
DeclaredValue::WithVariables(value)
},
PropertyDeclaration::WithVariables(..) => {
panic!("variables should already have been substituted")
}
_ => panic!("entered the wrong cascade_property() implementation"),
};

% if not property.derived_from:
{
let custom_props = context.style().custom_properties();
let quirks_mode = context.quirks_mode;
::properties::substitute_variables_${property.ident}(
&declared_value, &custom_props,
&mut |value| {
if let Some(ref mut cascade_info) = *cascade_info {
cascade_info.on_cascade_property(&declaration,
&value);
}
% if property.logical:
let wm = context.style.writing_mode;
% endif
<%
maybe_wm = ", wm" if property.logical else ""
maybe_cacheable = ", cacheable" if property.has_uncacheable_values == "True" else ""
props_need_device = "content list_style_type".split() if product == "gecko" else []
maybe_device = ", context.device" if property.ident in props_need_device else ""
%>
match *value {
DeclaredValue::Value(ref specified_value) => {
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
if let Some(sf) = specified_value.get_system() {
longhands::system_font::resolve_system_font(sf, context);
}
% endif
% if property.is_vector:
// In the case of a vector property we want to pass down
// an iterator so that this can be computed without allocation
//
// However, computing requires a context, but the style struct
// being mutated is on the context. We temporarily remove it,
// mutate it, and then put it back. Vector longhands cannot
// touch their own style struct whilst computing, else this will panic.
let mut s = context.mutate_style().take_${data.current_style_struct.name_lower}();
{
let iter = specified_value.compute_iter(context);
s.set_${property.ident}(iter ${maybe_cacheable});
}
context.mutate_style().put_${data.current_style_struct.name_lower}(s);
% else:
let computed = specified_value.to_computed_value(context);
% if property.ident == "font_size":
longhands::font_size::cascade_specified_font_size(context,
specified_value,
computed,
inherited_style.get_font());
% else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.set_${property.ident}(computed ${maybe_device}
${maybe_cacheable} ${maybe_wm});
% endif
% endif
if let Some(ref mut cascade_info) = *cascade_info {
cascade_info.on_cascade_property(&declaration,
&value);
}
% if property.logical:
let wm = context.style.writing_mode;
% endif
<%
maybe_wm = ", wm" if property.logical else ""
maybe_cacheable = ", cacheable" if property.has_uncacheable_values == "True" else ""
props_need_device = "content list_style_type".split() if product == "gecko" else []
maybe_device = ", context.device" if property.ident in props_need_device else ""
%>
match value {
DeclaredValue::Value(ref specified_value) => {
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
if let Some(sf) = specified_value.get_system() {
longhands::system_font::resolve_system_font(sf, context);
}
DeclaredValue::WithVariables(_) => unreachable!(),
DeclaredValue::CSSWideKeyword(keyword) => match keyword {
% if not data.current_style_struct.inherited:
CSSWideKeyword::Unset |
% endif
CSSWideKeyword::Initial => {
% if property.ident == "font_size":
longhands::font_size::cascade_initial_font_size(context);
% 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 |
% endif
CSSWideKeyword::Inherit => {
// This is a bit slow, but this is rare so it shouldn't
// matter.
//
// FIXME: is it still?
*cacheable = false;
let inherited_struct =
inherited_style.get_${data.current_style_struct.name_lower}();

% if property.ident == "font_size":
longhands::font_size::cascade_inherit_font_size(context, inherited_struct);
% else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
% endif
}
% endif
% if property.is_vector:
// In the case of a vector property we want to pass down
// an iterator so that this can be computed without allocation
//
// However, computing requires a context, but the style struct
// being mutated is on the context. We temporarily remove it,
// mutate it, and then put it back. Vector longhands cannot
// touch their own style struct whilst computing, else this will panic.
let mut s = context.mutate_style().take_${data.current_style_struct.name_lower}();
{
let iter = specified_value.compute_iter(context);
s.set_${property.ident}(iter ${maybe_cacheable});
}
context.mutate_style().put_${data.current_style_struct.name_lower}(s);
% else:
let computed = specified_value.to_computed_value(context);
% if property.ident == "font_size":
longhands::font_size::cascade_specified_font_size(context,
specified_value,
computed,
inherited_style.get_font());
% else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.set_${property.ident}(computed ${maybe_device}
${maybe_cacheable} ${maybe_wm});
% endif
% endif
}
DeclaredValue::WithVariables(_) => unreachable!(),
DeclaredValue::CSSWideKeyword(keyword) => match keyword {
% if not data.current_style_struct.inherited:
CSSWideKeyword::Unset |
% endif
CSSWideKeyword::Initial => {
% if property.ident == "font_size":
longhands::font_size::cascade_initial_font_size(context);
% 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 |
% endif
CSSWideKeyword::Inherit => {
// This is a bit slow, but this is rare so it shouldn't
// matter.
//
// FIXME: is it still?
*cacheable = false;
let inherited_struct =
inherited_style.get_${data.current_style_struct.name_lower}();

% if property.ident == "font_size":
longhands::font_size::cascade_inherit_font_size(context, inherited_struct);
% else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
% endif
}
}, quirks_mode);
}
}

% if property.custom_cascade:
Expand Down
37 changes: 3 additions & 34 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -524,7 +524,6 @@ impl AnimationValue {
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context,
initial: &ComputedValues) -> Option<Self> {
use properties::LonghandId;
use properties::DeclaredValue;

match *decl {
% for prop in data.longhands:
Expand Down Expand Up @@ -584,40 +583,10 @@ impl AnimationValue {
% endfor
}
},
PropertyDeclaration::WithVariables(id, ref variables) => {
PropertyDeclaration::WithVariables(id, ref unparsed) => {
let custom_props = context.style().custom_properties();
match id {
% for prop in data.longhands:
% if prop.animatable:
LonghandId::${prop.camel_case} => {
let mut result = None;
let quirks_mode = context.quirks_mode;
::properties::substitute_variables_${prop.ident}_slow(
&variables.css,
variables.first_token_type,
&variables.url_data,
variables.from_shorthand,
&custom_props,
&mut |v| {
let declaration = match *v {
DeclaredValue::Value(value) => {
PropertyDeclaration::${prop.camel_case}(value.clone())
},
DeclaredValue::CSSWideKeyword(keyword) => {
PropertyDeclaration::CSSWideKeyword(id, keyword)
},
DeclaredValue::WithVariables(_) => unreachable!(),
};
result = AnimationValue::from_declaration(&declaration, context, initial);
},
quirks_mode);
result
},
% else:
LonghandId::${prop.camel_case} => None,
% endif
% endfor
}
let substituted = unparsed.substitute_variables(id, &custom_props, context.quirks_mode);
AnimationValue::from_declaration(&substituted, context, initial)
},
_ => None // non animatable properties will get included because of shorthands. ignore.
}
Expand Down

0 comments on commit 34c5a21

Please sign in to comment.