diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2015-11-07 06:02:36 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2015-11-07 06:02:36 +0530 |
commit | faf2f34772fe06396a7b8542b00f0566832bc7ef (patch) | |
tree | ab093d99f382cbfadf10ffc0371b9ba126fea32c | |
parent | 33bbed7dc1d3e4f26fbf87e02d2f821015590743 (diff) | |
parent | 3973085cb69ab06b998e62ebf0c65e1a099a7af0 (diff) | |
download | servo-faf2f34772fe06396a7b8542b00f0566832bc7ef.tar.gz servo-faf2f34772fe06396a7b8542b00f0566832bc7ef.zip |
Auto merge of #8343 - servo:custom-properties, r=mbrubeck
Fix some custom properties bugs
Fix #7767.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8343)
<!-- Reviewable:end -->
-rw-r--r-- | components/canvas/Cargo.toml | 5 | ||||
-rw-r--r-- | components/canvas_traits/Cargo.toml | 5 | ||||
-rw-r--r-- | components/layout/Cargo.toml | 9 | ||||
-rw-r--r-- | components/script/Cargo.toml | 9 | ||||
-rw-r--r-- | components/script/dom/cssstyledeclaration.rs | 56 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 36 | ||||
-rw-r--r-- | components/style/Cargo.toml | 10 | ||||
-rw-r--r-- | components/style/custom_properties.rs | 188 | ||||
-rw-r--r-- | components/style/font_face.rs | 25 | ||||
-rw-r--r-- | components/style/properties.mako.rs | 284 | ||||
-rw-r--r-- | components/style/values.rs | 41 | ||||
-rw-r--r-- | components/style_traits/Cargo.toml | 10 | ||||
-rw-r--r-- | components/util/Cargo.toml | 9 | ||||
-rw-r--r-- | ports/cef/Cargo.lock | 32 | ||||
-rw-r--r-- | ports/gonk/Cargo.lock | 32 | ||||
-rw-r--r-- | tests/unit/style/Cargo.toml | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/css/test_variable_serialization_computed.html.ini | 53 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/css/test_variable_serialization_specified.html.ini | 116 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/css/test_variable_serialization_specified.html | 5 |
19 files changed, 422 insertions, 509 deletions
diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index 37276b5baf0..e3300568270 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -34,11 +34,8 @@ features = ["texture_surface"] [dependencies.ipc-channel] git = "https://github.com/pcwalton/ipc-channel" -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies] +cssparser = { version = "0.4", features = [ "serde-serialization" ] } log = "0.3" num = "0.1.24" gleam = "0.1" diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml index cd854a761b9..ec49ede4d32 100644 --- a/components/canvas_traits/Cargo.toml +++ b/components/canvas_traits/Cargo.toml @@ -28,10 +28,6 @@ git = "https://github.com/pcwalton/ipc-channel" version = "0.6" features = [ "nightly" ] -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies.plugins] path = "../plugins" @@ -39,6 +35,7 @@ path = "../plugins" path = "../util" [dependencies] +cssparser = { version = "0.4", features = [ "serde-serialization" ] } euclid = {version = "0.3", features = ["plugins"]} serde_macros = "0.6" diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 10af4f1566d..8697897c7b5 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -50,16 +50,9 @@ path = "../profile_traits" [dependencies.util] path = "../util" -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" - [dependencies.clock_ticks] git = "https://github.com/tomaka/clock_ticks" -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies.ipc-channel] git = "https://github.com/pcwalton/ipc-channel" @@ -69,12 +62,14 @@ features = [ "serde_serialization" ] [dependencies] app_units = {version = "0.1", features = ["plugins"]} +cssparser = { version = "0.4", features = [ "serde-serialization" ] } log = "0.3" encoding = "0.2" fnv = "1.0" bitflags = "0.3" rustc-serialize = "0.3" libc = "0.1" +selectors = "0.2" smallvec = "0.1" string_cache = "0.1" string_cache_plugin = "0.1" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index b2b96d04f72..34043b52a75 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -42,9 +42,6 @@ path = "../canvas" [dependencies.canvas_traits] path = "../canvas_traits" -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" - [dependencies.js] git = "https://github.com/servo/rust-mozjs" @@ -59,10 +56,6 @@ git = "https://github.com/ecoal95/rust-offscreen-rendering-context" git = "https://github.com/ecoal95/angle" branch = "servo" -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies.ipc-channel] git = "https://github.com/pcwalton/ipc-channel" @@ -76,6 +69,7 @@ features = ["unstable"] [dependencies] app_units = {version = "0.1", features = ["plugins"]} +cssparser = { version = "0.4", features = [ "serde-serialization" ] } log = "0.3" encoding = "0.2" fnv = "1.0" @@ -89,6 +83,7 @@ websocket = "0.12.0" uuid = "0.1.16" smallvec = "0.1" html5ever = { version = "0.2.1", features = ["unstable"] } +selectors = "0.2" string_cache = { version = "0.1.15", features = ["unstable"] } string_cache_plugin = "0.1" euclid = {version = "0.3", features = ["plugins"]} diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 91e2af7b0b0..aa2ce366819 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -16,8 +16,8 @@ use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Ref; use string_cache::Atom; -use style::properties::PropertyDeclaration; -use style::properties::{is_supported_property, longhands_from_shorthand, parse_one_declaration}; +use style::properties::{PropertyDeclaration, Shorthand}; +use style::properties::{is_supported_property, parse_one_declaration}; use util::str::{DOMString, str_join}; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface @@ -48,9 +48,27 @@ macro_rules! css_properties( ); ); -fn serialize_list(list: &[Ref<PropertyDeclaration>]) -> DOMString { - let str_iter = list.iter().map(|d| d.value()); - DOMString(str_join(str_iter, " ")) +fn serialize_shorthand(shorthand: Shorthand, declarations: &[Ref<PropertyDeclaration>]) + -> String { + // https://drafts.csswg.org/css-variables/#variables-in-shorthands + if let Some(css) = declarations[0].with_variables_from_shorthand(shorthand) { + if declarations[1..].iter() + .all(|d| d.with_variables_from_shorthand(shorthand) == Some(css)) { + css.to_owned() + } else { + String::new() + } + } else { + if declarations.iter().any(|d| d.with_variables()) { + String::new() + } else { + let str_iter = declarations.iter().map(|d| d.value()); + // FIXME: this needs property-specific code, which probably should be in style/ + // "as appropriate according to the grammar of shorthand " + // https://drafts.csswg.org/cssom/#serialize-a-css-value + str_join(str_iter, " ") + } + } } impl CSSStyleDeclaration { @@ -130,13 +148,12 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { } // Step 2 - let longhand_properties = longhands_from_shorthand(&property); - if let Some(longhand_properties) = longhand_properties { + if let Some(shorthand) = Shorthand::from_name(&property) { // Step 2.1 let mut list = vec!(); // Step 2.2 - for longhand in &*longhand_properties { + for longhand in shorthand.longhands() { // Step 2.2.1 let declaration = owner.get_inline_style_declaration(&Atom::from_slice(&longhand)); @@ -148,7 +165,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { } // Step 2.3 - return serialize_list(&list); + return DOMString(serialize_shorthand(shorthand, &list)); } // Step 3 & 4 @@ -166,12 +183,11 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let property = Atom::from_slice(&property); // Step 2 - let longhand_properties = longhands_from_shorthand(&property); - if let Some(longhand_properties) = longhand_properties { + if let Some(shorthand) = Shorthand::from_name(&property) { // Step 2.1 & 2.2 & 2.3 - if longhand_properties.iter() - .map(|&longhand| self.GetPropertyPriority(DOMString(longhand.to_owned()))) - .all(|priority| priority == "important") { + if shorthand.longhands().iter() + .map(|&longhand| self.GetPropertyPriority(DOMString(longhand.to_owned()))) + .all(|priority| priority == "important") { return DOMString("important".to_owned()); } @@ -261,8 +277,10 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let element = self.owner.upcast::<Element>(); // Step 5 & 6 - match longhands_from_shorthand(&property) { - Some(properties) => element.set_inline_style_property_priority(properties, priority), + match Shorthand::from_name(&property) { + Some(shorthand) => { + element.set_inline_style_property_priority(shorthand.longhands(), priority) + } None => element.set_inline_style_property_priority(&[&*property], priority) } @@ -292,10 +310,10 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { let elem = self.owner.upcast::<Element>(); - match longhands_from_shorthand(&property) { + match Shorthand::from_name(&property) { // Step 4 - Some(longhands) => { - for longhand in &*longhands { + Some(shorthand) => { + for longhand in shorthand.longhands() { elem.remove_inline_style_property(longhand) } } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 71f72c8f7ad..9cf20c4fe1b 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -151,7 +151,7 @@ version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -169,7 +169,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", @@ -321,7 +321,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.9" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -994,7 +994,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1011,7 +1011,7 @@ dependencies = [ "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1502,7 +1502,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1523,7 +1523,7 @@ dependencies = [ "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1570,11 +1570,11 @@ dependencies = [ [[package]] name = "selectors" -version = "0.2.0" -source = "git+https://github.com/servo/rust-selectors#53f5e09a37684f6a42eb894d7a6fd0b14380a1c6" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1718,7 +1718,7 @@ version = "0.0.1" dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1728,7 +1728,7 @@ dependencies = [ "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1744,9 +1744,9 @@ name = "style_tests" version = "0.0.1" dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache_plugin 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", @@ -1759,14 +1759,14 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1895,7 +1895,7 @@ dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1911,7 +1911,7 @@ dependencies = [ "plugins 0.0.1", "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 9f0a2dfdcfc..d3014bf38dd 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -18,20 +18,13 @@ path = "../util" [dependencies.style_traits] path = "../style_traits" -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" -features = ["unstable"] - -[dependencies.cssparser] -version = "0.3.9" -features = [ "serde-serialization" ] - [dependencies.url] version = "0.2" features = [ "serde_serialization" ] [dependencies] app_units = {version = "0.1", features = ["plugins"]} +cssparser = { version = "0.4", features = [ "serde-serialization" ] } log = "0.3" encoding = "0.2" fnv = "1.0" @@ -40,6 +33,7 @@ matches = "0.1" bitflags = "0.3" num = "0.1.24" lazy_static = "0.1.10" +selectors = { version = "0.2", features = ["unstable"] } smallvec = "0.1" string_cache = "0.1" string_cache_plugin = "0.1" diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index b5f7c3f3232..fbcf4c46b0e 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -5,6 +5,7 @@ use cssparser::{Delimiter, Parser, SourcePosition, ToCss, Token, TokenSerializationType}; use properties::DeclaredValue; use std::ascii::AsciiExt; +use std::borrow::Cow; use std::collections::{HashMap, HashSet}; use std::fmt; use std::sync::Arc; @@ -23,7 +24,7 @@ pub fn parse_name(s: &str) -> Result<&str, ()> { } } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug)] pub struct SpecifiedValue { css: String, @@ -41,7 +42,7 @@ pub struct BorrowedSpecifiedValue<'a> { references: Option<&'a HashSet<Name>>, } -#[derive(Clone, HeapSizeOf)] +#[derive(Clone, HeapSizeOf, Debug)] pub struct ComputedValue { css: String, first_token_type: TokenSerializationType, @@ -73,6 +74,11 @@ impl ComputedValue { fn push(&mut self, css: &str, css_first_token_type: TokenSerializationType, css_last_token_type: TokenSerializationType) { + // This happens e.g. between to subsequent var() functions: `var(--a)var(--b)`. + // In that case, css_*_token_type is non-sensical. + if css.is_empty() { + return + } self.first_token_type.set_if_nothing(css_first_token_type); // If self.first_token_type was nothing, // self.last_token_type is also nothing and this will be false: @@ -94,44 +100,99 @@ impl ComputedValue { } pub fn parse(input: &mut Parser) -> Result<SpecifiedValue, ()> { - let start = input.position(); let mut references = Some(HashSet::new()); - let (first, last) = try!(parse_declaration_value(input, &mut references)); + let (first, css, last) = try!(parse_self_contained_declaration_value(input, &mut references)); Ok(SpecifiedValue { - css: input.slice_from(start).to_owned(), + css: css.into_owned(), first_token_type: first, last_token_type: last, references: references.unwrap(), }) } +/// Parse the value of a non-custom property that contains `var()` references. +pub fn parse_non_custom_with_var<'i, 't> + (input: &mut Parser<'i, 't>) + -> Result<(TokenSerializationType, Cow<'i, str>), ()> { + let (first_token_type, css, _) = try!(parse_self_contained_declaration_value(input, &mut None)); + Ok((first_token_type, css)) +} + +fn parse_self_contained_declaration_value<'i, 't> + (input: &mut Parser<'i, 't>, + references: &mut Option<HashSet<Name>>) + -> Result<( + TokenSerializationType, + Cow<'i, str>, + TokenSerializationType + ), ()> { + let start_position = input.position(); + let mut missing_closing_characters = String::new(); + let (first, last) = try!( + parse_declaration_value(input, references, &mut missing_closing_characters)); + let mut css: Cow<str> = input.slice_from(start_position).into(); + if !missing_closing_characters.is_empty() { + // Unescaped backslash at EOF in a quoted string is ignored. + if css.ends_with("\\") && matches!(missing_closing_characters.as_bytes()[0], b'"' | b'\'') { + css.to_mut().pop(); + } + css.to_mut().push_str(&missing_closing_characters); + } + Ok((first, css, last)) +} + /// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value -pub fn parse_declaration_value(input: &mut Parser, references: &mut Option<HashSet<Name>>) - -> Result<(TokenSerializationType, TokenSerializationType), ()> { +fn parse_declaration_value<'i, 't> + (input: &mut Parser<'i, 't>, + references: &mut Option<HashSet<Name>>, + missing_closing_characters: &mut String) + -> Result<(TokenSerializationType, TokenSerializationType), ()> { input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { // Need at least one token let start_position = input.position(); try!(input.next_including_whitespace()); input.reset(start_position); - parse_declaration_value_block(input, references) + parse_declaration_value_block(input, references, missing_closing_characters) }) } /// Like parse_declaration_value, /// but accept `!` and `;` since they are only invalid at the top level -fn parse_declaration_value_block(input: &mut Parser, references: &mut Option<HashSet<Name>>) +fn parse_declaration_value_block(input: &mut Parser, + references: &mut Option<HashSet<Name>>, + missing_closing_characters: &mut String) -> Result<(TokenSerializationType, TokenSerializationType), ()> { - let mut first_token_type = TokenSerializationType::nothing(); - let mut last_token_type = TokenSerializationType::nothing(); - while let Ok(token) = input.next_including_whitespace_and_comments() { - first_token_type.set_if_nothing(token.serialization_type()); - // This may be OpenParen when it should be Other (for the closing paren) - // but that doesn’t make a difference since OpenParen is only special - // when it comes *after* an identifier (it would turn into a function) - // but a "last" token will only be concantenated *before* another unrelated token. - last_token_type = token.serialization_type(); - match token { + let mut token_start = input.position(); + let mut token = match input.next_including_whitespace_and_comments() { + Ok(token) => token, + Err(()) => return Ok((TokenSerializationType::nothing(), TokenSerializationType::nothing())) + }; + let first_token_type = token.serialization_type(); + loop { + macro_rules! nested { + () => { + try!(input.parse_nested_block(|input| { + parse_declaration_value_block(input, references, missing_closing_characters) + })) + } + } + macro_rules! check_closed { + ($closing: expr) => { + if !input.slice_from(token_start).ends_with($closing) { + missing_closing_characters.push_str($closing) + } + } + } + let last_token_type = match token { + Token::Comment(_) => { + let token_slice = input.slice_from(token_start); + if !token_slice.ends_with("*/") { + missing_closing_characters.push_str( + if token_slice.ends_with("*") { "/" } else { "*/" }) + } + token.serialization_type() + } Token::BadUrl | Token::BadString | Token::CloseParenthesis | @@ -139,35 +200,90 @@ fn parse_declaration_value_block(input: &mut Parser, references: &mut Option<Has Token::CloseCurlyBracket => { return Err(()) } - - Token::Function(ref name) if name.eq_ignore_ascii_case("var") => { - try!(input.parse_nested_block(|input| { - parse_var_function(input, references) - })); + Token::Function(ref name) => { + if name.eq_ignore_ascii_case("var") { + let position = input.position(); + try!(input.parse_nested_block(|input| { + parse_var_function(input, references) + })); + input.reset(position); + } + nested!(); + check_closed!(")"); + Token::CloseParenthesis.serialization_type() + } + Token::ParenthesisBlock => { + nested!(); + check_closed!(")"); + Token::CloseParenthesis.serialization_type() + } + Token::CurlyBracketBlock => { + nested!(); + check_closed!("}"); + Token::CloseCurlyBracket.serialization_type() } - - Token::Function(_) | - Token::ParenthesisBlock | - Token::CurlyBracketBlock | Token::SquareBracketBlock => { - try!(input.parse_nested_block(|input| { - parse_declaration_value_block(input, references) - })); + nested!(); + check_closed!("]"); + Token::CloseSquareBracket.serialization_type() + } + Token::QuotedString(_) => { + let token_slice = input.slice_from(token_start); + let quote = &token_slice[..1]; + debug_assert!(matches!(quote, "\"" | "'")); + if !(token_slice.ends_with(quote) && token_slice.len() > 1) { + missing_closing_characters.push_str(quote) + } + token.serialization_type() + } + Token::Ident(ref value) | + Token::AtKeyword(ref value) | + Token::Hash(ref value) | + Token::IDHash(ref value) | + Token::UnquotedUrl(ref value) | + Token::Dimension(_, ref value) => { + if value.ends_with("�") && input.slice_from(token_start).ends_with("\\") { + // Unescaped backslash at EOF in these contexts is interpreted as U+FFFD + // Check the value in case the final backslash was itself escaped. + // Serialize as escaped U+FFFD, which is also interpreted as U+FFFD. + // (Unescaped U+FFFD would also work, but removing the backslash is annoying.) + missing_closing_characters.push_str("�") + } + if matches!(token, Token::UnquotedUrl(_)) { + check_closed!(")"); + } + token.serialization_type() + } + _ => { + token.serialization_type() } + }; - _ => {} + token_start = input.position(); + token = if let Ok(token) = input.next_including_whitespace_and_comments() { + token + } else { + return Ok((first_token_type, last_token_type)) } } - Ok((first_token_type, last_token_type)) } // If the var function is valid, return Ok((custom_property_name, fallback)) -fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, references: &mut Option<HashSet<Name>>) +fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, + references: &mut Option<HashSet<Name>>) -> Result<(), ()> { let name = try!(input.expect_ident()); let name = try!(parse_name(&name)); - if input.expect_comma().is_ok() { - try!(parse_declaration_value(input, references)); + if input.try(|input| input.expect_comma()).is_ok() { + // Exclude `!` and `;` at the top level + // https://drafts.csswg.org/css-syntax/#typedef-declaration-value + try!(input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { + // At least one non-comment token. + try!(input.next_including_whitespace()); + // Skip until the end. + while let Ok(_) = input.next_including_whitespace_and_comments() {} + Ok(()) + })); } if let Some(ref mut refs) = *references { refs.insert(Atom::from_slice(name)); diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 54ffdcc7891..eea501b9cf2 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use computed_values::font_family::FontFamily; -use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token}; +use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use parser::{ParserContext, log_css_error}; use properties::longhands::font_family::parse_one_family; use std::ascii::AsciiExt; @@ -106,23 +106,12 @@ fn parse_one_non_generic_family_name(input: &mut Parser) -> Result<Atom, ()> { fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source, ()> { - let url = match input.next() { - // Parsing url() - Ok(Token::Url(url)) => { - UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else( - |_error| Url::parse("about:invalid").unwrap()) - }, - // Parsing local() with early return - Ok(Token::Function(name)) => { - if name.eq_ignore_ascii_case("local") { - return Ok(Source::Local(try!(input.parse_nested_block(|input| { - parse_one_non_generic_family_name(input) - })))) - } - return Err(()) - }, - _ => return Err(()) - }; + if input.try(|input| input.expect_function_matching("local")).is_ok() { + return Ok(Source::Local(try!(input.parse_nested_block(parse_one_non_generic_family_name)))) + } + let url = try!(input.expect_url()); + let url = UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else( + |_error| Url::parse("about:invalid").unwrap()); // Parsing optional format() let format_hints = if input.try(|input| input.expect_function_matching("format")).is_ok() { diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index a0ae4363037..847155c8de8 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -8,14 +8,13 @@ use std::ascii::AsciiExt; use std::collections::HashSet; use std::default::Default; use std::fmt; -use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::intrinsics; use std::mem; use std::sync::Arc; use app_units::Au; -use cssparser::{Parser, Color, RGBA, AtRuleParser, DeclarationParser, +use cssparser::{Parser, Color, RGBA, AtRuleParser, DeclarationParser, Delimiter, DeclarationListParser, parse_important, ToCss, TokenSerializationType}; use url::Url; use util::logical_geometry::{LogicalMargin, PhysicalSide, WritingMode}; @@ -211,13 +210,13 @@ pub mod longhands { let var = input.seen_var_functions(); if specified.is_err() && var { input.reset(start); - let (first_token_type, _) = try!( - ::custom_properties::parse_declaration_value(input, &mut None)); + let (first_token_type, css) = try!( + ::custom_properties::parse_non_custom_with_var(input)); return Ok(DeclaredValue::WithVariables { - css: input.slice_from(start).to_owned(), + css: css.into_owned(), first_token_type: first_token_type, base_url: context.base_url.clone(), - from_shorthand: Shorthand::None, + from_shorthand: None, }) } specified @@ -334,7 +333,7 @@ pub mod longhands { -> Result<SpecifiedValue, ()> { specified::parse_border_width(input).map(SpecifiedValue) } - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(pub specified::Length); pub mod computed_value { use app_units::Au; @@ -401,7 +400,7 @@ pub mod longhands { pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { specified::parse_border_width(input).map(SpecifiedValue) } - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(pub specified::Length); pub mod computed_value { use app_units::Au; @@ -673,7 +672,7 @@ pub mod longhands { use values::CSSFloat; use values::computed::Context; - #[derive(Clone, PartialEq, Copy)] + #[derive(Debug, Clone, PartialEq, Copy)] pub enum SpecifiedValue { Normal, Number(CSSFloat), @@ -711,21 +710,12 @@ pub mod longhands { use app_units::Au; use std::fmt; use values::CSSFloat; - #[derive(PartialEq, Copy, Clone, HeapSizeOf)] + #[derive(PartialEq, Copy, Clone, HeapSizeOf, Debug)] pub enum T { Normal, Length(Au), Number(CSSFloat), } - impl fmt::Debug for T { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - T::Normal => write!(f, "normal"), - T::Length(length) => write!(f, "{:?}%", length), - T::Number(number) => write!(f, "{}", number), - } - } - } } impl ToCss for computed_value::T { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { @@ -778,7 +768,7 @@ pub mod longhands { <% vertical_align_keywords = ( "baseline sub super top text-top middle bottom text-bottom".split()) %> #[allow(non_camel_case_types)] - #[derive(Clone, PartialEq, Copy)] + #[derive(Debug, Clone, PartialEq, Copy)] pub enum SpecifiedValue { % for keyword in vertical_align_keywords: ${to_rust_ident(keyword)}, @@ -821,23 +811,13 @@ pub mod longhands { use values::AuExtensionMethods; use values::{CSSFloat, computed}; #[allow(non_camel_case_types)] - #[derive(PartialEq, Copy, Clone, HeapSizeOf)] + #[derive(PartialEq, Copy, Clone, HeapSizeOf, Debug)] pub enum T { % for keyword in vertical_align_keywords: ${to_rust_ident(keyword)}, % endfor LengthOrPercentage(computed::LengthOrPercentage), } - impl fmt::Debug for T { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - % for keyword in vertical_align_keywords: - T::${to_rust_ident(keyword)} => write!(f, "${keyword}"), - % endfor - T::LengthOrPercentage(value) => write!(f, "{:?}", value), - } - } - } impl ::cssparser::ToCss for T { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { @@ -918,7 +898,7 @@ pub mod longhands { } pub mod computed_value { - #[derive(Clone, Copy, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, Copy, PartialEq, HeapSizeOf)] pub struct T(pub super::super::overflow_x::computed_value::T); } @@ -971,7 +951,7 @@ pub mod longhands { use cssparser::{self, ToCss}; use std::fmt; - #[derive(PartialEq, Eq, Clone, HeapSizeOf)] + #[derive(Debug, PartialEq, Eq, Clone, HeapSizeOf)] pub enum ContentItem { /// Literal string content. String(String), @@ -1020,7 +1000,7 @@ pub mod longhands { } #[allow(non_camel_case_types)] - #[derive(PartialEq, Eq, Clone, HeapSizeOf)] + #[derive(Debug, PartialEq, Eq, Clone, HeapSizeOf)] pub enum T { normal, none, @@ -1138,8 +1118,9 @@ pub mod longhands { use std::fmt; use url::Url; use values::computed::Context; + use values::LocalToCss; - #[derive(Clone, PartialEq, Eq)] + #[derive(Debug, Clone, PartialEq, Eq)] pub enum SpecifiedValue { None, Url(Url), @@ -1149,9 +1130,7 @@ pub mod longhands { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { SpecifiedValue::None => dest.write_str("none"), - SpecifiedValue::Url(ref url) => { - Token::Url(url.to_string().into()).to_css(dest) - } + SpecifiedValue::Url(ref url) => url.to_css(dest), } } } @@ -1160,15 +1139,16 @@ pub mod longhands { use cssparser::{ToCss, Token}; use std::fmt; use url::Url; + use values::LocalToCss; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<Url>); impl ToCss for T { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self.0 { None => dest.write_str("none"), - Some(ref url) => Token::Url(url.to_string().into()).to_css(dest) + Some(ref url) => url.to_css(dest), } } } @@ -1209,7 +1189,7 @@ pub mod longhands { pub use self::computed_value::T as SpecifiedValue; pub mod computed_value { - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Vec<(String,String)>); } @@ -1278,7 +1258,7 @@ pub mod longhands { pub use self::computed_value::T as SpecifiedValue; pub mod computed_value { - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Vec<(String,i32)>); } @@ -1359,10 +1339,11 @@ pub mod longhands { use std::fmt; use values::computed::Context; use values::specified::Image; + use values::LocalToCss; pub mod computed_value { use values::computed; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<computed::Image>); } @@ -1370,15 +1351,14 @@ pub mod longhands { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self.0 { None => dest.write_str("none"), - Some(computed::Image::Url(ref url)) => - ::cssparser::Token::Url(url.to_string().into()).to_css(dest), + Some(computed::Image::Url(ref url)) => url.to_css(dest), Some(computed::Image::LinearGradient(ref gradient)) => gradient.to_css(dest) } } } - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(pub Option<Image>); impl ToCss for SpecifiedValue { @@ -1431,7 +1411,7 @@ pub mod longhands { } } - #[derive(Clone, PartialEq, Copy)] + #[derive(Debug, Clone, PartialEq, Copy)] pub struct SpecifiedValue { pub horizontal: specified::LengthOrPercentage, pub vertical: specified::LengthOrPercentage, @@ -1727,7 +1707,7 @@ pub mod longhands { use std::fmt; use string_cache::Atom; - #[derive(PartialEq, Eq, Clone, Hash, HeapSizeOf)] + #[derive(Debug, PartialEq, Eq, Clone, Hash, HeapSizeOf)] pub enum FontFamily { FamilyName(Atom), // Generic @@ -1763,7 +1743,7 @@ pub mod longhands { Ok(()) } } - #[derive(Clone, PartialEq, Eq, Hash, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, Eq, Hash, HeapSizeOf)] pub struct T(pub Vec<FontFamily>); } @@ -1808,7 +1788,7 @@ pub mod longhands { use std::fmt; use values::computed::Context; - #[derive(Clone, PartialEq, Eq, Copy)] + #[derive(Debug, Clone, PartialEq, Eq, Copy)] pub enum SpecifiedValue { Bolder, Lighter, @@ -1855,21 +1835,12 @@ pub mod longhands { } pub mod computed_value { use std::fmt; - #[derive(PartialEq, Eq, Copy, Clone, Hash, Deserialize, Serialize, HeapSizeOf)] + #[derive(PartialEq, Eq, Copy, Clone, Hash, Deserialize, Serialize, HeapSizeOf, Debug)] pub enum T { % for weight in range(100, 901, 100): Weight${weight} = ${weight}, % endfor } - impl fmt::Debug for T { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - % for weight in range(100, 901, 100): - T::Weight${weight} => write!(f, "{}", ${weight}), - % endfor - } - } - } impl T { #[inline] pub fn is_bold(self) -> bool { @@ -1944,7 +1915,7 @@ pub mod longhands { } } - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(pub specified::LengthOrPercentage); pub mod computed_value { use app_units::Au; @@ -2044,7 +2015,7 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq)] pub enum SpecifiedValue { Normal, Specified(specified::Length), @@ -2061,7 +2032,7 @@ pub mod longhands { pub mod computed_value { use app_units::Au; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<Au>); } @@ -2107,7 +2078,7 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq)] pub enum SpecifiedValue { Normal, Specified(specified::Length), // FIXME(SimonSapin) support percentages @@ -2124,7 +2095,7 @@ pub mod longhands { pub mod computed_value { use app_units::Au; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<Au>); } @@ -2549,7 +2520,7 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq)] pub enum SpecifiedValue { Auto, Specified(specified::Length), @@ -2566,7 +2537,7 @@ pub mod longhands { pub mod computed_value { use app_units::Au; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<Au>); } @@ -2611,7 +2582,7 @@ pub mod longhands { use std::fmt; use values::computed::Context; - #[derive(Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq)] pub enum SpecifiedValue { Auto, Specified(u32), @@ -2627,7 +2598,7 @@ pub mod longhands { } pub mod computed_value { - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<u32>); } @@ -2678,7 +2649,7 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq)] pub enum SpecifiedValue { Normal, Specified(specified::Length), @@ -2695,7 +2666,7 @@ pub mod longhands { pub mod computed_value { use app_units::Au; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<Au>); } @@ -2750,7 +2721,7 @@ pub mod longhands { } } - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(pub CSSFloat); pub mod computed_value { use values::CSSFloat; @@ -2786,10 +2757,10 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(Vec<SpecifiedBoxShadow>); - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedBoxShadow { pub offset_x: specified::Length, pub offset_y: specified::Length, @@ -2842,10 +2813,10 @@ pub mod longhands { use std::fmt; use values::computed; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Clone, PartialEq, HeapSizeOf, Debug)] pub struct T(pub Vec<BoxShadow>); - #[derive(Clone, PartialEq, Copy, HeapSizeOf)] + #[derive(Clone, PartialEq, Copy, HeapSizeOf, Debug)] pub struct BoxShadow { pub offset_x: Au, pub offset_y: Au, @@ -2854,17 +2825,6 @@ pub mod longhands { pub color: computed::CSSColor, pub inset: bool, } - - impl fmt::Debug for BoxShadow { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.inset { - let _ = write!(f, "inset "); - } - let _ = write!(f, "{:?} {:?} {:?} {:?} {:?}", self.offset_x, self.offset_y, - self.blur_radius, self.spread_radius, self.color); - Ok(()) - } - } } impl ToCss for computed_value::T { @@ -3020,7 +2980,7 @@ pub mod longhands { pub left: Au, } - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Option<ClipRect>); } @@ -3161,10 +3121,10 @@ pub mod longhands { use values::AuExtensionMethods; use values::computed::Context; - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct SpecifiedValue(Vec<SpecifiedTextShadow>); - #[derive(Clone, PartialEq)] + #[derive(Clone, PartialEq, Debug)] pub struct SpecifiedTextShadow { pub offset_x: specified::Length, pub offset_y: specified::Length, @@ -3172,20 +3132,6 @@ pub mod longhands { pub color: Option<specified::CSSColor>, } - impl fmt::Debug for SpecifiedTextShadow { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let _ = write!(f, - "{:?} {:?} {:?}", - self.offset_x, - self.offset_y, - self.blur_radius); - if let Some(ref color) = self.color { - let _ = write!(f, "{:?}", color); - } - Ok(()) - } - } - pub mod computed_value { use app_units::Au; use cssparser::Color; @@ -3356,7 +3302,7 @@ pub mod longhands { use values::CSSFloat; use values::specified::{Angle, Length}; - #[derive(Clone, PartialEq)] + #[derive(Debug, Clone, PartialEq)] pub struct SpecifiedValue(Vec<SpecifiedFilter>); // TODO(pcwalton): `drop-shadow` @@ -4354,7 +4300,7 @@ pub mod longhands { pub use values::computed::Time as SingleComputedValue; - #[derive(Clone, PartialEq, HeapSizeOf)] + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Vec<SingleComputedValue>); impl ToComputedValue for T { @@ -4900,7 +4846,10 @@ pub mod shorthands { -> Result<(), ()> { input.look_for_var_functions(); let start = input.position(); - let value = parse_value(context, input); + let value = input.parse_entirely(|input| parse_value(context, input)); + if value.is_err() { + while let Ok(_) = input.next() {} // Look for var() after the error. + } let var = input.seen_var_functions(); if let Ok(value) = value { % for sub_property in shorthand.sub_properties: @@ -4914,16 +4863,15 @@ pub mod shorthands { Ok(()) } else if var { input.reset(start); - let (first_token_type, _) = try!( - ::custom_properties::parse_declaration_value(input, &mut None)); - let css = input.slice_from(start); + let (first_token_type, css) = try!( + ::custom_properties::parse_non_custom_with_var(input)); % for sub_property in shorthand.sub_properties: declarations.push(PropertyDeclaration::${sub_property.camel_case}( DeclaredValue::WithVariables { - css: css.to_owned(), + css: css.clone().into_owned(), first_token_type: first_token_type, base_url: context.base_url.clone(), - from_shorthand: Shorthand::${shorthand.camel_case}, + from_shorthand: Some(Shorthand::${shorthand.camel_case}), } )); % endfor @@ -5645,12 +5593,12 @@ mod property_bit_field { ::stylesheets::Origin::Author, base_url); Parser::new(&css).parse_entirely(|input| { match from_shorthand { - Shorthand::None => { + None => { longhands::${property.ident}::parse_specified(&context, input) } % for shorthand in SHORTHANDS: % if property in shorthand.sub_properties: - Shorthand::${shorthand.camel_case} => { + Some(Shorthand::${shorthand.camel_case}) => { shorthands::${shorthand.ident}::parse_value(&context, input) .map(|result| match result.${property.ident} { Some(value) => DeclaredValue::Value(value), @@ -5718,10 +5666,12 @@ impl<'a, 'b> DeclarationParser for PropertyDeclarationParser<'a, 'b> { fn parse_value(&self, name: &str, input: &mut Parser) -> Result<(Vec<PropertyDeclaration>, bool), ()> { let mut results = vec![]; - match PropertyDeclaration::parse(name, self.context, input, &mut results) { - PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => {} - _ => return Err(()) - } + try!(input.parse_until_before(Delimiter::Bang, |input| { + match PropertyDeclaration::parse(name, self.context, input, &mut results) { + PropertyDeclarationParseResult::ValidOrIgnoredDeclaration => Ok(()), + _ => Err(()) + } + })); let important = input.try(parse_important).is_ok(); Ok((results, important)) } @@ -5814,12 +5764,39 @@ impl CSSWideKeyword { #[derive(Clone, Copy, Eq, PartialEq, Debug)] pub enum Shorthand { - None, % for property in SHORTHANDS: ${property.camel_case}, % endfor } +impl Shorthand { + pub fn from_name(name: &str) -> Option<Shorthand> { + match_ignore_ascii_case! { name, + % for property in SHORTHANDS[:-1]: + "${property.name}" => Some(Shorthand::${property.camel_case}), + % endfor + % for property in SHORTHANDS[-1:]: + "${property.name}" => Some(Shorthand::${property.camel_case}) + % endfor + _ => None + } + } + + pub fn longhands(&self) -> &'static [&'static str] { + % for property in SHORTHANDS: + static ${property.ident.upper()}: &'static [&'static str] = &[ + % for sub in property.sub_properties: + "${sub.name}", + % endfor + ]; + % endfor + match *self { + % for property in SHORTHANDS: + Shorthand::${property.camel_case} => ${property.ident.upper()}, + % endfor + } + } +} #[derive(Clone, PartialEq, Eq, Debug)] pub enum DeclaredValue<T> { @@ -5828,7 +5805,7 @@ pub enum DeclaredValue<T> { css: String, first_token_type: TokenSerializationType, base_url: Url, - from_shorthand: Shorthand + from_shorthand: Option<Shorthand>, }, Initial, Inherit, @@ -5841,7 +5818,7 @@ impl<T: ToCss> ToCss for DeclaredValue<T> { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { DeclaredValue::Value(ref inner) => inner.to_css(dest), - DeclaredValue::WithVariables { ref css, from_shorthand: Shorthand::None, .. } => { + DeclaredValue::WithVariables { ref css, from_shorthand: None, .. } => { dest.write_str(css) } // https://drafts.csswg.org/css-variables/#variables-in-shorthands @@ -5852,7 +5829,7 @@ impl<T: ToCss> ToCss for DeclaredValue<T> { } } -#[derive(PartialEq, Clone)] +#[derive(PartialEq, Clone, Debug)] pub enum PropertyDeclaration { % for property in LONGHANDS: ${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>), @@ -5931,6 +5908,41 @@ impl PropertyDeclaration { } } + /// If this is a pending-substitution value from the given shorthand, return that value + // Extra space here because < seems to be removed by Mako when immediately followed by &. + // ↓ + pub fn with_variables_from_shorthand(&self, shorthand: Shorthand) -> Option< &str> { + match *self { + % for property in LONGHANDS: + PropertyDeclaration::${property.camel_case}(ref value) => match *value { + DeclaredValue::WithVariables { ref css, from_shorthand: Some(s), .. } + if s == shorthand => { + Some(&**css) + } + _ => None + }, + % endfor + PropertyDeclaration::Custom(..) => None, + } + } + + /// Return whether this is a pending-substitution value. + /// https://drafts.csswg.org/css-variables/#variables-in-shorthands + pub fn with_variables(&self) -> bool { + match *self { + % for property in LONGHANDS: + PropertyDeclaration::${property.camel_case}(ref value) => match *value { + DeclaredValue::WithVariables { .. } => true, + _ => false, + }, + % endfor + PropertyDeclaration::Custom(_, ref value) => match *value { + DeclaredValue::WithVariables { .. } => true, + _ => false, + } + } + } + pub fn matches(&self, name: &str) -> bool { match *self { % for property in LONGHANDS: @@ -6033,13 +6045,6 @@ impl PropertyDeclaration { } } -impl Debug for PropertyDeclaration { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}: {}", self.name(), self.value()) - } -} - - pub mod style_structs { use super::longhands; @@ -6913,27 +6918,6 @@ macro_rules! longhand_properties_idents { } } -// Extra space here because < seems to be removed by Mako when immediately followed by &. -// ↓ -pub fn longhands_from_shorthand(shorthand: &str) -> Option< &'static [&'static str]> { - % for property in SHORTHANDS: - static ${property.ident.upper()}: &'static [&'static str] = &[ - % for sub in property.sub_properties: - "${sub.name}", - % endfor - ]; - % endfor - match_ignore_ascii_case!{ shorthand, - % for property in SHORTHANDS[:-1]: - "${property.name}" => Some(${property.ident.upper()}), - % endfor - % for property in SHORTHANDS[-1:]: - "${property.name}" => Some(${property.ident.upper()}) - % endfor - _ => None - } -} - /// Corresponds to the fields in `gfx::font_template::FontTemplateDescriptor`. fn compute_font_hash(font: &mut style_structs::Font) { let mut hasher: FnvHasher = Default::default(); diff --git a/components/style/values.rs b/components/style/values.rs index a32b668fa9c..b6f630142b9 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -5,7 +5,10 @@ pub use cssparser::RGBA; use app_units::Au; -use std::fmt; +use cssparser::CssStringWriter; +use std::fmt::{self, Write}; +use url::Url; + // This is a re-implementation of the ToCss trait in cssparser. // It's done here because the app_units crate shouldn't depend @@ -64,6 +67,22 @@ macro_rules! define_numbered_css_keyword_enum { } } +/// The real ToCss trait can’t be implemented for Url +/// since neither rust-url or rust-cssparser depend on the other. +pub trait LocalToCss { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write; +} + +impl LocalToCss for Url { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + try!(dest.write_str("url(\"")); + try!(write!(CssStringWriter::new(dest), "{}", self)); + try!(dest.write_str("\")")); + Ok(()) + } +} + + pub type CSSFloat = f32; pub const FONT_MEDIUM_PX: i32 = 16; @@ -1177,20 +1196,16 @@ pub mod specified { impl Image { pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> { - match try!(input.next()) { - Token::Url(url) => { - Ok(Image::Url(context.parse_url(&url))) - } - Token::Function(name) => { - match_ignore_ascii_case! { name, - "linear-gradient" => { - Ok(Image::LinearGradient(try!( - input.parse_nested_block(LinearGradient::parse_function)))) - } - _ => Err(()) + if let Ok(url) = input.try(|input| input.expect_url()) { + Ok(Image::Url(context.parse_url(&url))) + } else { + match_ignore_ascii_case! { try!(input.expect_function()), + "linear-gradient" => { + Ok(Image::LinearGradient(try!( + input.parse_nested_block(LinearGradient::parse_function)))) } + _ => Err(()) } - _ => Err(()) } } } diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index 414bdf87ce2..7db0ab0298a 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -10,26 +10,20 @@ path = "lib.rs" [dependencies.util] path = "../util" -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies.plugins] path = "../plugins" -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" -features = ["unstable"] - [dependencies.url] version = "0.2" features = [ "serde_serialization" ] [dependencies] +cssparser = { version = "0.4", features = [ "serde-serialization" ] } euclid = {version = "0.3", features = ["plugins"]} log = "0.3" lazy_static = "0.1.10" num = "0.1.24" rustc-serialize = "0.3" +selectors = "0.2" serde = "0.6" serde_macros = "0.6" diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 7eac36662d3..480324f0578 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -29,10 +29,6 @@ git = "https://github.com/servo/rust-mozjs" git = "https://github.com/servo/rust-layers" features = ["plugins"] -[dependencies.cssparser] -version = "0.3" -features = [ "serde-serialization" ] - [dependencies.ipc-channel] git = "https://github.com/pcwalton/ipc-channel" @@ -40,11 +36,9 @@ git = "https://github.com/pcwalton/ipc-channel" version = "0.2" features = [ "serde_serialization" ] -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" - [dependencies] app_units = {version = "0.1", features = ["plugins"]} +cssparser = { version = "0.4", features = [ "serde-serialization" ] } log = "0.3" bitflags = "0.3" html5ever = { version = "0.2.1", features = ["unstable"] } @@ -55,6 +49,7 @@ smallvec = "0.1" num_cpus = "0.2.2" num = "0.1.24" euclid = {version = "0.3", features = ["plugins"]} +selectors = "0.2" serde = "0.6" serde_macros = "0.6" string_cache = "0.1" diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 3e4e193401b..ad3367f50d7 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -144,7 +144,7 @@ version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -162,7 +162,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", @@ -314,7 +314,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.9" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -947,7 +947,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -964,7 +964,7 @@ dependencies = [ "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1435,7 +1435,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1456,7 +1456,7 @@ dependencies = [ "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1494,11 +1494,11 @@ dependencies = [ [[package]] name = "selectors" -version = "0.2.0" -source = "git+https://github.com/servo/rust-selectors#53f5e09a37684f6a42eb894d7a6fd0b14380a1c6" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1676,7 +1676,7 @@ version = "0.0.1" dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1686,7 +1686,7 @@ dependencies = [ "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1701,14 +1701,14 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1837,7 +1837,7 @@ dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1853,7 +1853,7 @@ dependencies = [ "plugins 0.0.1", "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index b0093519403..87437ef7d79 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -136,7 +136,7 @@ version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -154,7 +154,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.2.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", @@ -306,7 +306,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.9" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -927,7 +927,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -944,7 +944,7 @@ dependencies = [ "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1415,7 +1415,7 @@ dependencies = [ "canvas 0.0.1", "canvas_traits 0.0.1", "caseless 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1436,7 +1436,7 @@ dependencies = [ "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script_traits 0.0.1", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1474,11 +1474,11 @@ dependencies = [ [[package]] name = "selectors" -version = "0.2.0" -source = "git+https://github.com/servo/rust-selectors#53f5e09a37684f6a42eb894d7a6fd0b14380a1c6" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1654,7 +1654,7 @@ version = "0.0.1" dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1664,7 +1664,7 @@ dependencies = [ "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1679,14 +1679,14 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1815,7 +1815,7 @@ dependencies = [ "app_units 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "azure 0.2.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1831,7 +1831,7 @@ dependencies = [ "plugins 0.0.1", "rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", - "selectors 0.2.0 (git+https://github.com/servo/rust-selectors)", + "selectors 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index b8f0cb51476..30140cecbd7 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -17,13 +17,11 @@ path = "../../../components/style_traits" [dependencies.util] path = "../../../components/util" -[dependencies.selectors] -git = "https://github.com/servo/rust-selectors" - [dependencies] app_units = {version = "0.1", features = ["plugins"]} url = "0.2" -cssparser = "0.3.1" +cssparser = "0.4" +selectors = "0.2" string_cache = "0.1" string_cache_plugin = "0.1" euclid = {version = "0.3", features = ["plugins"]} diff --git a/tests/wpt/mozilla/meta/css/test_variable_serialization_computed.html.ini b/tests/wpt/mozilla/meta/css/test_variable_serialization_computed.html.ini deleted file mode 100644 index 5c5d1ba2ebf..00000000000 --- a/tests/wpt/mozilla/meta/css/test_variable_serialization_computed.html.ini +++ /dev/null @@ -1,53 +0,0 @@ -[test_variable_serialization_computed.html] - type: testharness - [subtest #20 with `--a: var(--b)var(--c); --b:orange; --c:red;`] - expected: FAIL - - [subtest #21 with `--a: var(--b)var(--c,red); --b:orange;`] - expected: FAIL - - [subtest #22 with `--a: var(--b,orange)var(--c); --c:red;`] - expected: FAIL - - [subtest #24 with `--a: var(--b)var(--c); --c:[c\]; --b:('ab`] - expected: FAIL - - [subtest #25 with `--a: '`] - expected: FAIL - - [subtest #26 with `--a: '\\`] - expected: FAIL - - [subtest #27 with `--a: \\`] - expected: FAIL - - [subtest #28 with `--a: "`] - expected: FAIL - - [subtest #29 with `--a: "\\`] - expected: FAIL - - [subtest #30 with `--a: /* abc `] - expected: FAIL - - [subtest #31 with `--a: /* abc *`] - expected: FAIL - - [subtest #32 with `--a: url(http://example.org/`] - expected: FAIL - - [subtest #33 with `--a: url(http://example.org/\\`] - expected: FAIL - - [subtest #34 with `--a: url('http://example.org/`] - expected: FAIL - - [subtest #35 with `--a: url('http://example.org/\\`] - expected: FAIL - - [subtest #36 with `--a: url("http://example.org/`] - expected: FAIL - - [subtest #37 with `--a: url("http://example.org/\\`] - expected: FAIL - diff --git a/tests/wpt/mozilla/meta/css/test_variable_serialization_specified.html.ini b/tests/wpt/mozilla/meta/css/test_variable_serialization_specified.html.ini deleted file mode 100644 index b4b7a38b3f5..00000000000 --- a/tests/wpt/mozilla/meta/css/test_variable_serialization_specified.html.ini +++ /dev/null @@ -1,116 +0,0 @@ -[test_variable_serialization_specified.html] - type: testharness - [`var(--a)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a) ` is unchanged by specified value serialization] - expected: FAIL - - [`var( --a ) ` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a, )` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a,/**/a)` is unchanged by specified value serialization] - expected: FAIL - - [`1px var(--a)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a) 1px` is unchanged by specified value serialization] - expected: FAIL - - [`something 3px url(whereever) calc(var(--a) + 1px)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a)var(--b)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a, var(--b, var(--c, black)))` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a) <!--` is unchanged by specified value serialization] - expected: FAIL - - [`--> var(--a)` is unchanged by specified value serialization] - expected: FAIL - - [`{ [ var(--a) \] }` is unchanged by specified value serialization] - expected: FAIL - - [`[;\] var(--a)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a,(;))` is unchanged by specified value serialization] - expected: FAIL - - [`VAR(--a)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--0)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--\\30)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--\\d800)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--\\ffffff)` is unchanged by specified value serialization] - expected: FAIL - - [`var(--a` becomes `var(--a)` in specified value serialization] - expected: FAIL - - [`var(--a , ` becomes `var(--a , )` in specified value serialization] - expected: FAIL - - [`var(--a, ` becomes `var(--a, )` in specified value serialization] - expected: FAIL - - [`var(--a, var(--b` becomes `var(--a, var(--b))` in specified value serialization] - expected: FAIL - - [`var(--a /* unclosed comment` becomes `var(--a /* unclosed comment*/)` in specified value serialization] - expected: FAIL - - [`var(--a /* unclosed comment *` becomes `var(--a /* unclosed comment */)` in specified value serialization] - expected: FAIL - - [`[{(((var(--a` becomes `[{(((var(--a))))}\]` in specified value serialization] - expected: FAIL - - [`var(--a, "unclosed string` becomes `var(--a, "unclosed string")` in specified value serialization] - expected: FAIL - - [`var(--a, 'unclosed string` becomes `var(--a, 'unclosed string')` in specified value serialization] - expected: FAIL - - [`var(--a) "unclosed string\\` becomes `var(--a) "unclosed string"` in specified value serialization] - expected: FAIL - - [`var(--a) 'unclosed string\\` becomes `var(--a) 'unclosed string'` in specified value serialization] - expected: FAIL - - [`var(--a) \\` becomes `var(--a) \\�` in specified value serialization] - expected: FAIL - - [`var(--a) url(unclosedurl` becomes `var(--a) url(unclosedurl)` in specified value serialization] - expected: FAIL - - [`var(--a) url('unclosedurl` becomes `var(--a) url('unclosedurl')` in specified value serialization] - expected: FAIL - - [`var(--a) url("unclosedurl` becomes `var(--a) url("unclosedurl")` in specified value serialization] - expected: FAIL - - [`var(--a) url(unclosedurl\\` becomes `var(--a) url(unclosedurl\\�)` in specified value serialization] - expected: FAIL - - [`var(--a) url('unclosedurl\\` becomes `var(--a) url('unclosedurl')` in specified value serialization] - expected: FAIL - - [`var(--a) url("unclosedurl\\` becomes `var(--a) url("unclosedurl")` in specified value serialization] - expected: FAIL - diff --git a/tests/wpt/mozilla/tests/css/test_variable_serialization_specified.html b/tests/wpt/mozilla/tests/css/test_variable_serialization_specified.html index cbb9e01e3fb..ce6219707c4 100644 --- a/tests/wpt/mozilla/tests/css/test_variable_serialization_specified.html +++ b/tests/wpt/mozilla/tests/css/test_variable_serialization_specified.html @@ -104,11 +104,6 @@ function test_specified_value_serialization(value, expected) { div1.style.removeProperty("margin"); } -/* -function test(f) { f() } -function assert_equals(a, b, m) { if (a == b) { console.log("`"+a+"`", "`"+b+"`", m) } } -*/ - values_with_unchanged_specified_value_serialization.forEach(function(value) { test(function() { test_specified_value_serialization(value, value) }, "`" + value + "` is unchanged by specified value serialization"); |