mirror of
https://github.com/servo/servo.git
synced 2025-08-17 03:15:34 +01:00
style: Make PercentageOrNumber also reject negative percentages.
This commit is contained in:
parent
c2d9f663af
commit
372379428b
2 changed files with 20 additions and 10 deletions
|
@ -909,15 +909,26 @@ impl ToCss for Percentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl Percentage {
|
||||
fn parse_internal(input: &mut Parser, context: AllowedNumericType) -> Result<Self, ()> {
|
||||
match try!(input.next()) {
|
||||
Token::Percentage(ref value) if context.is_ok(value.unit_value) => {
|
||||
Ok(Percentage(value.unit_value))
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a percentage token, but rejects it if it's negative.
|
||||
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Percentage {
|
||||
#[inline]
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
let context = AllowedNumericType::All;
|
||||
match try!(input.next()) {
|
||||
Token::Percentage(ref value) if context.is_ok(value.unit_value) =>
|
||||
Ok(Percentage(value.unit_value)),
|
||||
_ => Err(())
|
||||
}
|
||||
Self::parse_internal(input, AllowedNumericType::All)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue