Skip to content

Commit

Permalink
Allow either comma or space seperated css rect()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Hentges committed May 30, 2016
1 parent e8e7c65 commit 41d2670
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions components/style/properties/longhand/effects.mako.rs
Expand Up @@ -344,31 +344,45 @@ ${helpers.predefined_type("opacity",
use std::ascii::AsciiExt;
use values::specified::Length;

fn parse_argument(input: &mut Parser) -> Result<Option<Length>, ()> {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
Ok(None)
} else {
Length::parse(input).map(Some)
}
}

if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
return Ok(SpecifiedValue(None))
}
if !try!(input.expect_function()).eq_ignore_ascii_case("rect") {
return Err(())
}
let sides = try!(input.parse_nested_block(|input| {
input.parse_comma_separated(|input| {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
Ok(None)
} else {
Length::parse(input).map(Some)
}
})
}));
if sides.len() == 4 {

input.parse_nested_block(|input| {
let top = try!(parse_argument(input));
let right;
let bottom;
let left;

if input.try(|input| input.expect_comma()).is_ok() {
right = try!(parse_argument(input));
try!(input.expect_comma());
bottom = try!(parse_argument(input));
try!(input.expect_comma());
left = try!(parse_argument(input));
} else {
right = try!(parse_argument(input));
bottom = try!(parse_argument(input));
left = try!(parse_argument(input));
}
Ok(SpecifiedValue(Some(SpecifiedClipRect {
top: sides[0].unwrap_or(Length::Absolute(Au(0))),
right: sides[1],
bottom: sides[2],
left: sides[3].unwrap_or(Length::Absolute(Au(0))),
top: top.unwrap_or(Length::Absolute(Au(0))),
right: right,
bottom: bottom,
left: left.unwrap_or(Length::Absolute(Au(0))),
})))
} else {
Err(())
}
})
}
</%helpers:longhand>

Expand Down

0 comments on commit 41d2670

Please sign in to comment.