From 4bc0fbeeb1b594abbe8e3d37b11ec8b97861ae00 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 1 Mar 2017 17:01:57 +1100 Subject: [PATCH] Impl ToCss on LonghandsToSerialize directly --- components/style/properties/helpers.mako.rs | 13 ++---------- .../properties/shorthand/background.mako.rs | 8 ++++---- .../style/properties/shorthand/border.mako.rs | 20 +++++++++---------- .../style/properties/shorthand/box.mako.rs | 16 +++++++-------- .../style/properties/shorthand/column.mako.rs | 8 ++++---- .../style/properties/shorthand/font.mako.rs | 4 ++-- .../shorthand/inherited_svg.mako.rs | 4 ++-- .../shorthand/inherited_text.mako.rs | 8 ++++---- .../style/properties/shorthand/list.mako.rs | 4 ++-- .../style/properties/shorthand/mask.mako.rs | 8 ++++---- .../properties/shorthand/outline.mako.rs | 8 ++++---- .../properties/shorthand/position.mako.rs | 8 ++++---- .../style/properties/shorthand/text.mako.rs | 4 ++-- 13 files changed, 52 insertions(+), 61 deletions(-) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 858699a3aba..861bcc2eaa6 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -554,15 +554,6 @@ } } - impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, - { - self.to_css_declared(dest) - } - } - - /// Parse the given shorthand and fill the result into the /// `declarations` vector. pub fn parse(context: &ParserContext, @@ -635,8 +626,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { super::serialize_four_sides( dest, self.${to_rust_ident(sub_property_pattern % 'top')}, diff --git a/components/style/properties/shorthand/background.mako.rs b/components/style/properties/shorthand/background.mako.rs index 5f820e69d43..a0747e9ea81 100644 --- a/components/style/properties/shorthand/background.mako.rs +++ b/components/style/properties/shorthand/background.mako.rs @@ -127,8 +127,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let len = self.background_image.0.len(); // There should be at least one declared value if len == 0 { @@ -224,8 +224,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let len = self.background_position_x.0.len(); if len == 0 || len != self.background_position_y.0.len() { return Ok(()); diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs index 4b44925ff8a..a215cf89136 100644 --- a/components/style/properties/shorthand/border.mako.rs +++ b/components/style/properties/shorthand/border.mako.rs @@ -29,8 +29,8 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style", }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { % for side in ["top", "right", "bottom", "left"]: let ${side} = self.border_${side}_width.clone(); % endfor @@ -108,8 +108,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { super::serialize_directional_border( dest, self.border_${to_rust_ident(side)}_width, @@ -139,8 +139,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let all_equal = { % for side in PHYSICAL_SIDES: let border_${side}_width = self.border_${side}_width; @@ -198,8 +198,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) // TODO: I do not understand how border radius works with respect to the slashes /, // so putting a default generic impl for now // https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.border_top_left_radius.to_css(dest)); try!(write!(dest, " ")); @@ -289,8 +289,8 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.border_image_source.to_css(dest)?; dest.write_str(" ")?; self.border_image_slice.to_css(dest)?; diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 248a2baec09..3bb821fe737 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -16,8 +16,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if *self.overflow_x == self.overflow_y.0 { self.overflow_x.to_css(dest) } else { @@ -115,8 +115,8 @@ macro_rules! try_parse_one { }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let len = self.transition_property.0.len(); // There should be at least one declared value if len == 0 { @@ -257,8 +257,8 @@ macro_rules! try_parse_one { }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let len = self.animation_name.0.len(); // There should be at least one declared value if len == 0 { @@ -307,10 +307,10 @@ macro_rules! try_parse_one { }) } - impl<'a> LonghandsToSerialize<'a> { + impl<'a> ToCss for LonghandsToSerialize<'a> { // Serializes into the single keyword value if both scroll-snap-type and scroll-snap-type-y are same. // Otherwise into an empty string. This is done to match Gecko's behaviour. - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.scroll_snap_type_x == self.scroll_snap_type_y { self.scroll_snap_type_x.to_css(dest) } else { diff --git a/components/style/properties/shorthand/column.mako.rs b/components/style/properties/shorthand/column.mako.rs index 7388cb8abdb..3e8648d38ba 100644 --- a/components/style/properties/shorthand/column.mako.rs +++ b/components/style/properties/shorthand/column.mako.rs @@ -49,8 +49,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.column_width.to_css(dest)); try!(write!(dest, " ")); @@ -96,8 +96,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.column_rule_width.to_css(dest)?; dest.write_str(" ")?; self.column_rule_style.to_css(dest)?; diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index fc78bb297da..a94c2efa7c1 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -95,8 +95,8 @@ } // This may be a bit off, unsure, possibly needs changes - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.font_style.to_css(dest)?; dest.write_str(" ")?; self.font_variant.to_css(dest)?; diff --git a/components/style/properties/shorthand/inherited_svg.mako.rs b/components/style/properties/shorthand/inherited_svg.mako.rs index 3db54601d7c..e33aa3bac16 100644 --- a/components/style/properties/shorthand/inherited_svg.mako.rs +++ b/components/style/properties/shorthand/inherited_svg.mako.rs @@ -20,8 +20,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.marker_start == self.marker_mid && self.marker_mid == self.marker_end { self.marker_start.to_css(dest) } else { diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index 1b15034f50e..af94643bc3c 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -38,8 +38,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.text_emphasis_style.to_css(dest)?; dest.write_str(" ")?; self.text_emphasis_color.to_css(dest) @@ -86,8 +86,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self._webkit_text_stroke_width.to_css(dest)?; dest.write_str(" ")?; self._webkit_text_stroke_color.to_css(dest) diff --git a/components/style/properties/shorthand/list.mako.rs b/components/style/properties/shorthand/list.mako.rs index d0e08404ff4..cd8cc0775dd 100644 --- a/components/style/properties/shorthand/list.mako.rs +++ b/components/style/properties/shorthand/list.mako.rs @@ -96,8 +96,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.list_style_position.to_css(dest)?; dest.write_str(" ")?; self.list_style_image.to_css(dest)?; diff --git a/components/style/properties/shorthand/mask.mako.rs b/components/style/properties/shorthand/mask.mako.rs index 4d5d5ca68d4..01caeddb9ca 100644 --- a/components/style/properties/shorthand/mask.mako.rs +++ b/components/style/properties/shorthand/mask.mako.rs @@ -120,8 +120,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { use properties::longhands::mask_origin::single_value::computed_value::T as Origin; use properties::longhands::mask_clip::single_value::computed_value::T as Clip; @@ -217,8 +217,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { let len = self.mask_position_x.0.len(); if len == 0 || self.mask_position_y.0.len() != len { return Ok(()); diff --git a/components/style/properties/shorthand/outline.mako.rs b/components/style/properties/shorthand/outline.mako.rs index 86651becf12..25757c28a2d 100644 --- a/components/style/properties/shorthand/outline.mako.rs +++ b/components/style/properties/shorthand/outline.mako.rs @@ -51,8 +51,8 @@ } } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.outline_width.to_css(dest)); try!(write!(dest, " ")); try!(self.outline_style.to_css(dest)); @@ -81,8 +81,8 @@ } // TODO: Border radius for the radius shorthand is not implemented correctly yet - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self._moz_outline_radius_topleft.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 5e875e4dfa1..603a810804e 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -37,8 +37,8 @@ } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.flex_direction.to_css(dest)?; dest.write_str(" ")?; self.flex_wrap.to_css(dest) @@ -97,8 +97,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.flex_grow.to_css(dest)); try!(write!(dest, " ")); diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs index 6e89b11a518..b9bc7013a2c 100644 --- a/components/style/properties/shorthand/text.mako.rs +++ b/components/style/properties/shorthand/text.mako.rs @@ -46,8 +46,8 @@ }) } - impl<'a> LonghandsToSerialize<'a> { - fn to_css_declared(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.text_decoration_line.to_css(dest)?; dest.write_str(" ")?; self.text_decoration_style.to_css(dest)?;