diff --git a/components/style/properties/build.py b/components/style/properties/build.py index c20cac95cb45..cee204558716 100644 --- a/components/style/properties/build.py +++ b/components/style/properties/build.py @@ -70,13 +70,17 @@ def write(directory, filename, content): open(os.path.join(directory, filename), "wb").write(content) +def static_id_generator(properties): + for kind, props in [("Longhand", properties.longhands), + ("Shorthand", properties.shorthands)]: + for p in props: + yield "%s\tStaticId::%s(%sId::%s)" % (p.name, kind, kind, p.camel_case) + for alias in p.alias: + yield "%s\tStaticId::%s(%sId::%s)" % (alias, kind, kind, p.camel_case) + + def static_ids(properties): - return '\n'.join( - "%s\tStaticId::%s(%sId::%s)" % (p.name, kind, kind, p.camel_case) - for kind, props in [("Longhand", properties.longhands), - ("Shorthand", properties.shorthands)] - for p in props - ) + return '\n'.join(static_id_generator(properties)) def write_html(properties): diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 9ee8c08cf182..bbef9df1c4e3 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -88,7 +88,7 @@ def __init__(self, style_struct, name, spec=None, animatable=None, derived_from= predefined_type=None, custom_cascade=False, experimental=False, internal=False, need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, allowed_in_keyframe_block=True, complex_color=False, cast_type='u8', - has_uncacheable_values=False, logical=False): + has_uncacheable_values=False, logical=False, alias=None): self.name = name if not spec: raise TypeError("Spec should be specified for %s" % name) @@ -109,6 +109,7 @@ def __init__(self, style_struct, name, spec=None, animatable=None, derived_from= self.complex_color = complex_color self.cast_type = cast_type self.logical = arg_to_bool(logical) + self.alias = alias.split() if alias else [] # https://drafts.csswg.org/css-animations/#keyframes # > The inside of accepts any CSS property @@ -134,7 +135,7 @@ def __init__(self, style_struct, name, spec=None, animatable=None, derived_from= class Shorthand(object): def __init__(self, name, sub_properties, spec=None, experimental=False, internal=False, - allowed_in_keyframe_block=True): + allowed_in_keyframe_block=True, alias=None): self.name = name if not spec: raise TypeError("Spec should be specified for %s" % name) @@ -145,6 +146,7 @@ def __init__(self, name, sub_properties, spec=None, experimental=False, internal self.experimental = ("layout.%s.enabled" % name) if experimental else None self.sub_properties = sub_properties self.internal = internal + self.alias = alias.split() if alias else [] # https://drafts.csswg.org/css-animations/#keyframes # > The inside of accepts any CSS property diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 32e5c91b7d09..e40d8e31e3f5 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -170,7 +170,8 @@ ${helpers.single_keyword("overflow-wrap", "normal break-word", gecko_constant_prefix="NS_STYLE_OVERFLOWWRAP", animatable=False, - spec="https://drafts.csswg.org/css-text/#propdef-overflow-wrap")} + spec="https://drafts.csswg.org/css-text/#propdef-overflow-wrap", + alias="word-wrap")} // TODO(pcwalton): Support `word-break: keep-all` once we have better CJK support. ${helpers.single_keyword("word-break", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 77175707ef28..138558ae4963 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -48,7 +48,7 @@ macro_rules! property_name { } <%! - from data import Method, Keyword, to_rust_ident + from data import Method, Keyword, to_rust_ident, to_camel_case import os.path %> @@ -758,24 +758,33 @@ impl PropertyId { pub fn from_nscsspropertyid(id: nsCSSPropertyID) -> Result { use gecko_bindings::structs::*; <% + def alias_to_nscsspropertyid(alias): + return "nsCSSPropertyID_eCSSPropertyAlias_%s" % to_camel_case(alias) def to_nscsspropertyid(ident): - if ident == "word_wrap": - return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap" - if ident == "float": ident = "float_" - return "nsCSSPropertyID::eCSSProperty_" + ident + return "nsCSSPropertyID::eCSSProperty_%s" % ident %> match id { % for property in data.longhands: ${to_nscsspropertyid(property.ident)} => { Ok(PropertyId::Longhand(LonghandId::${property.camel_case})) } + % for alias in property.alias: + ${alias_to_nscsspropertyid(alias)} => { + Ok(PropertyId::Longhand(LonghandId::${property.camel_case})) + } + % endfor % endfor % for property in data.shorthands: ${to_nscsspropertyid(property.ident)} => { Ok(PropertyId::Shorthand(ShorthandId::${property.camel_case})) } + % for alias in property.alias: + ${alias_to_nscsspropertyid(alias)} => { + Ok(PropertyId::Longhand(LonghandId::${property.camel_case})) + } + % endfor % endfor _ => Err(()) } @@ -2223,12 +2232,14 @@ macro_rules! css_properties_accessors { % for kind, props in [("Longhand", data.longhands), ("Shorthand", data.shorthands)]: % for property in props: % if not property.derived_from and not property.internal: - % if '-' in property.name: - [${property.ident.capitalize()}, Set${property.ident.capitalize()}, + % for name in [property.name] + property.alias: + % if '-' in name: + [${to_rust_ident(name).capitalize()}, Set${to_rust_ident(name).capitalize()}, + PropertyId::${kind}(${kind}Id::${property.camel_case})], + % endif + [${to_camel_case(name)}, Set${to_camel_case(name)}, PropertyId::${kind}(${kind}Id::${property.camel_case})], - % endif - [${property.camel_case}, Set${property.camel_case}, - PropertyId::${kind}(${kind}Id::${property.camel_case})], + % endfor % endif % endfor % endfor diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index fe5fe298f490..38789c5275e1 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -4,25 +4,6 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -// Per CSS-TEXT 6.2, "for legacy reasons, UAs must treat `word-wrap` as an alternate name for -// the `overflow-wrap` property, as if it were a shorthand of `overflow-wrap`." -<%helpers:shorthand name="word-wrap" sub_properties="overflow-wrap" - spec="https://drafts.csswg.org/css-text/#propdef-word-wrap"> - use properties::longhands::overflow_wrap; - - pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { - Ok(Longhands { - overflow_wrap: Some(try!(overflow_wrap::parse(context, input))), - }) - } - - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.overflow_wrap.to_css(dest) - } - } - - <%helpers:shorthand name="text-emphasis" products="gecko" sub_properties="text-emphasis-color text-emphasis-style" spec="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-property"> diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 21e490a86c1e..8a3ed9bfa854 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -457,24 +457,6 @@ mod shorthand_serialization { } } - #[test] - fn overflow_wrap_should_only_serialize_with_a_single_property() { - use style::properties::longhands::overflow_wrap::computed_value::T as OverflowWrap; - - let value = DeclaredValue::Value(OverflowWrap::break_word); - - let properties = vec![ - PropertyDeclaration::OverflowWrap(value) - ]; - - let serialization = shorthand_properties_to_string(properties); - - // word-wrap is considered an outdated alternative to overflow-wrap, but it is currently - // what servo is using in its naming conventions: - // https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap - assert_eq!(serialization, "word-wrap: break-word;"); - } - mod outline { use style::properties::longhands::outline_width::SpecifiedValue as WidthContainer; use super::*;