From 4abe7cdf977c2497aa691a64b5d2aa9a7d1175d3 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 3 Sep 2015 18:10:45 +0200 Subject: [PATCH 01/10] Support var() in shorthands. --- components/style/lib.rs | 1 + components/style/properties.mako.rs | 155 +++++++++++++----- .../html/variable-reference-36.htm.ini | 3 - .../html/variable-reference-38.htm.ini | 3 - 4 files changed, 111 insertions(+), 51 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-36.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-38.htm.ini diff --git a/components/style/lib.rs b/components/style/lib.rs index 60e137a1ab0..425a5eafb06 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -5,6 +5,7 @@ #![feature(arc_unique)] #![feature(box_syntax)] #![feature(box_patterns)] +#![feature(concat_idents)] #![feature(core_intrinsics)] #![feature(custom_attribute)] #![feature(custom_derive)] diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 79e1a5e7182..7bb31d0fc5b 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -115,6 +115,7 @@ pub mod longhands { derived_from=derived_from, custom_cascade=custom_cascade, experimental=experimental) + property.style_struct = THIS_STYLE_STRUCT THIS_STYLE_STRUCT.longhands.append(property) LONGHANDS.append(property) LONGHANDS_BY_NAME[name] = property @@ -128,7 +129,7 @@ pub mod longhands { % if derived_from is None: use cssparser::Parser; use parser::ParserContext; - use properties::{CSSWideKeyword, DeclaredValue}; + use properties::{CSSWideKeyword, DeclaredValue, Shorthand}; % endif use properties::longhands; use properties::property_bit_field::PropertyBitField; @@ -157,7 +158,7 @@ pub mod longhands { return } seen.set_${property.ident}(); - let computed_value = substitute_variables( + let computed_value = ::properties::substitute_variables_${property.ident}( declared_value, &style.custom_properties, |value| match *value { DeclaredValue::Value(ref specified_value) => { specified_value.to_computed_value(&context) @@ -193,29 +194,6 @@ pub mod longhands { % endif } % if derived_from is None: - pub fn substitute_variables(value: &DeclaredValue, - custom_properties: &Option>>, - f: F) - -> R - where F: FnOnce(&DeclaredValue) -> R { - if let DeclaredValue::WithVariables { ref css, ref base_url } = *value { - f(& - ::custom_properties::substitute(css, custom_properties) - .and_then(|css| { - // As of this writing, only the base URL is used for property values: - let context = ParserContext::new( - ::stylesheets::Origin::Author, base_url); - parse_specified(&context, &mut Parser::new(&css)) - }) - .unwrap_or( - // Invalid at computed-value time. - DeclaredValue::${"Inherit" if THIS_STYLE_STRUCT.inherited else "Initial"} - ) - ) - } else { - f(value) - } - } pub fn parse_declared(context: &ParserContext, input: &mut Parser) -> Result, ()> { match input.try(CSSWideKeyword::parse) { @@ -234,6 +212,7 @@ pub mod longhands { return Ok(DeclaredValue::WithVariables { css: input.slice_from(start).to_owned(), base_url: context.base_url.clone(), + from_shorthand: Shorthand::None, }) } specified @@ -4881,7 +4860,7 @@ pub mod shorthands { pub mod ${shorthand.ident} { use cssparser::Parser; use parser::ParserContext; - use properties::longhands; + use properties::{longhands, PropertyDeclaration, DeclaredValue, Shorthand}; pub struct Longhands { % for sub_property in shorthand.sub_properties: @@ -4890,8 +4869,44 @@ pub mod shorthands { % endfor } + pub fn parse(context: &ParserContext, input: &mut Parser, + declarations: &mut Vec) + -> Result<(), ()> { + input.look_for_var_functions(); + let start = input.position(); + let value = parse_value(context, input); + let var = input.seen_var_functions(); + if let Ok(value) = value { + % for sub_property in shorthand.sub_properties: + declarations.push(PropertyDeclaration::${sub_property.camel_case}( + match value.${sub_property.ident} { + Some(value) => DeclaredValue::Value(value), + None => DeclaredValue::Initial, + } + )); + % endfor + Ok(()) + } else if var { + input.reset(start); + try!(::custom_properties::parse_declaration_value(input, &mut None)); + let css = input.slice_from(start); + % for sub_property in shorthand.sub_properties: + declarations.push(PropertyDeclaration::${sub_property.camel_case}( + DeclaredValue::WithVariables { + css: css.to_owned(), + base_url: context.base_url.clone(), + from_shorthand: Shorthand::${shorthand.camel_case}, + } + )); + % endfor + Ok(()) + } else { + Err(()) + } + } + #[allow(unused_variables)] - pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { + pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result { ${caller.body()} } } @@ -5582,6 +5597,54 @@ mod property_bit_field { } } +% for property in LONGHANDS: + % if property.derived_from is None: + fn substitute_variables_${property.ident}( + value: &DeclaredValue, + custom_properties: &Option>>, + f: F) + -> R + where F: FnOnce(&DeclaredValue) -> R + { + if let DeclaredValue::WithVariables { + ref css, ref base_url, from_shorthand + } = *value { + f(& + ::custom_properties::substitute(css, custom_properties) + .and_then(|css| { + // As of this writing, only the base URL is used for property values: + let context = ParserContext::new( + ::stylesheets::Origin::Author, base_url); + let mut input = Parser::new(&css); + match from_shorthand { + Shorthand::None => { + longhands::${property.ident}::parse_specified(&context, &mut input) + } + % for shorthand in SHORTHANDS: + % if property in shorthand.sub_properties: + Shorthand::${shorthand.camel_case} => { + shorthands::${shorthand.ident}::parse_value(&context, &mut input) + .map(|result| match result.${property.ident} { + Some(value) => DeclaredValue::Value(value), + None => DeclaredValue::Initial, + }) + } + % endif + % endfor + _ => unreachable!() + } + }) + .unwrap_or( + // Invalid at computed-value time. + DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"} + ) + ) + } else { + f(value) + } + } + % endif +% endfor /// Declarations are stored in reverse order. /// Overridden declarations are skipped. @@ -5720,11 +5783,19 @@ impl CSSWideKeyword { } } +#[derive(Clone, Copy, Eq, PartialEq, Debug)] +pub enum Shorthand { + None, + % for property in SHORTHANDS: + ${property.camel_case}, + % endfor +} + #[derive(Clone, PartialEq, Eq, Debug)] pub enum DeclaredValue { Value(T), - WithVariables { css: String, base_url: Url }, + WithVariables { css: String, base_url: Url, from_shorthand: Shorthand }, Initial, Inherit, // There is no Unset variant here. @@ -5736,7 +5807,11 @@ impl DeclaredValue { pub fn specified_value(&self) -> String { match *self { DeclaredValue::Value(ref inner) => inner.to_css_string(), - DeclaredValue::WithVariables { ref css, .. } => css.clone(), + DeclaredValue::WithVariables { ref css, from_shorthand: Shorthand::None, .. } => { + css.clone() + } + // https://drafts.csswg.org/css-variables/#variables-in-shorthands + DeclaredValue::WithVariables { .. } => String::new(), DeclaredValue::Initial => "initial".to_owned(), DeclaredValue::Inherit => "inherit".to_owned(), } @@ -5865,18 +5940,8 @@ impl PropertyDeclaration { % endfor PropertyDeclarationParseResult::ValidOrIgnoredDeclaration }, - Err(()) => match shorthands::${shorthand.ident}::parse(context, input) { - Ok(result) => { - % for sub_property in shorthand.sub_properties: - result_list.push(PropertyDeclaration::${sub_property.camel_case}( - match result.${sub_property.ident} { - Some(value) => DeclaredValue::Value(value), - None => DeclaredValue::Initial, - } - )); - % endfor - PropertyDeclarationParseResult::ValidOrIgnoredDeclaration - }, + Err(()) => match shorthands::${shorthand.ident}::parse(context, input, result_list) { + Ok(()) => PropertyDeclarationParseResult::ValidOrIgnoredDeclaration, Err(()) => PropertyDeclarationParseResult::InvalidValue, } } @@ -6182,7 +6247,7 @@ fn cascade_with_cached_declarations( } seen.set_${property.ident}(); let computed_value = - longhands::${property.ident}::substitute_variables( + substitute_variables_${property.ident}( declared_value, &custom_properties, |value| match *value { DeclaredValue::Value(ref specified_value) => specified_value.to_computed_value(context), @@ -6354,7 +6419,7 @@ pub fn cascade(viewport_size: Size2D, // This assumes that the computed and specified values have the same Rust type. macro_rules! get_specified( ($style_struct_getter: ident, $property: ident, $declared_value: expr) => { - longhands::$property::substitute_variables( + concat_idents!(substitute_variables_, $property)( $declared_value, &custom_properties, |value| match *value { DeclaredValue::Value(specified_value) => specified_value, DeclaredValue::Initial => longhands::$property::get_initial_value(), @@ -6374,7 +6439,7 @@ pub fn cascade(viewport_size: Size2D, for declaration in sub_list.declarations.iter().rev() { match *declaration { PropertyDeclaration::FontSize(ref value) => { - context.font_size = longhands::font_size::substitute_variables( + context.font_size = substitute_variables_font_size( value, &custom_properties, |value| match *value { DeclaredValue::Value(ref specified_value) => { match specified_value.0 { @@ -6395,7 +6460,7 @@ pub fn cascade(viewport_size: Size2D, ); } PropertyDeclaration::Color(ref value) => { - context.color = longhands::color::substitute_variables( + context.color = substitute_variables_color( value, &custom_properties, |value| match *value { DeclaredValue::Value(ref specified_value) => { specified_value.parsed diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-36.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-36.htm.ini deleted file mode 100644 index d052a96d261..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-36.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-36.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-38.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-38.htm.ini deleted file mode 100644 index ae8c7dd94be..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-38.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-38.htm] - type: reftest - expected: FAIL From c7622bf22fa5d9623a5818d6f63c6e6369b23b60 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Sep 2015 16:07:56 +0200 Subject: [PATCH 02/10] Fix !important in custom properties. Test changes are also in https://github.com/w3c/csswg-test/pull/847/files --- components/servo/Cargo.lock | 20 ++++---- components/style/Cargo.toml | 2 +- components/style/custom_properties.rs | 49 ++++--------------- ports/cef/Cargo.lock | 18 +++---- ports/gonk/Cargo.lock | 18 +++---- ...s-vars-custom-property-inheritance.htm.ini | 3 -- .../html/variable-declaration-20.htm.ini | 3 -- .../html/variable-reference-13.htm.ini | 3 -- .../html/variable-reference-14.htm.ini | 3 -- 9 files changed, 38 insertions(+), 81 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/css-vars-custom-property-inheritance.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-20.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-13.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-14.htm.ini diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 64b32314511..7121519301f 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -137,7 +137,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -154,7 +154,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (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)", @@ -290,7 +290,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -929,7 +929,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.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1414,7 +1414,7 @@ dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "canvas 0.0.1", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1480,7 +1480,7 @@ version = "0.1.0" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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)", @@ -1622,7 +1622,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1647,7 +1647,7 @@ dependencies = [ name = "style_tests" version = "0.0.1" dependencies = [ - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", "string_cache 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1662,7 +1662,7 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1784,7 +1784,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index c67bf713616..ce0553f95f9 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -23,7 +23,7 @@ git = "https://github.com/servo/rust-selectors" features = ["unstable"] [dependencies.cssparser] -version = "0.3.6" +version = "0.3.8" features = [ "serde-serialization" ] [dependencies.url] diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 7a8ce7c2c67..057b7c27ce4 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -2,7 +2,7 @@ * 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/. */ -use cssparser::{Parser, Token, SourcePosition}; +use cssparser::{Parser, Token, SourcePosition, Delimiter}; use properties::DeclaredValue; use std::collections::{HashMap, HashSet}; use std::sync::Arc; @@ -37,8 +37,6 @@ pub struct BorrowedValue<'a> { pub fn parse(input: &mut Parser) -> Result { let start = input.position(); let mut references = Some(HashSet::new()); - // FIXME: don’t consume a top-level `!` as that would prevent parsing `!important`. - // Maybe using Parser::parse_until_before? try!(parse_declaration_value(input, &mut references)); Ok(Value { value: input.slice_from(start).to_owned(), @@ -49,42 +47,13 @@ pub fn parse(input: &mut Parser) -> Result { /// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value pub fn parse_declaration_value(input: &mut Parser, references: &mut Option>) -> Result<(), ()> { - if input.is_exhausted() { - // Need at least one token - return Err(()) - } - while let Ok(token) = input.next() { - match token { - Token::BadUrl | - Token::BadString | - Token::CloseParenthesis | - Token::CloseSquareBracket | - Token::CloseCurlyBracket | - - Token::Semicolon | - Token::Delim('!') => { - return Err(()) - } - - Token::Function(ref name) if name == "var" => { - try!(input.parse_nested_block(|input| { - parse_var_function(input, references) - })); - } - - Token::Function(_) | - Token::ParenthesisBlock | - Token::CurlyBracketBlock | - Token::SquareBracketBlock => { - try!(input.parse_nested_block(|input| { - parse_declaration_value_block(input, references) - })); - } - - _ => {} + input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { + if input.is_exhausted() { + // Need at least one token + return Err(()) } - } - Ok(()) + parse_declaration_value_block(input, references) + }) } /// Like parse_declaration_value, @@ -312,11 +281,11 @@ fn substitute_block(input: &mut Parser, -> Result<(), ()> where F: FnMut(&Name, &mut String) -> Result<(), ()> { loop { - let input_slice = input.slice_from(*start); + let before_this_token = input.position(); let token = if let Ok(token) = input.next() { token } else { break }; match token { Token::Function(ref name) if name == "var" => { - substituted.push_str(input_slice); + substituted.push_str(input.slice(*start..before_this_token)); try!(input.parse_nested_block(|input| { // parse_var_function() ensures neither .unwrap() will fail. let name = input.expect_ident().unwrap(); diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index c10a232265b..2328d2d2111 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -129,7 +129,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -146,7 +146,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (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)", @@ -282,7 +282,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -880,7 +880,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.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1348,7 +1348,7 @@ dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "canvas 0.0.1", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1406,7 +1406,7 @@ version = "0.1.0" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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)", @@ -1581,7 +1581,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1606,7 +1606,7 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1728,7 +1728,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 2974aa69209..65b3d3a1a4f 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -110,7 +110,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -127,7 +127,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (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)", @@ -252,7 +252,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -764,7 +764,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.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1214,7 +1214,7 @@ dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "canvas 0.0.1", "canvas_traits 0.0.1", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1272,7 +1272,7 @@ version = "0.1.0" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (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)", @@ -1427,7 +1427,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1452,7 +1452,7 @@ dependencies = [ name = "style_traits" version = "0.0.1" dependencies = [ - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1563,7 +1563,7 @@ version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/css-vars-custom-property-inheritance.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/css-vars-custom-property-inheritance.htm.ini deleted file mode 100644 index 87fee1c5ce8..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/css-vars-custom-property-inheritance.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[css-vars-custom-property-inheritance.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-20.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-20.htm.ini deleted file mode 100644 index e3de1be4109..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-20.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-declaration-20.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-13.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-13.htm.ini deleted file mode 100644 index 7f832f8cdac..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-13.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-13.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-14.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-14.htm.ini deleted file mode 100644 index dd849805038..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-14.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-14.htm] - type: reftest - expected: FAIL From ab9e1af20650509382ea21527909ee3086d78031 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Sep 2015 16:48:07 +0200 Subject: [PATCH 03/10] Allow whitespace-only custom property values. --- components/style/custom_properties.rs | 7 +++++-- .../html/variable-declaration-08.htm.ini | 3 --- .../html/variable-declaration-26.htm.ini | 3 --- .../html/variable-declaration-37.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-03.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-04.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-26.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-27.htm.ini | 3 --- 8 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-08.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-26.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-37.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-03.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-04.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-26.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-27.htm.ini diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 057b7c27ce4..eda03ecfe23 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -48,10 +48,13 @@ pub fn parse(input: &mut Parser) -> Result { pub fn parse_declaration_value(input: &mut Parser, references: &mut Option>) -> Result<(), ()> { input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { - if input.is_exhausted() { - // Need at least one token + // Need at least one token + let start_position = input.position(); + if input.next_including_whitespace().is_err() { return Err(()) } + input.reset(start_position); + parse_declaration_value_block(input, references) }) } diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-08.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-08.htm.ini deleted file mode 100644 index 83e66d3a80e..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-08.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-declaration-08.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-26.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-26.htm.ini deleted file mode 100644 index 98c918745b5..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-26.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-declaration-26.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-37.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-37.htm.ini deleted file mode 100644 index 6c8b66e14c0..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-37.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-declaration-37.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-03.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-03.htm.ini deleted file mode 100644 index d845cc12cd8..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-03.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-03.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-04.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-04.htm.ini deleted file mode 100644 index fba032c2710..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-04.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-04.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-26.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-26.htm.ini deleted file mode 100644 index ebd0652279f..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-26.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-26.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-27.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-27.htm.ini deleted file mode 100644 index 8a36f19f2e7..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-27.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-27.htm] - type: reftest - expected: FAIL From 54ef8055ec67b2eb72a76f66bb678f0d619ae6e9 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Sep 2015 17:00:36 +0200 Subject: [PATCH 04/10] The function name var() is case-insensitive. --- components/style/custom_properties.rs | 5 +++-- .../css-variables-1_dev/html/variable-reference-20.htm.ini | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-20.htm.ini diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index eda03ecfe23..c593feb1a6c 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -4,6 +4,7 @@ use cssparser::{Parser, Token, SourcePosition, Delimiter}; use properties::DeclaredValue; +use std::ascii::AsciiExt; use std::collections::{HashMap, HashSet}; use std::sync::Arc; use string_cache::Atom; @@ -73,7 +74,7 @@ fn parse_declaration_value_block(input: &mut Parser, references: &mut Option { + Token::Function(ref name) if name.eq_ignore_ascii_case("var") => { try!(input.parse_nested_block(|input| { parse_var_function(input, references) })); @@ -287,7 +288,7 @@ fn substitute_block(input: &mut Parser, let before_this_token = input.position(); let token = if let Ok(token) = input.next() { token } else { break }; match token { - Token::Function(ref name) if name == "var" => { + Token::Function(ref name) if name.eq_ignore_ascii_case("var") => { substituted.push_str(input.slice(*start..before_this_token)); try!(input.parse_nested_block(|input| { // parse_var_function() ensures neither .unwrap() will fail. diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-20.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-20.htm.ini deleted file mode 100644 index 4ab2b3816af..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-20.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-20.htm] - type: reftest - expected: FAIL From 70ea5f61a2fdecd89f869b7303c5262d2867795d Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Sep 2015 17:28:03 +0200 Subject: [PATCH 05/10] =?UTF-8?q?Don=E2=80=99t=20ignore=20input=20at=20the?= =?UTF-8?q?=20end=20of=20a=20declaration=20with=20var().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/style/properties.mako.rs | 35 ++++++++++--------- .../html/variable-declaration-24.htm.ini | 3 -- 2 files changed, 18 insertions(+), 20 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-24.htm.ini diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 7bb31d0fc5b..a9f9b92156b 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -5615,24 +5615,25 @@ mod property_bit_field { // As of this writing, only the base URL is used for property values: let context = ParserContext::new( ::stylesheets::Origin::Author, base_url); - let mut input = Parser::new(&css); - match from_shorthand { - Shorthand::None => { - longhands::${property.ident}::parse_specified(&context, &mut input) + Parser::new(&css).parse_entirely(|input| { + match from_shorthand { + Shorthand::None => { + longhands::${property.ident}::parse_specified(&context, input) + } + % for shorthand in SHORTHANDS: + % if property in shorthand.sub_properties: + Shorthand::${shorthand.camel_case} => { + shorthands::${shorthand.ident}::parse_value(&context, input) + .map(|result| match result.${property.ident} { + Some(value) => DeclaredValue::Value(value), + None => DeclaredValue::Initial, + }) + } + % endif + % endfor + _ => unreachable!() } - % for shorthand in SHORTHANDS: - % if property in shorthand.sub_properties: - Shorthand::${shorthand.camel_case} => { - shorthands::${shorthand.ident}::parse_value(&context, &mut input) - .map(|result| match result.${property.ident} { - Some(value) => DeclaredValue::Value(value), - None => DeclaredValue::Initial, - }) - } - % endif - % endfor - _ => unreachable!() - } + }) }) .unwrap_or( // Invalid at computed-value time. diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-24.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-24.htm.ini deleted file mode 100644 index ba980233612..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-declaration-24.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-declaration-24.htm] - type: reftest - expected: FAIL From 389d537451ddfe2cb8a7e46eb95f5fe2a6bc94b6 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 7 Sep 2015 17:54:14 +0200 Subject: [PATCH 06/10] Look for var() in a non-custom property declaration after a parse error. --- components/style/properties.mako.rs | 3 +++ .../css-variables-1_dev/html/variable-reference-15.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-18.htm.ini | 3 --- .../css-variables-1_dev/html/variable-reference-19.htm.ini | 3 --- 4 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-15.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-18.htm.ini delete mode 100644 tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-19.htm.ini diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index a9f9b92156b..27250d379d8 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -205,6 +205,9 @@ pub mod longhands { input.look_for_var_functions(); let start = input.position(); let specified = parse_specified(context, input); + if specified.is_err() { + while let Ok(_) = input.next() {} // Look for var() after the error. + } let var = input.seen_var_functions(); if specified.is_err() && var { input.reset(start); diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-15.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-15.htm.ini deleted file mode 100644 index 7dcf1687aab..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-15.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-15.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-18.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-18.htm.ini deleted file mode 100644 index e09c394fc76..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-18.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-18.htm] - type: reftest - expected: FAIL diff --git a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-19.htm.ini b/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-19.htm.ini deleted file mode 100644 index 3847b908e1b..00000000000 --- a/tests/wpt/metadata-css/css-variables-1_dev/html/variable-reference-19.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[variable-reference-19.htm] - type: reftest - expected: FAIL From b8fd51e9403ca941acdc09e55851b377c0359fee Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 8 Sep 2015 16:15:18 +0200 Subject: [PATCH 07/10] Add a copy of a test that uses a style attribute instead of a stylesheet. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `tests/wpt/css-tests/css-variables-1_dev/html/test_variable_legal_values.htm` relies on setting `.data` on a text node inside a `