diff --git a/components/style/color/convert.rs b/components/style/color/convert.rs index 78d5a9da544..4fa037f9d6d 100644 --- a/components/style/color/convert.rs +++ b/components/style/color/convert.rs @@ -45,7 +45,7 @@ fn rgb_to_hue_min_max(red: f32, green: f32, blue: f32) -> (f32, f32, f32) { (red - green) / delta + 4.0 } } else { - std::f32::NAN + f32::NAN }; (hue, min, max) diff --git a/components/style/lib.rs b/components/style/lib.rs index 8cf85868a86..90a52e567b1 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -107,6 +107,7 @@ pub mod media_queries; pub mod parallel; pub mod parser; pub mod piecewise_linear; +pub mod properties_and_values; #[macro_use] pub mod queries; pub mod rule_cache; diff --git a/components/style/properties_and_values/mod.rs b/components/style/properties_and_values/mod.rs new file mode 100644 index 00000000000..3590d1279cc --- /dev/null +++ b/components/style/properties_and_values/mod.rs @@ -0,0 +1,9 @@ +/* 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/. */ + +//! Properties and Values +//! +//! https://drafts.css-houdini.org/css-properties-values-api-1/ + +pub mod syntax; diff --git a/components/style/properties_and_values/syntax/ascii.rs b/components/style/properties_and_values/syntax/ascii.rs new file mode 100644 index 00000000000..e1a1b08535b --- /dev/null +++ b/components/style/properties_and_values/syntax/ascii.rs @@ -0,0 +1,60 @@ +/* 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/. */ + +/// Trims ASCII whitespace characters from a slice, and returns the trimmed input. +pub fn trim_ascii_whitespace(input: &str) -> &str { + if input.is_empty() { + return input; + } + + let mut start = 0; + { + let mut iter = input.as_bytes().iter(); + loop { + let byte = match iter.next() { + Some(b) => b, + None => return "", + }; + + if !byte.is_ascii_whitespace() { + break; + } + start += 1; + } + } + + let mut end = input.len(); + assert!(start < end); + { + let mut iter = input.as_bytes()[start..].iter().rev(); + loop { + let byte = match iter.next() { + Some(b) => b, + None => { + debug_assert!(false, "We should have caught this in the loop above!"); + return ""; + }, + }; + + if !byte.is_ascii_whitespace() { + break; + } + end -= 1; + } + } + + &input[start..end] +} + +#[test] +fn trim_ascii_whitespace_test() { + fn test(i: &str, o: &str) { + assert_eq!(trim_ascii_whitespace(i), o) + } + + test("", ""); + test(" ", ""); + test(" a b c ", "a b c"); + test(" \t \t \ta b c \t \t \t \t", "a b c"); +} diff --git a/components/style/properties_and_values/syntax/data_type.rs b/components/style/properties_and_values/syntax/data_type.rs new file mode 100644 index 00000000000..db5c1478db6 --- /dev/null +++ b/components/style/properties_and_values/syntax/data_type.rs @@ -0,0 +1,91 @@ +/* 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/. */ + +use super::{Component, ComponentName, Multiplier}; + +/// +#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)] +pub enum DataType { + /// Any valid `` value + Length, + /// `` values + Number, + /// Any valid value + Percentage, + /// Any valid `` or `` value, any valid `` expression combining + /// `` and `` components. + LengthPercentage, + /// Any valid `` value + Color, + /// Any valid `` value + Image, + /// Any valid `` value + Url, + /// Any valid `` value + Integer, + /// Any valid `` value + Angle, + /// Any valid `