From edf211ae4de5ef8b9c7a38f0bacb16eab1627181 Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Fri, 14 Apr 2017 12:39:39 -0500 Subject: [PATCH] servo: Merge #16352 - Correct serialization for border-radius property (from pyfisch:issue12655); r=Wafflespeanut I don't think there is a way to avoid the clones, or is there one? --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12655 (github issue number if applicable). - [X] These changes do not require tests because just a function is called. Source-Repo: https://github.com/servo/servo Source-Revision: e918d4886885e29d07eb9ad29b8d3b16df44b931 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : ed500c92cc58111a50f51df8d92330bcdbab5354 --- .../style/properties/shorthand/border.mako.rs | 20 +++++----------- .../unit/style/properties/serialization.rs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/servo/components/style/properties/shorthand/border.mako.rs b/servo/components/style/properties/shorthand/border.mako.rs index 7f48a74ff9d2..8441f5ce395e 100644 --- a/servo/components/style/properties/shorthand/border.mako.rs +++ b/servo/components/style/properties/shorthand/border.mako.rs @@ -182,7 +182,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser) 'border-%s-radius' % (corner) for corner in ['top-left', 'top-right', 'bottom-right', 'bottom-left'] )}" extra_prefixes="webkit" spec="https://drafts.csswg.org/css-backgrounds/#border-radius"> - use values::specified::basic_shape::BorderRadius; + use values::specified::basic_shape::{BorderRadius, serialize_radius_values}; use parser::Parse; pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { @@ -195,21 +195,13 @@ 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> 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, " ")); - - try!(self.border_top_right_radius.to_css(dest)); - try!(write!(dest, " ")); - - try!(self.border_bottom_right_radius.to_css(dest)); - try!(write!(dest, " ")); - - self.border_bottom_left_radius.to_css(dest) + serialize_radius_values(dest, + &self.border_top_left_radius.0, + &self.border_top_right_radius.0, + &self.border_bottom_right_radius.0, + &self.border_bottom_left_radius.0) } } diff --git a/servo/tests/unit/style/properties/serialization.rs b/servo/tests/unit/style/properties/serialization.rs index 770e94701e7b..12e8a631987f 100644 --- a/servo/tests/unit/style/properties/serialization.rs +++ b/servo/tests/unit/style/properties/serialization.rs @@ -368,6 +368,29 @@ mod shorthand_serialization { let serialization = shorthand_properties_to_string(properties); assert_eq!(serialization, "border-style: solid dotted;"); } + + use style::values::specified::BorderRadiusSize; + use style::values::specified::length::Percentage; + + #[test] + fn border_radius_should_serialize_correctly() { + let mut properties = Vec::new(); + properties.push(PropertyDeclaration::BorderTopLeftRadius(Box::new(BorderRadiusSize::new( + Percentage(0.01).into(), Percentage(0.05).into() + )))); + properties.push(PropertyDeclaration::BorderTopRightRadius(Box::new(BorderRadiusSize::new( + Percentage(0.02).into(), Percentage(0.06).into() + )))); + properties.push(PropertyDeclaration::BorderBottomRightRadius(Box::new(BorderRadiusSize::new( + Percentage(0.03).into(), Percentage(0.07).into() + )))); + properties.push(PropertyDeclaration::BorderBottomLeftRadius(Box::new(BorderRadiusSize::new( + Percentage(0.04).into(), Percentage(0.08).into() + )))); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "border-radius: 1% 2% 3% 4% / 5% 6% 7% 8%;"); + } }