mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Centralize calc function parsing.
So that extending it to support other math functions like min / max / etc is simpler. There should be no behavior change with this patch, though I added a comment to some places where we don't do calc() clamping correctly (though other browsers don't either so...). Differential Revision: https://phabricator.services.mozilla.com/D59939
This commit is contained in:
parent
9026720f04
commit
d74f90e3a7
7 changed files with 116 additions and 58 deletions
|
@ -208,7 +208,9 @@ impl Angle {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_unitless_zero: AllowUnitlessZeroAngle,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let t = input.next()?;
|
||||
let allow_unitless_zero = matches!(allow_unitless_zero, AllowUnitlessZeroAngle::Yes);
|
||||
match *t {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
|
@ -221,15 +223,12 @@ impl Angle {
|
|||
},
|
||||
}
|
||||
},
|
||||
Token::Number { value, .. } if value == 0. => match allow_unitless_zero {
|
||||
AllowUnitlessZeroAngle::Yes => Ok(Angle::zero()),
|
||||
AllowUnitlessZeroAngle::No => {
|
||||
let t = t.clone();
|
||||
Err(input.new_unexpected_token_error(t))
|
||||
},
|
||||
Token::Function(ref name) => {
|
||||
let function = CalcNode::math_function(name, location)?;
|
||||
CalcNode::parse_angle(context, input, function)
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i));
|
||||
Token::Number { value, .. } if value == 0. && allow_unitless_zero => {
|
||||
Ok(Angle::zero())
|
||||
},
|
||||
ref t => {
|
||||
let t = t.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue