From 1182296c4b1ce682f170bc5398a92a01f425b2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 27 Apr 2023 19:52:28 +0000 Subject: [PATCH] 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 --- components/style/values/specified/angle.rs | 2 +- components/style/values/specified/calc.rs | 7 +++++-- components/style/values/specified/color.rs | 4 ++-- components/style/values/specified/length.rs | 4 ++-- components/style/values/specified/mod.rs | 4 ++-- components/style/values/specified/percentage.rs | 2 +- components/style/values/specified/resolution.rs | 2 +- components/style/values/specified/time.rs | 2 +- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/components/style/values/specified/angle.rs b/components/style/values/specified/angle.rs index 212aa5fb03b..54b690c80c7 100644 --- a/components/style/values/specified/angle.rs +++ b/components/style/values/specified/angle.rs @@ -260,7 +260,7 @@ impl Angle { } }, 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) }, Token::Number { value, .. } if value == 0. && allow_unitless_zero => Ok(Angle::zero()), diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index ff6380380a0..073b5b650ff 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -456,7 +456,7 @@ impl CalcNode { CalcNode::parse_argument(context, input, allowed_units) }), &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) }, &Token::Ident(ref ident) => { @@ -905,6 +905,7 @@ impl CalcNode { /// return a mathematical function corresponding to that name or an error. #[inline] pub fn math_function<'i>( + context: &ParserContext, name: &CowRcStr<'i>, location: cssparser::SourceLocation, ) -> Result> { @@ -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() } else if matches!(function, Round) { round_enabled() diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index eb24b8717ed..078009c21e5 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -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::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) }, 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 }) }, 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) }, ref t => return Err(location.new_unexpected_token_error(t.clone())), diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 5aa3eb65966..23749d6a8b7 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1307,7 +1307,7 @@ impl Length { )))) }, 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)?; Ok(Length::Calc(Box::new(calc))) }, @@ -1536,7 +1536,7 @@ impl LengthPercentage { } }, Token::Function(ref name) => { - let function = CalcNode::math_function(name, location)?; + let function = CalcNode::math_function(context, name, location)?; let calc = CalcNode::parse_length_or_percentage(context, input, num_context, function)?; Ok(LengthPercentage::Calc(Box::new(calc))) diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 3dedfa221ca..1acf622980c 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -199,7 +199,7 @@ fn parse_number_with_clamping_mode<'i, 't>( }) }, 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)?; Ok(Number { value: result.min(f32::MAX).max(f32::MIN), @@ -633,7 +633,7 @@ impl Parse for Integer { int_value: Some(v), .. } => Ok(Integer::new(v)), 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)?; Ok(Integer::from_calc(result)) }, diff --git a/components/style/values/specified/percentage.rs b/components/style/values/specified/percentage.rs index 62dca187635..6e6869d8700 100644 --- a/components/style/values/specified/percentage.rs +++ b/components/style/values/specified/percentage.rs @@ -119,7 +119,7 @@ impl Percentage { Ok(Percentage::new(unit_value)) }, 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)?; Ok(Percentage { value, diff --git a/components/style/values/specified/resolution.rs b/components/style/values/specified/resolution.rs index 5e8b0ef656c..87284615e63 100644 --- a/components/style/values/specified/resolution.rs +++ b/components/style/values/specified/resolution.rs @@ -132,7 +132,7 @@ impl Parse for Resolution { } => Self::parse_dimension(value, unit) .map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)), 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) }, ref t => return Err(location.new_unexpected_token_error(t.clone())), diff --git a/components/style/values/specified/time.rs b/components/style/values/specified/time.rs index 59900438a9c..3fbba214f36 100644 --- a/components/style/values/specified/time.rs +++ b/components/style/values/specified/time.rs @@ -109,7 +109,7 @@ impl Time { .map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) }, 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) }, ref t => return Err(location.new_unexpected_token_error(t.clone())),