style: Handle properly potentially-disabled longhands in a shorthand.

This commit is contained in:
Emilio Cobos Álvarez 2018-02-28 00:43:54 +01:00
parent 15b0a32035
commit 3fd5f796f0
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 24 additions and 1 deletions

View file

@ -229,6 +229,11 @@ class Longhand(object):
def enabled_in_content(self):
return self.enabled_in == "content"
def may_be_disabled_in(self, shorthand, product):
if product == "gecko":
return self.gecko_pref and self.gecko_pref != shorthand.gecko_pref
return self.servo_pref and self.servo_pref != shorthand.servo_pref
def base_type(self):
if self.predefined_type and not self.is_vector:
return "::values::specified::{}".format(self.predefined_type)

View file

@ -688,7 +688,13 @@
pub struct LonghandsToSerialize<'a> {
% for sub_property in shorthand.sub_properties:
pub ${sub_property.ident}:
% if sub_property.may_be_disabled_in(shorthand, product):
Option<
% endif
&'a longhands::${sub_property.ident}::SpecifiedValue,
% if sub_property.may_be_disabled_in(shorthand, product):
>,
% endif
% endfor
}
@ -725,12 +731,16 @@
(
% for sub_property in shorthand.sub_properties:
% if sub_property.may_be_disabled_in(shorthand, product):
${sub_property.ident},
% else:
Some(${sub_property.ident}),
% endif
% endfor
) =>
Ok(LonghandsToSerialize {
% for sub_property in shorthand.sub_properties:
${sub_property.ident}: ${sub_property.ident},
${sub_property.ident},
% endfor
}),
_ => Err(())
@ -745,11 +755,19 @@
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<(), ParseError<'i>> {
#[allow(unused_imports)]
use properties::{NonCustomPropertyId, LonghandId};
input.parse_entirely(|input| parse_value(context, input)).map(|longhands| {
% for sub_property in shorthand.sub_properties:
% if sub_property.may_be_disabled_in(shorthand, product):
if NonCustomPropertyId::from(LonghandId::${sub_property.camel_case}).allowed_in(context) {
% endif
declarations.push(PropertyDeclaration::${sub_property.camel_case}(
longhands.${sub_property.ident}
));
% if sub_property.may_be_disabled_in(shorthand, product):
}
% endif
% endfor
})
}