mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Don't return a value from CSS variable substitution, and instead modify the style struct within the closure.
This commit is contained in:
parent
8db1ab240a
commit
16d2e9af65
1 changed files with 38 additions and 28 deletions
|
@ -168,27 +168,34 @@ pub mod longhands {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
seen.set_${property.ident}();
|
seen.set_${property.ident}();
|
||||||
let computed_value = ::properties::substitute_variables_${property.ident}(
|
|
||||||
declared_value, &context.style.custom_properties, |value| match *value {
|
{
|
||||||
|
let custom_props = context.style.custom_properties.clone();
|
||||||
|
::properties::substitute_variables_${property.ident}(
|
||||||
|
declared_value, &custom_props, |value| match *value {
|
||||||
DeclaredValue::Value(ref specified_value) => {
|
DeclaredValue::Value(ref specified_value) => {
|
||||||
specified_value.to_computed_value(&context)
|
Arc::make_mut(&mut context.style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||||
|
specified_value.to_computed_value(&context);
|
||||||
}
|
}
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
DeclaredValue::Initial => get_initial_value(),
|
DeclaredValue::Initial => {
|
||||||
|
Arc::make_mut(&mut context.style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||||
|
get_initial_value();
|
||||||
|
},
|
||||||
DeclaredValue::Inherit => {
|
DeclaredValue::Inherit => {
|
||||||
// This is a bit slow, but this is rare so it shouldn't
|
// This is a bit slow, but this is rare so it shouldn't
|
||||||
// matter.
|
// matter.
|
||||||
//
|
//
|
||||||
// FIXME: is it still?
|
// FIXME: is it still?
|
||||||
*cacheable = false;
|
*cacheable = false;
|
||||||
inherited_style.${THIS_STYLE_STRUCT.ident}
|
Arc::make_mut(&mut context.style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||||
.${property.ident}
|
inherited_style.${THIS_STYLE_STRUCT.ident}
|
||||||
.clone()
|
.${property.ident}
|
||||||
|
.clone();
|
||||||
}
|
}
|
||||||
}, error_reporter
|
}, error_reporter
|
||||||
);
|
);
|
||||||
Arc::make_mut(&mut context.style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
}
|
||||||
computed_value;
|
|
||||||
|
|
||||||
% if custom_cascade:
|
% if custom_cascade:
|
||||||
cascade_property_custom(declaration,
|
cascade_property_custom(declaration,
|
||||||
|
@ -5579,13 +5586,12 @@ mod property_bit_field {
|
||||||
% for property in LONGHANDS:
|
% for property in LONGHANDS:
|
||||||
% if property.derived_from is None:
|
% if property.derived_from is None:
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn substitute_variables_${property.ident}<F, R>(
|
fn substitute_variables_${property.ident}<F>(
|
||||||
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
||||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
f: F,
|
f: F,
|
||||||
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
||||||
-> R
|
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>)
|
||||||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
|
|
||||||
{
|
{
|
||||||
if let DeclaredValue::WithVariables {
|
if let DeclaredValue::WithVariables {
|
||||||
ref css, first_token_type, ref base_url, from_shorthand
|
ref css, first_token_type, ref base_url, from_shorthand
|
||||||
|
@ -5596,15 +5602,15 @@ mod property_bit_field {
|
||||||
from_shorthand,
|
from_shorthand,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
f,
|
f,
|
||||||
error_reporter)
|
error_reporter);
|
||||||
} else {
|
} else {
|
||||||
f(value)
|
f(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn substitute_variables_${property.ident}_slow<F, R>(
|
fn substitute_variables_${property.ident}_slow<F>(
|
||||||
css: &String,
|
css: &String,
|
||||||
first_token_type: TokenSerializationType,
|
first_token_type: TokenSerializationType,
|
||||||
base_url: &Url,
|
base_url: &Url,
|
||||||
|
@ -5612,9 +5618,7 @@ mod property_bit_field {
|
||||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
f: F,
|
f: F,
|
||||||
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
||||||
-> R
|
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) {
|
||||||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>)
|
|
||||||
-> R {
|
|
||||||
f(&
|
f(&
|
||||||
::custom_properties::substitute(css, first_token_type, custom_properties)
|
::custom_properties::substitute(css, first_token_type, custom_properties)
|
||||||
.and_then(|css| {
|
.and_then(|css| {
|
||||||
|
@ -5648,7 +5652,7 @@ mod property_bit_field {
|
||||||
// Invalid at computed-value time.
|
// Invalid at computed-value time.
|
||||||
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"}
|
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"}
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -6429,28 +6433,34 @@ fn cascade_with_cached_declarations(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen.set_${property.ident}();
|
seen.set_${property.ident}();
|
||||||
let computed_value =
|
let custom_props = context.style.custom_properties.clone();
|
||||||
substitute_variables_${property.ident}(
|
substitute_variables_${property.ident}(
|
||||||
declared_value, &context.style.custom_properties,
|
declared_value, &custom_props,
|
||||||
|value| match *value {
|
|value| match *value {
|
||||||
DeclaredValue::Value(ref specified_value)
|
DeclaredValue::Value(ref specified_value)
|
||||||
=> specified_value.to_computed_value(&context),
|
=> {
|
||||||
|
Arc::make_mut(&mut context.style.${style_struct.ident})
|
||||||
|
.${property.ident} = specified_value.to_computed_value(&context);
|
||||||
|
},
|
||||||
DeclaredValue::Initial
|
DeclaredValue::Initial
|
||||||
=> longhands::${property.ident}::get_initial_value(),
|
=> {
|
||||||
|
Arc::make_mut(&mut context.style.${style_struct.ident})
|
||||||
|
.${property.ident} =
|
||||||
|
longhands::${property.ident}::get_initial_value();
|
||||||
|
},
|
||||||
DeclaredValue::Inherit => {
|
DeclaredValue::Inherit => {
|
||||||
// This is a bit slow, but this is rare so it shouldn't
|
// This is a bit slow, but this is rare so it shouldn't
|
||||||
// matter.
|
// matter.
|
||||||
//
|
//
|
||||||
// FIXME: is it still?
|
// FIXME: is it still?
|
||||||
parent_style.${style_struct.ident}
|
Arc::make_mut(&mut context.style.${style_struct.ident})
|
||||||
.${property.ident}
|
.${property.ident} = parent_style.${style_struct.ident}
|
||||||
.clone()
|
.${property.ident}
|
||||||
|
.clone();
|
||||||
}
|
}
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||||
}, &mut error_reporter
|
}, &mut error_reporter
|
||||||
);
|
);
|
||||||
Arc::make_mut(&mut context.style.${style_struct.ident})
|
|
||||||
.${property.ident} = computed_value;
|
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
% if property.name in DERIVED_LONGHANDS:
|
% if property.name in DERIVED_LONGHANDS:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue