diff --git a/components/style/values/generics/calc.rs b/components/style/values/generics/calc.rs index 5d52cdf5f5f..c4f63552440 100644 --- a/components/style/values/generics/calc.rs +++ b/components/style/values/generics/calc.rs @@ -158,6 +158,14 @@ impl CalcNode { } } + /// Returns the leaf if we can (if simplification has allowed it). + pub fn as_leaf(&self) -> Option<&L> { + match *self { + Self::Leaf(ref l) => Some(l), + _ => None, + } + } + /// Tries to merge one sum to another, that is, perform `x` + `y`. fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> { match (self, other) { diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index c3abb9170d5..20736231e99 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -43,6 +43,8 @@ pub enum MathFunction { Acos, /// `atan()`: https://drafts.csswg.org/css-values-4/#funcdef-atan Atan, + /// `atan2()`: https://drafts.csswg.org/css-values-4/#funcdef-atan2 + Atan2, } /// A leaf node inside a `Calc` expression's AST. @@ -60,6 +62,15 @@ pub enum Leaf { Number(CSSFloat), } +impl Leaf { + fn as_length(&self) -> Option<&NoCalcLength> { + match *self { + Self::Length(ref l) => Some(l), + _ => None, + } + } +} + impl ToCss for Leaf { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where @@ -75,23 +86,22 @@ impl ToCss for Leaf { } } -/// An expected unit we intend to parse within a `calc()` expression. -/// -/// This is used as a hint for the parser to fast-reject invalid expressions. -#[derive(Clone, Copy, PartialEq)] -enum CalcUnit { - /// `` - Number, - /// `` - Length, - /// `` - Percentage, - /// ` | ` - LengthPercentage, - /// `` - Angle, - /// `