diff --git a/components/style/properties/data.py b/components/style/properties/data.py index a54bd6c25ae..7b5a791de90 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -47,7 +47,7 @@ class Keyword(object): class Longhand(object): def __init__(self, style_struct, name, derived_from=None, keyword=None, custom_cascade=False, experimental=False, internal=False, - gecko_ffi_name=None): + need_clone=False, gecko_ffi_name=None): self.name = name self.keyword = keyword self.ident = to_rust_ident(name) @@ -56,6 +56,7 @@ class Longhand(object): self.experimental = ("layout.%s.enabled" % name) if experimental else None self.custom_cascade = custom_cascade self.internal = internal + self.need_clone = need_clone self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case self.derived_from = (derived_from or "").split() diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 9b89fa282b8..039c1fdbb9c 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -9,15 +9,13 @@ <% data.new_style_struct("Box", inherited=False, gecko_ffi_name="nsStyleDisplay", - additional_methods=[Method("clone_display", "longhands::display::computed_value::T"), - Method("clone_position", "longhands::position::computed_value::T"), - Method("is_floated", "bool"), + additional_methods=[Method("is_floated", "bool"), Method("overflow_x_is_visible", "bool"), Method("overflow_y_is_visible", "bool"), Method("transition_count", "usize")]) %> // TODO(SimonSapin): don't parse `inline-table`, since we don't support it -<%helpers:longhand name="display" custom_cascade="${product == 'servo'}"> +<%helpers:longhand name="display" need_clone="True" custom_cascade="${product == 'servo'}"> <% values = """inline block inline-block table inline-table table-row-group table-header-group table-footer-group @@ -89,7 +87,7 @@ -${helpers.single_keyword("position", "static absolute relative fixed", extra_gecko_values="sticky")} +${helpers.single_keyword("position", "static absolute relative fixed", need_clone=True, extra_gecko_values="sticky")} <%helpers:single_keyword_computed name="float" values="none left right" gecko_ffi_name="mFloats"> impl ToComputedValue for SpecifiedValue { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 0868b23f91c..afe5cb01487 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -54,15 +54,9 @@ pub mod longhands { <%include file="/longhand/padding.mako.rs" /> <%include file="/longhand/position.mako.rs" /> - <% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility", - additional_methods=[Method("clone_direction", - "longhands::direction::computed_value::T"), - Method("clone_writing_mode", - "longhands::writing_mode::computed_value::T"), - Method("clone_text_orientation", - "longhands::text_orientation::computed_value::T")]) %> + <% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility") %> - ${helpers.single_keyword("direction", "ltr rtl")} + ${helpers.single_keyword("direction", "ltr rtl", need_clone=True)} // CSS 2.1, Section 10 - Visual formatting model details @@ -92,10 +86,7 @@ pub mod longhands { "computed::LengthOrPercentageOrNone::None", "parse_non_negative")} - <% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText", - additional_methods=([Method("clone__servo_text_decorations_in_effect", - "longhands::_servo_text_decorations_in_effect::computed_value::T")] - if product == "servo" else [])) %> + <% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText") %> <%helpers:longhand name="line-height"> use cssparser::ToCss; @@ -1076,11 +1067,9 @@ pub mod longhands { } - <% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor", - additional_methods=[Method("clone_color", - "longhands::color::computed_value::T")]) %> + <% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor") %> - <%helpers:raw_longhand name="color"> + <%helpers:raw_longhand name="color" need_clone="True"> use cssparser::Color as CSSParserColor; use cssparser::RGBA; use values::specified::{CSSColor, CSSRGBA}; @@ -1119,12 +1108,7 @@ pub mod longhands { // CSS 2.1, Section 15 - Fonts <% data.new_style_struct("Font", inherited=True, gecko_ffi_name="nsStyleFont", - additional_methods=[Method("clone_font_size", - "longhands::font_size::computed_value::T"), - Method("clone_font_weight", - "longhands::font_weight::computed_value::T"), - Method("compute_font_hash", is_mut=True)]) %> - + additional_methods=[Method("compute_font_hash", is_mut=True)]) %> <%helpers:longhand name="font-family"> use self::computed_value::FontFamily; use values::computed::ComputedValueAsSpecified; @@ -1238,7 +1222,7 @@ pub mod longhands { ${helpers.single_keyword("font-style", "normal italic oblique")} ${helpers.single_keyword("font-variant", "normal small-caps")} - <%helpers:longhand name="font-weight"> + <%helpers:longhand name="font-weight" need_clone="True"> use cssparser::ToCss; use std::fmt; @@ -1356,7 +1340,7 @@ pub mod longhands { } - <%helpers:longhand name="font-size"> + <%helpers:longhand name="font-size" need_clone="True"> use app_units::Au; use cssparser::ToCss; use std::fmt; @@ -1724,7 +1708,7 @@ pub mod longhands { <% data.switch_to_style_struct("InheritedText") %> <%helpers:longhand name="-servo-text-decorations-in-effect" - derived_from="display text-decoration" products="servo"> + derived_from="display text-decoration" need_clone="True" products="servo"> use cssparser::{RGBA, ToCss}; use std::fmt; @@ -1970,11 +1954,13 @@ pub mod longhands { // http://dev.w3.org/csswg/css-writing-modes/ <% data.switch_to_style_struct("InheritedBox") %> - ${helpers.single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr", experimental=True)} + ${helpers.single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr", + experimental=True, need_clone=True)} // FIXME(SimonSapin): Add 'mixed' and 'upright' (needs vertical text support) // FIXME(SimonSapin): initial (first) value should be 'mixed', when that's implemented - ${helpers.single_keyword("text-orientation", "sideways sideways-left sideways-right", experimental=True)} + ${helpers.single_keyword("text-orientation", "sideways sideways-left sideways-right", + experimental=True, need_clone=True)} // CSS Color Module Level 4 // https://drafts.csswg.org/css-color/ @@ -5678,6 +5664,10 @@ pub mod style_struct_traits { fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T); #[allow(non_snake_case)] fn copy_${longhand.ident}_from(&mut self, other: &Self); + % if longhand.need_clone: + #[allow(non_snake_case)] + fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T; + % endif % endfor % for additional in style_struct.additional_methods: #[allow(non_snake_case)] diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 422b7116b29..edf67a70851 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -220,6 +220,21 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { fn copy_${longhand.ident}_from(&mut self, other: &Self) { self.gecko.${longhand.gecko_ffi_name} = other.gecko.${longhand.gecko_ffi_name}; } + + %if longhand.need_clone: + fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { + use gecko_style_structs as gss; + use style::properties::longhands::${longhand.ident}::computed_value::T as Keyword; + // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts + match self.gecko.${longhand.gecko_ffi_name} as u32 { + % for value in longhand.keyword.values_for('gecko'): + gss::${longhand.keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)}, + % endfor + x => panic!("Found unexpected value in style struct for ${longhand.name} property: {}", x), + } + } + + % endif % endfor /* @@ -232,6 +247,11 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { fn copy_${longhand.ident}_from(&mut self, _: &Self) { unimplemented!() } + % if longhand.need_clone: + fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { + unimplemented!() + } + % endif % endfor <% additionals = [x for x in style_struct.additional_methods if not (skip_additionals and x.name in skip_additionals)] %>