mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Enable all math functions on chrome code
They should be stable. Not sure this is worth writing a test for since the idea is that this code goes away eventually. Differential Revision: https://phabricator.services.mozilla.com/D176680
This commit is contained in:
parent
a523fffc9e
commit
1182296c4b
8 changed files with 15 additions and 12 deletions
|
@ -260,7 +260,7 @@ impl Angle {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
CalcNode::parse_angle(context, input, function)
|
CalcNode::parse_angle(context, input, function)
|
||||||
},
|
},
|
||||||
Token::Number { value, .. } if value == 0. && allow_unitless_zero => Ok(Angle::zero()),
|
Token::Number { value, .. } if value == 0. && allow_unitless_zero => Ok(Angle::zero()),
|
||||||
|
|
|
@ -456,7 +456,7 @@ impl CalcNode {
|
||||||
CalcNode::parse_argument(context, input, allowed_units)
|
CalcNode::parse_argument(context, input, allowed_units)
|
||||||
}),
|
}),
|
||||||
&Token::Function(ref name) => {
|
&Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
CalcNode::parse(context, input, function, allowed_units)
|
CalcNode::parse(context, input, function, allowed_units)
|
||||||
},
|
},
|
||||||
&Token::Ident(ref ident) => {
|
&Token::Ident(ref ident) => {
|
||||||
|
@ -905,6 +905,7 @@ impl CalcNode {
|
||||||
/// return a mathematical function corresponding to that name or an error.
|
/// return a mathematical function corresponding to that name or an error.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn math_function<'i>(
|
pub fn math_function<'i>(
|
||||||
|
context: &ParserContext,
|
||||||
name: &CowRcStr<'i>,
|
name: &CowRcStr<'i>,
|
||||||
location: cssparser::SourceLocation,
|
location: cssparser::SourceLocation,
|
||||||
) -> Result<MathFunction, ParseError<'i>> {
|
) -> Result<MathFunction, ParseError<'i>> {
|
||||||
|
@ -917,7 +918,9 @@ impl CalcNode {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let enabled = if matches!(function, Sin | Cos | Tan | Asin | Acos | Atan | Atan2) {
|
let enabled = if context.chrome_rules_enabled() {
|
||||||
|
true
|
||||||
|
} else if matches!(function, Sin | Cos | Tan | Asin | Acos | Atan | Atan2) {
|
||||||
trig_enabled()
|
trig_enabled()
|
||||||
} else if matches!(function, Round) {
|
} else if matches!(function, Round) {
|
||||||
round_enabled()
|
round_enabled()
|
||||||
|
|
|
@ -556,7 +556,7 @@ impl<'a, 'b: 'a, 'i: 'a> ::cssparser::ColorParser<'i> for ColorParser<'a, 'b> {
|
||||||
},
|
},
|
||||||
Token::Number { value, .. } => Ok(AngleOrNumber::Number { value }),
|
Token::Number { value, .. } => Ok(AngleOrNumber::Number { value }),
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(self.0, name, location)?;
|
||||||
CalcNode::parse_angle_or_number(self.0, input, function)
|
CalcNode::parse_angle_or_number(self.0, input, function)
|
||||||
},
|
},
|
||||||
t => return Err(location.new_unexpected_token_error(t)),
|
t => return Err(location.new_unexpected_token_error(t)),
|
||||||
|
@ -585,7 +585,7 @@ impl<'a, 'b: 'a, 'i: 'a> ::cssparser::ColorParser<'i> for ColorParser<'a, 'b> {
|
||||||
Ok(NumberOrPercentage::Percentage { unit_value })
|
Ok(NumberOrPercentage::Percentage { unit_value })
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(self.0, name, location)?;
|
||||||
CalcNode::parse_number_or_percentage(self.0, input, function)
|
CalcNode::parse_number_or_percentage(self.0, input, function)
|
||||||
},
|
},
|
||||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||||
|
|
|
@ -1307,7 +1307,7 @@ impl Length {
|
||||||
))))
|
))))
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
let calc = CalcNode::parse_length(context, input, num_context, function)?;
|
let calc = CalcNode::parse_length(context, input, num_context, function)?;
|
||||||
Ok(Length::Calc(Box::new(calc)))
|
Ok(Length::Calc(Box::new(calc)))
|
||||||
},
|
},
|
||||||
|
@ -1536,7 +1536,7 @@ impl LengthPercentage {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
let calc =
|
let calc =
|
||||||
CalcNode::parse_length_or_percentage(context, input, num_context, function)?;
|
CalcNode::parse_length_or_percentage(context, input, num_context, function)?;
|
||||||
Ok(LengthPercentage::Calc(Box::new(calc)))
|
Ok(LengthPercentage::Calc(Box::new(calc)))
|
||||||
|
|
|
@ -199,7 +199,7 @@ fn parse_number_with_clamping_mode<'i, 't>(
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
let result = CalcNode::parse_number(context, input, function)?;
|
let result = CalcNode::parse_number(context, input, function)?;
|
||||||
Ok(Number {
|
Ok(Number {
|
||||||
value: result.min(f32::MAX).max(f32::MIN),
|
value: result.min(f32::MAX).max(f32::MIN),
|
||||||
|
@ -633,7 +633,7 @@ impl Parse for Integer {
|
||||||
int_value: Some(v), ..
|
int_value: Some(v), ..
|
||||||
} => Ok(Integer::new(v)),
|
} => Ok(Integer::new(v)),
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
let result = CalcNode::parse_integer(context, input, function)?;
|
let result = CalcNode::parse_integer(context, input, function)?;
|
||||||
Ok(Integer::from_calc(result))
|
Ok(Integer::from_calc(result))
|
||||||
},
|
},
|
||||||
|
|
|
@ -119,7 +119,7 @@ impl Percentage {
|
||||||
Ok(Percentage::new(unit_value))
|
Ok(Percentage::new(unit_value))
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
let value = CalcNode::parse_percentage(context, input, function)?;
|
let value = CalcNode::parse_percentage(context, input, function)?;
|
||||||
Ok(Percentage {
|
Ok(Percentage {
|
||||||
value,
|
value,
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl Parse for Resolution {
|
||||||
} => Self::parse_dimension(value, unit)
|
} => Self::parse_dimension(value, unit)
|
||||||
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
CalcNode::parse_resolution(context, input, function)
|
CalcNode::parse_resolution(context, input, function)
|
||||||
},
|
},
|
||||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl Time {
|
||||||
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
},
|
},
|
||||||
Token::Function(ref name) => {
|
Token::Function(ref name) => {
|
||||||
let function = CalcNode::math_function(name, location)?;
|
let function = CalcNode::math_function(context, name, location)?;
|
||||||
CalcNode::parse_time(context, input, clamping_mode, function)
|
CalcNode::parse_time(context, input, clamping_mode, function)
|
||||||
},
|
},
|
||||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue