mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Thread ParseError return values through CSS parsing.
This commit is contained in:
parent
58e39bfffa
commit
27ae1ef2e7
121 changed files with 2133 additions and 1505 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use style_traits::ParseError;
|
||||
use values::generics::background::BackgroundSize as GenericBackgroundSize;
|
||||
use values::specified::length::LengthOrPercentageOrAuto;
|
||||
|
||||
|
@ -13,17 +15,18 @@ use values::specified::length::LengthOrPercentageOrAuto;
|
|||
pub type BackgroundSize = GenericBackgroundSize<LengthOrPercentageOrAuto>;
|
||||
|
||||
impl Parse for BackgroundSize {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(width) = input.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i)) {
|
||||
let height = input
|
||||
.try(|i| LengthOrPercentageOrAuto::parse_non_negative(context, i))
|
||||
.unwrap_or(LengthOrPercentageOrAuto::Auto);
|
||||
return Ok(GenericBackgroundSize::Explicit { width: width, height: height });
|
||||
}
|
||||
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||
let ident = input.expect_ident()?;
|
||||
(match_ignore_ascii_case! { &ident,
|
||||
"cover" => Ok(GenericBackgroundSize::Cover),
|
||||
"contain" => Ok(GenericBackgroundSize::Contain),
|
||||
_ => Err(()),
|
||||
}
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue