/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! [Calc expressions][calc]. //! //! [calc]: https://drafts.csswg.org/css-values/#calc-notation use crate::parser::ParserContext; use crate::values::generics::calc as generic; use crate::values::generics::calc::{MinMaxOp, ModRemOp, RoundingStrategy, SortKey}; use crate::values::specified::length::{AbsoluteLength, FontRelativeLength, NoCalcLength}; use crate::values::specified::length::{ContainerRelativeLength, ViewportPercentageLength}; use crate::values::specified::{self, Angle, Resolution, Time}; use crate::values::{CSSFloat, CSSInteger}; use cssparser::{AngleOrNumber, CowRcStr, NumberOrPercentage, Parser, Token}; use smallvec::SmallVec; use std::cmp; use std::fmt::{self, Write}; use style_traits::values::specified::AllowedNumericType; use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss}; fn trig_enabled() -> bool { static_prefs::pref!("layout.css.trig.enabled") } fn nan_inf_enabled() -> bool { static_prefs::pref!("layout.css.nan-inf.enabled") } /// The name of the mathematical function that we're parsing. #[derive(Clone, Copy, Debug, Parse)] pub enum MathFunction { /// `calc()`: https://drafts.csswg.org/css-values-4/#funcdef-calc Calc, /// `min()`: https://drafts.csswg.org/css-values-4/#funcdef-min Min, /// `max()`: https://drafts.csswg.org/css-values-4/#funcdef-max Max, /// `clamp()`: https://drafts.csswg.org/css-values-4/#funcdef-clamp Clamp, /// `round()`: https://drafts.csswg.org/css-values-4/#funcdef-round Round, /// `mod()`: https://drafts.csswg.org/css-values-4/#funcdef-mod Mod, /// `rem()`: https://drafts.csswg.org/css-values-4/#funcdef-rem Rem, /// `sin()`: https://drafts.csswg.org/css-values-4/#funcdef-sin Sin, /// `cos()`: https://drafts.csswg.org/css-values-4/#funcdef-cos Cos, /// `tan()`: https://drafts.csswg.org/css-values-4/#funcdef-tan Tan, /// `asin()`: https://drafts.csswg.org/css-values-4/#funcdef-asin Asin, /// `acos()`: https://drafts.csswg.org/css-values-4/#funcdef-acos Acos, /// `atan()`: https://drafts.csswg.org/css-values-4/#funcdef-atan Atan, /// `atan2()`: https://drafts.csswg.org/css-values-4/#funcdef-atan2 Atan2, /// `pow()`: https://drafts.csswg.org/css-values-4/#funcdef-pow Pow, /// `sqrt()`: https://drafts.csswg.org/css-values-4/#funcdef-sqrt Sqrt, /// `hypot()`: https://drafts.csswg.org/css-values-4/#funcdef-hypot Hypot, /// `log()`: https://drafts.csswg.org/css-values-4/#funcdef-log Log, /// `exp()`: https://drafts.csswg.org/css-values-4/#funcdef-exp Exp, } /// A leaf node inside a `Calc` expression's AST. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)] pub enum Leaf { /// `` Length(NoCalcLength), /// `` Angle(Angle), /// `