From 9dc25ed21462eeb8f9c286560b990072b56f7f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Jan 2018 10:48:53 +0100 Subject: [PATCH] style: Remove "derived" properties and the concept of "custom cascade". --- components/style/properties/data.py | 14 +- components/style/properties/helpers.mako.rs | 195 ++++++++---------- .../style/properties/properties.mako.rs | 19 +- 3 files changed, 98 insertions(+), 130 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 51ed2b88348..ac7f9e427f7 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -145,10 +145,10 @@ def arg_to_bool(arg): class Longhand(object): - def __init__(self, style_struct, name, spec=None, animation_value_type=None, derived_from=None, keyword=None, - predefined_type=None, custom_cascade=False, servo_pref=None, gecko_pref=None, + def __init__(self, style_struct, name, spec=None, animation_value_type=None, keyword=None, + predefined_type=None, servo_pref=None, gecko_pref=None, enabled_in="content", need_index=False, - custom_cascade_function=None, gecko_ffi_name=None, + gecko_ffi_name=None, allowed_in_keyframe_block=True, cast_type='u8', logical=False, alias=None, extra_prefixes=None, boxed=False, flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False, @@ -164,8 +164,6 @@ class Longhand(object): self.style_struct = style_struct self.servo_pref = servo_pref self.gecko_pref = gecko_pref - self.custom_cascade = custom_cascade - self.custom_cascade_function = custom_cascade_function if custom_cascade else None # For enabled_in, the setup is as follows: # It needs to be one of the four values: ["", "ua", "chrome", "content"] # * "chrome" implies "ua", and implies that they're explicitly @@ -177,7 +175,6 @@ class Longhand(object): self.enabled_in = enabled_in self.need_index = need_index self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case - self.derived_from = (derived_from or "").split() self.cast_type = cast_type self.logical = arg_to_bool(logical) self.alias = alias.split() if alias else [] @@ -241,7 +238,6 @@ class Shorthand(object): self.spec = spec self.ident = to_rust_ident(name) self.camel_case = to_camel_case(self.ident) - self.derived_from = None self.servo_pref = servo_pref self.gecko_pref = gecko_pref self.sub_properties = sub_properties @@ -365,7 +361,6 @@ class PropertiesData(object): self.current_style_struct = None self.longhands = [] self.longhands_by_name = {} - self.derived_longhands = {} self.longhand_aliases = [] self.shorthands = [] self.shorthand_aliases = [] @@ -397,9 +392,6 @@ class PropertiesData(object): self.longhands.append(longhand) self.longhands_by_name[name] = longhand - for name in longhand.derived_from: - self.derived_longhands.setdefault(name, []).append(longhand) - return longhand def declare_shorthand(self, name, sub_properties, products="gecko servo", *args, **kwargs): diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 5be81b59f88..becef724657 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -260,14 +260,12 @@ %> /// ${property.spec} pub mod ${property.ident} { - % if not property.derived_from: - #[allow(unused_imports)] - use cssparser::{Parser, BasicParseError, Token}; - #[allow(unused_imports)] - use parser::{Parse, ParserContext}; - #[allow(unused_imports)] - use properties::{UnparsedValue, ShorthandId}; - % endif + #[allow(unused_imports)] + use cssparser::{Parser, BasicParseError, Token}; + #[allow(unused_imports)] + use parser::{Parse, ParserContext}; + #[allow(unused_imports)] + use properties::{UnparsedValue, ShorthandId}; #[allow(unused_imports)] use values::{Auto, Either, None_, Normal}; #[allow(unused_imports)] @@ -319,106 +317,95 @@ Some(LonghandId::${property.camel_case}); % endif - % if not property.derived_from: - match value { - DeclaredValue::Value(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 not property.style_struct.inherited and property.logical: - context.rule_cache_conditions.borrow_mut() - .set_writing_mode_dependency(context.builder.writing_mode); - % 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.builder.take_${data.current_style_struct.name_lower}(); - { - let iter = specified_value.compute_iter(context); - s.set_${property.ident}(iter); - } - context.builder.put_${data.current_style_struct.name_lower}(s); - % else: - % if property.boxed: - let computed = (**specified_value).to_computed_value(context); - % else: - let computed = specified_value.to_computed_value(context); - % endif - % if property.ident == "font_size": - specified::FontSize::cascade_specified_font_size( - context, - &specified_value, - computed, - ); - % else: - context.builder.set_${property.ident}(computed) - % 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": - computed::FontSize::cascade_initial_font_size(context); - % else: - context.builder.reset_${property.ident}(); - % endif - }, - % if data.current_style_struct.inherited: - CSSWideKeyword::Unset | - % endif - CSSWideKeyword::Inherit => { - % if not property.style_struct.inherited: - context.rule_cache_conditions.borrow_mut().set_uncacheable(); - % endif - % if property.ident == "font_size": - computed::FontSize::cascade_inherit_font_size(context); - % else: - context.builder.inherit_${property.ident}(); - % endif + match value { + DeclaredValue::Value(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 not property.style_struct.inherited and property.logical: + context.rule_cache_conditions.borrow_mut() + .set_writing_mode_dependency(context.builder.writing_mode); + % 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.builder.take_${data.current_style_struct.name_lower}(); + { + let iter = specified_value.compute_iter(context); + s.set_${property.ident}(iter); + } + context.builder.put_${data.current_style_struct.name_lower}(s); + % else: + % if property.boxed: + let computed = (**specified_value).to_computed_value(context); + % else: + let computed = specified_value.to_computed_value(context); + % endif + % if property.ident == "font_size": + specified::FontSize::cascade_specified_font_size( + context, + &specified_value, + computed, + ); + % else: + context.builder.set_${property.ident}(computed) + % 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": + computed::FontSize::cascade_initial_font_size(context); + % else: + context.builder.reset_${property.ident}(); + % endif + }, + % if data.current_style_struct.inherited: + CSSWideKeyword::Unset | + % endif + CSSWideKeyword::Inherit => { + % if not property.style_struct.inherited: + context.rule_cache_conditions.borrow_mut().set_uncacheable(); + % endif + % if property.ident == "font_size": + computed::FontSize::cascade_inherit_font_size(context); + % else: + context.builder.inherit_${property.ident}(); + % endif } } - - % if property.custom_cascade and property.custom_cascade_function: - ${property.custom_cascade_function}(declaration, context); - % elif property.custom_cascade: - cascade_property_custom(declaration, context); - % endif - % else: - // Do not allow stylesheets to set derived properties. - % endif - } - % if not property.derived_from: - pub fn parse_declared<'i, 't>( - context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - % if property.allow_quirks: - parse_quirky(context, input, specified::AllowQuirks::Yes) - % else: - parse(context, input) - % endif - % if property.boxed: - .map(Box::new) - % endif - .map(PropertyDeclaration::${property.camel_case}) } - % endif + } + + pub fn parse_declared<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + % if property.allow_quirks: + parse_quirky(context, input, specified::AllowQuirks::Yes) + % else: + parse(context, input) + % endif + % if property.boxed: + .map(Box::new) + % endif + .map(PropertyDeclaration::${property.camel_case}) + } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 84be9763490..5cd5f78bc97 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -570,13 +570,7 @@ impl LonghandId { match *self { % for property in data.longhands: LonghandId::${property.camel_case} => { - % if not property.derived_from: - longhands::${property.ident}::parse_declared(context, input) - % else: - Err(input.new_custom_error( - StyleParseErrorKind::UnknownProperty("${property.ident}".into()) - )) - % endif + longhands::${property.ident}::parse_declared(context, input) } % endfor } @@ -1454,10 +1448,8 @@ impl ToCss for PropertyDeclaration { { match *self { % for property in data.longhands: - % if not property.derived_from: - PropertyDeclaration::${property.camel_case}(ref value) => - value.to_css(dest), - % endif + PropertyDeclaration::${property.camel_case}(ref value) => + value.to_css(dest), % endfor PropertyDeclaration::CSSWideKeyword(_, keyword) => keyword.to_css(dest), PropertyDeclaration::WithVariables(_, ref with_variables) => { @@ -1474,9 +1466,6 @@ impl ToCss for PropertyDeclaration { Ok(()) }, PropertyDeclaration::Custom(_, ref value) => value.borrow().to_css(dest), - % if any(property.derived_from for property in data.longhands): - _ => Err(fmt::Error), - % endif } } } @@ -3653,7 +3642,7 @@ macro_rules! css_properties_accessors { $macro_name! { % for kind, props in [("Longhand", data.longhands), ("Shorthand", data.shorthands)]: % for property in props: - % if not property.derived_from and property.enabled_in_content(): + % if property.enabled_in_content(): % for name in [property.name] + property.alias: % if '-' in name: [${to_rust_ident(name).capitalize()}, Set${to_rust_ident(name).capitalize()},