From cc35d4fccea57fe6487c2c45b0abf5a1c0906883 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 19 Apr 2016 16:41:38 -0700 Subject: [PATCH] Get rid of some of our custom additional methods in favor of clonable keywords. Now that I'm pretty convinced we can auto-generate these and make them fast, we can ditch the additional complexity. --- .../style/properties/longhand/border.mako.rs | 4 +- .../style/properties/longhand/box.mako.rs | 7 +--- .../style/properties/longhand/outline.mako.rs | 4 +- .../style/properties/properties.mako.rs | 41 +++++++++++-------- ports/geckolib/properties.mako.rs | 7 +++- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 49903672754..16e8bc7a6eb 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -7,7 +7,7 @@ <% from data import Method %> <% data.new_style_struct("Border", inherited=False, gecko_ffi_name="nsStyleBorder", - additional_methods=[Method("border_" + side + "_is_none_or_hidden_and_has_nonzero_width", + additional_methods=[Method("border_" + side + "_has_nonzero_width", "bool") for side in ["top", "right", "bottom", "left"]]) %> % for side in ["top", "right", "bottom", "left"]: @@ -15,7 +15,7 @@ % endfor % for side in ["top", "right", "bottom", "left"]: - ${helpers.predefined_type("border-%s-style" % side, "BorderStyle", "specified::BorderStyle::none")} + ${helpers.predefined_type("border-%s-style" % side, "BorderStyle", "specified::BorderStyle::none", need_clone=True)} % endfor % for side in ["top", "right", "bottom", "left"]: diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 039c1fdbb9c..34d425ec16e 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -9,10 +9,7 @@ <% data.new_style_struct("Box", inherited=False, gecko_ffi_name="nsStyleDisplay", - additional_methods=[Method("is_floated", "bool"), - Method("overflow_x_is_visible", "bool"), - Method("overflow_y_is_visible", "bool"), - Method("transition_count", "usize")]) %> + additional_methods=[Method("transition_count", "usize")]) %> // TODO(SimonSapin): don't parse `inline-table`, since we don't support it <%helpers:longhand name="display" need_clone="True" custom_cascade="${product == 'servo'}"> @@ -89,7 +86,7 @@ ${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" need_clone="True" gecko_ffi_name="mFloats"> impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index ef3649b6b88..0b36e664a23 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -9,12 +9,12 @@ <% data.new_style_struct("Outline", inherited=False, gecko_ffi_name="nsStyleOutline", - additional_methods=[Method("outline_is_none_or_hidden_and_has_nonzero_width", "bool")]) %> + additional_methods=[Method("outline_has_nonzero_width", "bool")]) %> // TODO(pcwalton): `invert` ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor")} -<%helpers:longhand name="outline-style"> +<%helpers:longhand name="outline-style" need_clone="True"> pub use values::specified::BorderStyle as SpecifiedValue; pub fn get_initial_value() -> SpecifiedValue { SpecifiedValue::none } pub mod computed_value { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index afe5cb01487..031a79a6966 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -277,10 +277,11 @@ pub mod longhands { internal=True)} // FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`. - ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", gecko_constant_prefix="NS_STYLE_OVERFLOW")} + ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=True, + gecko_constant_prefix="NS_STYLE_OVERFLOW")} // FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`. - <%helpers:longhand name="overflow-y"> + <%helpers:longhand name="overflow-y" need_clone="True"> use super::overflow_x; use cssparser::ToCss; @@ -5719,8 +5720,10 @@ pub mod style_structs { % endfor % if style_struct.trait_name == "Border": % for side in ["top", "right", "bottom", "left"]: - fn border_${side}_is_none_or_hidden_and_has_nonzero_width(&self) -> bool { - self.border_${side}_style.none_or_hidden() && + fn clone_border_${side}_style(&self) -> longhands::border_${side}_style::computed_value::T { + self.border_${side}_style.clone() + } + fn border_${side}_has_nonzero_width(&self) -> bool { self.border_${side}_width != ::app_units::Au(0) } % endfor @@ -5731,14 +5734,14 @@ pub mod style_structs { fn clone_position(&self) -> longhands::position::computed_value::T { self.position.clone() } - fn is_floated(&self) -> bool { - self.float != longhands::float::SpecifiedValue::none + fn clone_float(&self) -> longhands::float::computed_value::T { + self.float.clone() } - fn overflow_x_is_visible(&self) -> bool { - self.overflow_x == longhands::overflow_x::computed_value::T::visible + fn clone_overflow_x(&self) -> longhands::overflow_x::computed_value::T { + self.overflow_x.clone() } - fn overflow_y_is_visible(&self) -> bool { - self.overflow_y.0 == longhands::overflow_x::computed_value::T::visible + fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T { + self.overflow_y.clone() } fn transition_count(&self) -> usize { self.transition_property.0.len() @@ -5778,8 +5781,11 @@ pub mod style_structs { self._servo_text_decorations_in_effect.clone() } % elif style_struct.trait_name == "Outline": - fn outline_is_none_or_hidden_and_has_nonzero_width(&self) -> bool { - self.outline_style.none_or_hidden() && self.outline_width != ::app_units::Au(0) + fn clone_outline_style(&self) -> longhands::outline_style::computed_value::T { + self.outline_style.clone() + } + fn outline_has_nonzero_width(&self) -> bool { + self.outline_width != ::app_units::Au(0) } % elif style_struct.trait_name == "Text": fn has_underline(&self) -> bool { @@ -6438,7 +6444,7 @@ pub fn cascade( let positioned = matches!(style.get_box().clone_position(), longhands::position::SpecifiedValue::absolute | longhands::position::SpecifiedValue::fixed); - let floated = style.get_box().is_floated(); + let floated = style.get_box().clone_float() != longhands::float::SpecifiedValue::none; if positioned || floated || is_root_element { use computed_values::display::T; @@ -6472,7 +6478,8 @@ pub fn cascade( { use computed_values::overflow_x::T as overflow; use computed_values::overflow_y; - match (style.get_box().overflow_x_is_visible(), style.get_box().overflow_y_is_visible()) { + match (style.get_box().clone_overflow_x() == longhands::overflow_x::computed_value::T::visible, + style.get_box().clone_overflow_y().0 == longhands::overflow_x::computed_value::T::visible) { (true, true) => {} (true, _) => { style.mutate_box().set_overflow_x(overflow::auto); @@ -6487,13 +6494,15 @@ pub fn cascade( // The initial value of border-*-width may be changed at computed value time. % for side in ["top", "right", "bottom", "left"]: // Like calling to_computed_value, which wouldn't type check. - if style.get_border().border_${side}_is_none_or_hidden_and_has_nonzero_width() { + if style.get_border().clone_border_${side}_style().none_or_hidden() && + style.get_border().border_${side}_has_nonzero_width() { style.mutate_border().set_border_${side}_width(Au(0)); } % endfor // The initial value of outline width may be changed at computed value time. - if style.get_outline().outline_is_none_or_hidden_and_has_nonzero_width() { + if style.get_outline().clone_outline_style().none_or_hidden() && + style.get_outline().outline_has_nonzero_width() { style.mutate_outline().set_outline_width(Au(0)); } diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index edf67a70851..c1c4dd799b5 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -276,7 +276,7 @@ ${caller.body()} // iteratively implement more and more methods. <%self:impl_trait style_struct_name="Border" skip_longhands="${['border-left-color', 'border-left-style']}" - skip_additionals="${['border_bottom_is_none_or_hidden_and_has_nonzero_width']}"> + skip_additionals="${['border_bottom_has_nonzero_width']}"> fn set_border_left_color(&mut self, _: longhands::border_left_color::computed_value::T) { unimplemented!() } @@ -289,7 +289,10 @@ ${caller.body()} fn copy_border_left_style_from(&mut self, _: &Self) { unimplemented!() } - fn border_bottom_is_none_or_hidden_and_has_nonzero_width(&self) -> bool { + fn clone_border_left_style(&self) -> longhands::border_left_style::computed_value::T { + unimplemented!() + } + fn border_bottom_has_nonzero_width(&self) -> bool { unimplemented!() }