From 3608dc808833b846fd9fd0a7f7af9b372954c687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 4 May 2017 18:51:18 +0200 Subject: [PATCH] style: Rewrite calc to be cleaner and support arbitrary expressions. This improves Servo's calc support compliant with[1], and makes it cleaner and more straight-forward. [1]: https://github.com/w3c/csswg-drafts/issues/1241 --- components/style/values/specified/calc.rs | 547 +++++++++++++++++++ components/style/values/specified/length.rs | 454 +-------------- components/style/values/specified/mod.rs | 197 +++---- tests/unit/style/parsing/inherited_box.rs | 8 +- tests/unit/style/parsing/length.rs | 1 + tests/unit/style/parsing/value.rs | 19 - tests/unit/style/properties/serialization.rs | 8 +- 7 files changed, 638 insertions(+), 596 deletions(-) create mode 100644 components/style/values/specified/calc.rs diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs new file mode 100644 index 00000000000..4f49df256e7 --- /dev/null +++ b/components/style/values/specified/calc.rs @@ -0,0 +1,547 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +//! [Calc expressions][calc]. +//! +//! [calc]: https://drafts.csswg.org/css-values/#calc-notation + +use app_units::Au; +use cssparser::{Parser, Token}; +use parser::ParserContext; +use std::ascii::AsciiExt; +use std::fmt; +use style_traits::ToCss; +use values::{CSSInteger, CSSFloat, HasViewportPercentage}; +use values::specified::{Angle, Time}; +use values::specified::length::{FontRelativeLength, NoCalcLength, ViewportPercentageLength}; + +/// A node inside a `Calc` expression's AST. +#[derive(Clone, Debug)] +pub enum CalcNode { + /// `` + Length(NoCalcLength), + /// `` + Angle(Angle), + /// `