Track cloning separately from additional_methods and auto-generate clone methods.

This commit is contained in:
Bobby Holley 2016-04-18 18:51:13 -07:00
parent 0e0e902edd
commit a4ee11da0a
4 changed files with 42 additions and 33 deletions

View file

@ -47,7 +47,7 @@ class Keyword(object):
class Longhand(object): class Longhand(object):
def __init__(self, style_struct, name, derived_from=None, keyword=None, def __init__(self, style_struct, name, derived_from=None, keyword=None,
custom_cascade=False, experimental=False, internal=False, custom_cascade=False, experimental=False, internal=False,
gecko_ffi_name=None): need_clone=False, gecko_ffi_name=None):
self.name = name self.name = name
self.keyword = keyword self.keyword = keyword
self.ident = to_rust_ident(name) self.ident = to_rust_ident(name)
@ -56,6 +56,7 @@ class Longhand(object):
self.experimental = ("layout.%s.enabled" % name) if experimental else None self.experimental = ("layout.%s.enabled" % name) if experimental else None
self.custom_cascade = custom_cascade self.custom_cascade = custom_cascade
self.internal = internal self.internal = internal
self.need_clone = need_clone
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split() self.derived_from = (derived_from or "").split()

View file

@ -9,15 +9,13 @@
<% data.new_style_struct("Box", <% data.new_style_struct("Box",
inherited=False, inherited=False,
gecko_ffi_name="nsStyleDisplay", gecko_ffi_name="nsStyleDisplay",
additional_methods=[Method("clone_display", "longhands::display::computed_value::T"), additional_methods=[Method("is_floated", "bool"),
Method("clone_position", "longhands::position::computed_value::T"),
Method("is_floated", "bool"),
Method("overflow_x_is_visible", "bool"), Method("overflow_x_is_visible", "bool"),
Method("overflow_y_is_visible", "bool"), Method("overflow_y_is_visible", "bool"),
Method("transition_count", "usize")]) %> Method("transition_count", "usize")]) %>
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it // 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 values = """inline block inline-block
table inline-table table-row-group table-header-group table-footer-group table inline-table table-row-group table-header-group table-footer-group
@ -89,7 +87,7 @@
</%helpers:longhand> </%helpers:longhand>
${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"> <%helpers:single_keyword_computed name="float" values="none left right" gecko_ffi_name="mFloats">
impl ToComputedValue for SpecifiedValue { impl ToComputedValue for SpecifiedValue {

View file

@ -54,15 +54,9 @@ pub mod longhands {
<%include file="/longhand/padding.mako.rs" /> <%include file="/longhand/padding.mako.rs" />
<%include file="/longhand/position.mako.rs" /> <%include file="/longhand/position.mako.rs" />
<% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility", <% 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")]) %>
${helpers.single_keyword("direction", "ltr rtl")} ${helpers.single_keyword("direction", "ltr rtl", need_clone=True)}
// CSS 2.1, Section 10 - Visual formatting model details // CSS 2.1, Section 10 - Visual formatting model details
@ -92,10 +86,7 @@ pub mod longhands {
"computed::LengthOrPercentageOrNone::None", "computed::LengthOrPercentageOrNone::None",
"parse_non_negative")} "parse_non_negative")}
<% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText", <% 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 [])) %>
<%helpers:longhand name="line-height"> <%helpers:longhand name="line-height">
use cssparser::ToCss; use cssparser::ToCss;
@ -1076,11 +1067,9 @@ pub mod longhands {
} }
</%helpers:longhand> </%helpers:longhand>
<% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor", <% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor") %>
additional_methods=[Method("clone_color",
"longhands::color::computed_value::T")]) %>
<%helpers:raw_longhand name="color"> <%helpers:raw_longhand name="color" need_clone="True">
use cssparser::Color as CSSParserColor; use cssparser::Color as CSSParserColor;
use cssparser::RGBA; use cssparser::RGBA;
use values::specified::{CSSColor, CSSRGBA}; use values::specified::{CSSColor, CSSRGBA};
@ -1119,12 +1108,7 @@ pub mod longhands {
// CSS 2.1, Section 15 - Fonts // CSS 2.1, Section 15 - Fonts
<% data.new_style_struct("Font", inherited=True, gecko_ffi_name="nsStyleFont", <% data.new_style_struct("Font", inherited=True, gecko_ffi_name="nsStyleFont",
additional_methods=[Method("clone_font_size", additional_methods=[Method("compute_font_hash", is_mut=True)]) %>
"longhands::font_size::computed_value::T"),
Method("clone_font_weight",
"longhands::font_weight::computed_value::T"),
Method("compute_font_hash", is_mut=True)]) %>
<%helpers:longhand name="font-family"> <%helpers:longhand name="font-family">
use self::computed_value::FontFamily; use self::computed_value::FontFamily;
use values::computed::ComputedValueAsSpecified; use values::computed::ComputedValueAsSpecified;
@ -1238,7 +1222,7 @@ pub mod longhands {
${helpers.single_keyword("font-style", "normal italic oblique")} ${helpers.single_keyword("font-style", "normal italic oblique")}
${helpers.single_keyword("font-variant", "normal small-caps")} ${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 cssparser::ToCss;
use std::fmt; use std::fmt;
@ -1356,7 +1340,7 @@ pub mod longhands {
} }
</%helpers:longhand> </%helpers:longhand>
<%helpers:longhand name="font-size"> <%helpers:longhand name="font-size" need_clone="True">
use app_units::Au; use app_units::Au;
use cssparser::ToCss; use cssparser::ToCss;
use std::fmt; use std::fmt;
@ -1724,7 +1708,7 @@ pub mod longhands {
<% data.switch_to_style_struct("InheritedText") %> <% data.switch_to_style_struct("InheritedText") %>
<%helpers:longhand name="-servo-text-decorations-in-effect" <%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 cssparser::{RGBA, ToCss};
use std::fmt; use std::fmt;
@ -1970,11 +1954,13 @@ pub mod longhands {
// http://dev.w3.org/csswg/css-writing-modes/ // http://dev.w3.org/csswg/css-writing-modes/
<% data.switch_to_style_struct("InheritedBox") %> <% 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): Add 'mixed' and 'upright' (needs vertical text support)
// FIXME(SimonSapin): initial (first) value should be 'mixed', when that's implemented // 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 // CSS Color Module Level 4
// https://drafts.csswg.org/css-color/ // 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); fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T);
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn copy_${longhand.ident}_from(&mut self, other: &Self); 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 % endfor
% for additional in style_struct.additional_methods: % for additional in style_struct.additional_methods:
#[allow(non_snake_case)] #[allow(non_snake_case)]

View file

@ -220,6 +220,21 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
fn copy_${longhand.ident}_from(&mut self, other: &Self) { fn copy_${longhand.ident}_from(&mut self, other: &Self) {
self.gecko.${longhand.gecko_ffi_name} = other.gecko.${longhand.gecko_ffi_name}; 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 % endfor
/* /*
@ -232,6 +247,11 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
fn copy_${longhand.ident}_from(&mut self, _: &Self) { fn copy_${longhand.ident}_from(&mut self, _: &Self) {
unimplemented!() unimplemented!()
} }
% if longhand.need_clone:
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T {
unimplemented!()
}
% endif
% endfor % endfor
<% additionals = [x for x in style_struct.additional_methods <% additionals = [x for x in style_struct.additional_methods
if not (skip_additionals and x.name in skip_additionals)] %> if not (skip_additionals and x.name in skip_additionals)] %>