From 48f115984532c3e47a6af255b82961ab8d82bb64 Mon Sep 17 00:00:00 2001 From: Bryan Bell Date: Tue, 15 Sep 2015 13:27:30 -0700 Subject: [PATCH] gfx: Add elliptical border-radius shorthand parsing Adds elliptical border-radius shorthand parsing, e.g.: /* The syntax of the second radius allows one to four values */ /* (first radius values) / radius */ border-radius: 10px 5% / 20px; /* (first radius values) / top-left-and-bottom-right | top-right-and-bottom-left */ border-radius: 10px 5% / 20px 30px; /* (first radius values) / top-left | top-right-and-bottom-left | bottom-right */ border-radius: 10px 5px 2em / 20px 25px 30%; /* (first radius values) / top-left | top-right | bottom-right | bottom-left */ border-radius: 10px 5% / 20px 25em 30px 35em; --- components/style/properties.mako.rs | 26 ++++++++++++---- components/style/values.rs | 36 +++++++++------------- tests/ref/basic.list | 1 + tests/ref/border_radius_shorthand_a.html | 22 +++++++++++++ tests/ref/border_radius_shorthand_ref.html | 25 +++++++++++++++ 5 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 tests/ref/border_radius_shorthand_a.html create mode 100644 tests/ref/border_radius_shorthand_ref.html diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 5b4d765fa08..75d6971ba39 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -5135,16 +5135,18 @@ pub mod shorthands { 'border-%s-radius' % (corner) for corner in ['top-left', 'top-right', 'bottom-right', 'bottom-left'] )}"> + use util::geometry::Au; + use values::specified::{Length, LengthOrPercentage}; use values::specified::BorderRadiusSize; let _ignored = context; - fn parse_one_set_of_border_radii(mut input: &mut Parser) - -> Result<[BorderRadiusSize; 4], ()> { + fn parse_one_set_of_border_values(mut input: &mut Parser) + -> Result<[LengthOrPercentage; 4], ()> { let mut count = 0; - let mut values = [BorderRadiusSize::zero(); 4]; + let mut values = [LengthOrPercentage::Length(Length::Absolute(Au(0))); 4]; while count < 4 { - if let Ok(value) = input.try(BorderRadiusSize::parse_one_radii) { + if let Ok(value) = input.try(LengthOrPercentage::parse) { values[count] = value; count += 1; } else { @@ -5161,9 +5163,21 @@ pub mod shorthands { } } - let radii = try!(parse_one_set_of_border_radii(input)); - // TODO(bjwbell): Finish parsing code for elliptical borders. + fn parse_one_set_of_border_radii(mut input: &mut Parser) + -> Result<[BorderRadiusSize; 4], ()> { + let widths = try!(parse_one_set_of_border_values(input)); + let mut heights = widths.clone(); + let mut radii_values = [BorderRadiusSize::zero(); 4]; + if input.try(|input| input.expect_delim('/')).is_ok() { + heights = try!(parse_one_set_of_border_values(input)); + } + for i in 0..radii_values.len() { + radii_values[i] = BorderRadiusSize::new(widths[i], heights[i]); + } + Ok(radii_values) + } + let radii = try!(parse_one_set_of_border_radii(input)); Ok(Longhands { border_top_left_radius: Some(radii[0]), border_top_right_radius: Some(radii[1]), diff --git a/components/style/values.rs b/components/style/values.rs index 77c639abc5e..7627528c3c6 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -842,6 +842,21 @@ pub mod specified { let zero = LengthOrPercentage::Length(Length::Absolute(Au(0))); BorderRadiusSize(Size2D::new(zero, zero)) } + + pub fn new(width: LengthOrPercentage, height: LengthOrPercentage) -> BorderRadiusSize { + BorderRadiusSize(Size2D::new(width, height)) + } + + pub fn circle(radius: LengthOrPercentage) -> BorderRadiusSize { + BorderRadiusSize(Size2D::new(radius, radius)) + } + + #[inline] + pub fn parse(input: &mut Parser) -> Result { + let first = try!(LengthOrPercentage::parse_non_negative(input)); + let second = input.try(LengthOrPercentage::parse_non_negative).unwrap_or(first); + Ok(BorderRadiusSize(Size2D::new(first, second))) + } } impl ToCss for BorderRadiusSize { @@ -852,27 +867,6 @@ pub mod specified { size.height.to_css(dest) } } - impl BorderRadiusSize { - pub fn circle(radius: LengthOrPercentage) -> BorderRadiusSize { - BorderRadiusSize(Size2D::new(radius, radius)) - } - - pub fn parse_one_radii(input: &mut Parser) -> Result { - if let Ok(first) = LengthOrPercentage::parse_non_negative(input) { - Ok(BorderRadiusSize(Size2D::new(first, first))) - } else { - Err(()) - } - } - - #[allow(dead_code)] - #[inline] - pub fn parse(input: &mut Parser) -> Result { - let first = try!(LengthOrPercentage::parse_non_negative(input)); - let second = input.try(LengthOrPercentage::parse_non_negative).unwrap_or(first); - Ok(BorderRadiusSize(Size2D::new(first, second))) - } - } // http://dev.w3.org/csswg/css2/colors.html#propdef-background-position #[derive(Clone, PartialEq, Copy)] diff --git a/tests/ref/basic.list b/tests/ref/basic.list index bfe8d6abda3..ae10ad1ea61 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -68,6 +68,7 @@ flaky_cpu == append_style_a.html append_style_b.html != border_radius_dashed_a.html border_radius_dashed_ref.html == border_radius_elliptical_a.html border_radius_elliptical_ref.html == border_radius_overlapping_a.html border_radius_overlapping_ref.html +== border_radius_shorthand_a.html border_radius_shorthand_ref.html == border_rounding_1px_invisible_issue_7184_a.html border_rounding_1px_invisible_issue_7184_ref.html == border_spacing_a.html border_spacing_ref.html == border_spacing_auto_layout_a.html border_spacing_ref.html diff --git a/tests/ref/border_radius_shorthand_a.html b/tests/ref/border_radius_shorthand_a.html new file mode 100644 index 00000000000..ed0769e380a --- /dev/null +++ b/tests/ref/border_radius_shorthand_a.html @@ -0,0 +1,22 @@ + + + + + + + + +

Shorthand Border Radius - Elliptical

+

+ + diff --git a/tests/ref/border_radius_shorthand_ref.html b/tests/ref/border_radius_shorthand_ref.html new file mode 100644 index 00000000000..5d84fed4d01 --- /dev/null +++ b/tests/ref/border_radius_shorthand_ref.html @@ -0,0 +1,25 @@ + + + + + + + + +

Shorthand Border Radius - Elliptical

+

+ +