mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Fix related to #14101
Add Parse trait implementation for some structures
This commit is contained in:
parent
4b9693cf81
commit
9564673b5a
14 changed files with 149 additions and 114 deletions
|
@ -213,14 +213,6 @@ pub struct InsetRect {
|
|||
}
|
||||
|
||||
impl InsetRect {
|
||||
pub fn parse(input: &mut Parser) -> Result<InsetRect, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"inset" => {
|
||||
Ok(try!(input.parse_nested_block(InsetRect::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
pub fn parse_function_arguments(input: &mut Parser) -> Result<InsetRect, ()> {
|
||||
let (t, r, b, l) = try!(parse_four_sides(input, LengthOrPercentage::parse));
|
||||
let mut rect = InsetRect {
|
||||
|
@ -237,6 +229,17 @@ impl InsetRect {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for InsetRect {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"inset" => {
|
||||
Ok(try!(input.parse_nested_block(InsetRect::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for InsetRect {
|
||||
// XXXManishearth again, we should try to reduce the number of values printed here
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
|
@ -374,14 +377,6 @@ pub struct Circle {
|
|||
}
|
||||
|
||||
impl Circle {
|
||||
pub fn parse(input: &mut Parser) -> Result<Circle, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"circle" => {
|
||||
Ok(try!(input.parse_nested_block(Circle::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
pub fn parse_function_arguments(input: &mut Parser) -> Result<Circle, ()> {
|
||||
let radius = input.try(ShapeRadius::parse).ok().unwrap_or_else(Default::default);
|
||||
let position = if let Ok(_) = input.try(|input| input.expect_ident_matching("at")) {
|
||||
|
@ -402,6 +397,17 @@ impl Circle {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for Circle {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"circle" => {
|
||||
Ok(try!(input.parse_nested_block(Circle::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Circle {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("circle("));
|
||||
|
@ -446,14 +452,6 @@ pub struct Ellipse {
|
|||
|
||||
|
||||
impl Ellipse {
|
||||
pub fn parse(input: &mut Parser) -> Result<Ellipse, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"ellipse" => {
|
||||
Ok(try!(input.parse_nested_block(Ellipse::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
pub fn parse_function_arguments(input: &mut Parser) -> Result<Ellipse, ()> {
|
||||
let (a, b) = input.try(|input| -> Result<_, ()> {
|
||||
Ok((try!(ShapeRadius::parse(input)), try!(ShapeRadius::parse(input))))
|
||||
|
@ -477,6 +475,17 @@ impl Ellipse {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for Ellipse {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"ellipse" => {
|
||||
Ok(try!(input.parse_nested_block(Ellipse::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Ellipse {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("ellipse("));
|
||||
|
@ -524,14 +533,6 @@ pub struct Polygon {
|
|||
}
|
||||
|
||||
impl Polygon {
|
||||
pub fn parse(input: &mut Parser) -> Result<Polygon, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"polygon" => {
|
||||
Ok(try!(input.parse_nested_block(Polygon::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
pub fn parse_function_arguments(input: &mut Parser) -> Result<Polygon, ()> {
|
||||
let fill = input.try(|input| {
|
||||
let fill = FillRule::parse(input);
|
||||
|
@ -550,6 +551,17 @@ impl Polygon {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for Polygon {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_function()),
|
||||
"polygon" => {
|
||||
Ok(try!(input.parse_nested_block(Polygon::parse_function_arguments)))
|
||||
},
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Polygon {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("polygon("));
|
||||
|
@ -616,8 +628,8 @@ impl Default for ShapeRadius {
|
|||
}
|
||||
}
|
||||
|
||||
impl ShapeRadius {
|
||||
pub fn parse(input: &mut Parser) -> Result<ShapeRadius, ()> {
|
||||
impl Parse for ShapeRadius {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
input.try(LengthOrPercentage::parse).map(ShapeRadius::Length)
|
||||
.or_else(|_| {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
|
@ -703,8 +715,8 @@ impl ToCss for BorderRadius {
|
|||
}
|
||||
}
|
||||
|
||||
impl BorderRadius {
|
||||
pub fn parse(input: &mut Parser) -> Result<BorderRadius, ()> {
|
||||
impl Parse for BorderRadius {
|
||||
fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||
let widths = try!(parse_one_set_of_border_values(input));
|
||||
let heights = if input.try(|input| input.expect_delim('/')).is_ok() {
|
||||
try!(parse_one_set_of_border_values(input))
|
||||
|
@ -781,8 +793,8 @@ pub enum FillRule {
|
|||
|
||||
impl ComputedValueAsSpecified for FillRule {}
|
||||
|
||||
impl FillRule {
|
||||
pub fn parse(input: &mut Parser) -> Result<FillRule, ()> {
|
||||
impl Parse for FillRule {
|
||||
fn parse(input: &mut Parser) -> Result<FillRule, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
"nonzero" => Ok(FillRule::NonZero),
|
||||
"evenodd" => Ok(FillRule::EvenOdd),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue