diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-05-13 10:57:46 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-05-15 15:36:24 +0200 |
commit | 9e6f9db1275c7bfaeb3584be330e5e09ac4c3eab (patch) | |
tree | e4136f010a3d97ed3adc4339b9de737c29806724 /components | |
parent | c9d140121d70cedd239ae5df3b9110074345902a (diff) | |
download | servo-9e6f9db1275c7bfaeb3584be330e5e09ac4c3eab.tar.gz servo-9e6f9db1275c7bfaeb3584be330e5e09ac4c3eab.zip |
Reorganise specified::image::GradientItem methods
Diffstat (limited to 'components')
-rw-r--r-- | components/style/values/specified/image.rs | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 166eed64fe3..f85535d011d 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -82,7 +82,7 @@ impl Parse for Image { if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) { return Ok(GenericImage::Url(url)); } - if let Ok(gradient) = input.try(|input| Gradient::parse_function(context, input)) { + if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) { return Ok(GenericImage::Gradient(gradient)); } if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) { @@ -113,9 +113,8 @@ impl Image { } } -impl Gradient { - /// Parses a gradient from the given arguments. - pub fn parse_function(context: &ParserContext, input: &mut Parser) -> Result<Gradient, ()> { +impl Parse for Gradient { + fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { enum Shape { Linear, Radial, @@ -154,7 +153,7 @@ impl Gradient { Shape::Linear => GradientKind::parse_linear(context, i, compat_mode)?, Shape::Radial => GradientKind::parse_radial(context, i, compat_mode)?, }; - let items = Gradient::parse_items(context, i)?; + let items = GradientItem::parse_comma_separated(context, i)?; Ok((shape, items)) })?; @@ -169,24 +168,6 @@ impl Gradient { compat_mode: compat_mode, }) } - - fn parse_items(context: &ParserContext, input: &mut Parser) -> Result<Vec<GradientItem>, ()> { - let mut seen_stop = false; - let items = try!(input.parse_comma_separated(|input| { - if seen_stop { - if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) { - seen_stop = false; - return Ok(GenericGradientItem::InterpolationHint(hint)); - } - } - seen_stop = true; - ColorStop::parse(context, input).map(GenericGradientItem::ColorStop) - })); - if !seen_stop || items.len() < 2 { - return Err(()); - } - Ok(items) - } } impl GradientKind { @@ -391,6 +372,26 @@ impl ShapeExtent { } } +impl GradientItem { + fn parse_comma_separated(context: &ParserContext, input: &mut Parser) -> Result<Vec<Self>, ()> { + let mut seen_stop = false; + let items = try!(input.parse_comma_separated(|input| { + if seen_stop { + if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) { + seen_stop = false; + return Ok(GenericGradientItem::InterpolationHint(hint)); + } + } + seen_stop = true; + ColorStop::parse(context, input).map(GenericGradientItem::ColorStop) + })); + if !seen_stop || items.len() < 2 { + return Err(()); + } + Ok(items) + } +} + impl Parse for ColorStop { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { Ok(ColorStop { |