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
This commit is contained in:
Emilio Cobos Álvarez 2017-05-04 18:51:18 +02:00
parent 36f26148e6
commit 3608dc8088
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
7 changed files with 638 additions and 596 deletions

View file

@ -6,7 +6,6 @@ use app_units::Au;
use parsing::parse;
use style::values::HasViewportPercentage;
use style::values::specified::{AbsoluteLength, NoCalcLength, ViewportPercentageLength};
use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit};
#[test]
fn length_has_viewport_percentage() {
@ -15,21 +14,3 @@ fn length_has_viewport_percentage() {
let l = NoCalcLength::Absolute(AbsoluteLength::Px(Au(100).to_f32_px()));
assert!(!l.has_viewport_percentage());
}
#[test]
fn calc_top_level_number_with_unit() {
fn parse_value(text: &str, unit: CalcUnit) -> Result<CalcLengthOrPercentage, ()> {
parse(|context, input| CalcLengthOrPercentage::parse(context, input, unit), text)
}
assert_eq!(parse_value("1", CalcUnit::Length), Err(()));
assert_eq!(parse_value("1", CalcUnit::LengthOrPercentage), Err(()));
assert_eq!(parse_value("1", CalcUnit::Angle), Err(()));
assert_eq!(parse_value("1", CalcUnit::Time), Err(()));
assert_eq!(parse_value("1px + 1", CalcUnit::Length), Err(()));
assert_eq!(parse_value("1em + 1", CalcUnit::Length), Err(()));
assert_eq!(parse_value("1px + 1", CalcUnit::LengthOrPercentage), Err(()));
assert_eq!(parse_value("1% + 1", CalcUnit::LengthOrPercentage), Err(()));
assert_eq!(parse_value("1rad + 1", CalcUnit::Angle), Err(()));
assert_eq!(parse_value("1deg + 1", CalcUnit::Angle), Err(()));
assert_eq!(parse_value("1s + 1", CalcUnit::Time), Err(()));
}