diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index c0e8618d76f..a8a8c24c644 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -135,7 +135,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -152,7 +152,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -288,7 +288,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -886,7 +886,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1369,7 +1369,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1435,7 +1435,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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)", @@ -1572,7 +1572,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1596,7 +1596,7 @@ dependencies = [ name = "style_tests" version = "0.0.1" dependencies = [ - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.1.0 (git+https://github.com/servo/rust-selectors)", "string_cache 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1714,7 +1714,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 2bac5a5ddb9..12e2a44656e 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -20,7 +20,7 @@ git = "https://github.com/servo/rust-selectors" features = ["unstable"] [dependencies.cssparser] -version = "0.3" +version = "0.3.6" features = [ "serde-serialization" ] [dependencies.url] diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 7c816185ee7..18aeb9dd0ca 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -24,18 +24,19 @@ pub struct BorrowedValue<'a> { pub fn parse(input: &mut Parser) -> Result { let start = input.position(); - let mut references = HashSet::new(); + 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(), - references: references, + references: references.unwrap(), }) } /// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value -fn parse_declaration_value(input: &mut Parser, references: &mut HashSet) -> Result<(), ()> { +pub fn parse_declaration_value(input: &mut Parser, references: &mut Option>) + -> Result<(), ()> { if input.is_exhausted() { // Need at least one token return Err(()) @@ -76,7 +77,7 @@ fn parse_declaration_value(input: &mut Parser, references: &mut HashSet) - /// 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 HashSet) +fn parse_declaration_value_block(input: &mut Parser, references: &mut Option>) -> Result<(), ()> { while let Ok(token) = input.next() { match token { @@ -110,7 +111,7 @@ fn parse_declaration_value_block(input: &mut Parser, references: &mut HashSet(input: &mut Parser<'i, 't>, references: &mut HashSet) +fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, references: &mut Option>) -> Result<(), ()> { // https://drafts.csswg.org/css-variables/#typedef-custom-property-name let name = try!(input.expect_ident()); @@ -122,7 +123,9 @@ fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, references: &mut HashS if input.expect_comma().is_ok() { try!(parse_declaration_value(input, references)); } - references.insert(Atom::from_slice(name)); + if let Some(ref mut refs) = *references { + refs.insert(Atom::from_slice(name)); + } Ok(()) } @@ -153,7 +156,8 @@ pub fn cascade<'a>(custom_properties: &mut Option unreachable!(), DeclaredValue::Initial => { map.remove(&name); } @@ -188,8 +192,8 @@ fn remove_cycles(map: &mut HashMap<&Atom, BorrowedValue>) { stack: &mut Vec<&'a Atom>, visited: &mut HashSet<&'a Atom>, to_remove: &mut HashSet) { - let was_not_already_present = visited.insert(name); - if !was_not_already_present { + let already_visited_before = !visited.insert(name); + if already_visited_before { return } if let Some(value) = map.get(name) { @@ -216,6 +220,7 @@ fn remove_cycles(map: &mut HashMap<&Atom, BorrowedValue>) { } } +/// Replace `var()` functions for all custom properties. fn substitute_all(custom_properties: HashMap<&Atom, BorrowedValue>, inherited: &Option>>) -> HashMap { @@ -230,6 +235,9 @@ fn substitute_all(custom_properties: HashMap<&Atom, BorrowedValue>, substituted_map } +/// Replace `var()` functions for one custom property. +/// Also recursively record results for other custom properties referenced by `var()` functions. +/// Return `Err(())` for invalid at computed time. fn substitute_one(name: &Atom, value: &BorrowedValue, custom_properties: &HashMap<&Atom, BorrowedValue>, @@ -252,10 +260,14 @@ fn substitute_one(name: &Atom, let mut substituted = String::new(); let mut input = Parser::new(&value.value); let mut start = input.position(); - if substitute_block( - custom_properties, inherited, &mut input, &mut start, &mut substituted, - substituted_map, invalid, - ).is_ok() { + if substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| { + if let Some(value) = custom_properties.get(name) { + substitute_one(name, value, custom_properties, inherited, + Some(substituted), substituted_map, invalid) + } else { + Err(()) + } + }).is_ok() { substituted.push_str(input.slice_from(start)); substituted } else { @@ -279,27 +291,33 @@ fn substitute_one(name: &Atom, Ok(()) } -fn substitute_block(custom_properties: &HashMap<&Atom, BorrowedValue>, - inherited: &Option>>, - input: &mut Parser, - start: &mut SourcePosition, - substituted: &mut String, - substituted_map: &mut HashMap, - invalid: &mut HashSet) - -> Result<(), ()> { - while let Ok(token) = input.next() { +/// Replace `var()` functions in an arbitrary bit of input. +/// +/// The `substitute_one` callback is called for each `var()` function in `input`. +/// If the variable has its initial value, +/// the callback should return `Err(())` and leave `substituted` unchanged. +/// Otherwise, it should push the value of the variable (with its own `var()` functions replaced) +/// to `substituted` and return `Ok(())`. +/// +/// Return `Err(())` if `input` is invalid at computed-value time. +fn substitute_block(input: &mut Parser, + start: &mut SourcePosition, + substituted: &mut String, + substitute_one: &mut F) + -> Result<(), ()> + where F: FnMut(&Atom, &mut String) -> Result<(), ()> { + loop { + let input_slice = input.slice_from(*start); + 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_from(*start)); + substituted.push_str(input_slice); try!(input.parse_nested_block(|input| { let name = input.expect_ident().unwrap(); - debug_assert!(name.starts_with("--")); + debug_assert!(name.starts_with("--")); // Ensured by parse_var_function() let name = Atom::from_slice(&name[2..]); - if let Some(value) = custom_properties.get(&name) { - try!(substitute_one( - &name, value, custom_properties, inherited, - Some(substituted), substituted_map, invalid)); + if substitute_one(&name, substituted).is_ok() { // Skip over the fallback, as `parse_nested_block` would return `Err` // if we don’t consume all of `input`. // FIXME: Add a specialized method to cssparser to do this with less work. @@ -307,9 +325,7 @@ fn substitute_block(custom_properties: &HashMap<&Atom, BorrowedValue>, } else { try!(input.expect_comma()); let mut start = input.position(); - try!(substitute_block( - custom_properties, inherited, input, - &mut start, substituted, substituted_map, invalid)); + try!(substitute_block(input, &mut start, substituted, substitute_one)); substituted.push_str(input.slice_from(start)); } Ok(()) @@ -321,9 +337,9 @@ fn substitute_block(custom_properties: &HashMap<&Atom, BorrowedValue>, Token::ParenthesisBlock | Token::CurlyBracketBlock | Token::SquareBracketBlock => { - try!(input.parse_nested_block(|input| substitute_block( - custom_properties, inherited, input, - start, substituted, substituted_map, invalid))); + try!(input.parse_nested_block(|input| { + substitute_block(input, start, substituted, substitute_one) + })); } _ => {} @@ -337,3 +353,29 @@ fn substitute_block(custom_properties: &HashMap<&Atom, BorrowedValue>, // ``` Ok(()) } + +/// Replace `var()` functions for a non-custom property. +/// Return `Err(())` for invalid at computed time. +pub fn substitute(input: &str, custom_properties: &Option>>) + -> Result { + let empty_map; + let custom_properties = if let &Some(ref arc) = custom_properties { + &**arc + } else { + empty_map = HashMap::new(); + &empty_map + }; + let mut substituted = String::new(); + let mut input = Parser::new(input); + let mut start = input.position(); + try!(substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| { + if let Some(value) = custom_properties.get(name) { + substituted.push_str(value); + Ok(()) + } else { + Err(()) + } + })); + substituted.push_str(input.slice_from(start)); + Ok(substituted) +} diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 866d18e5068..d50018bf37c 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -133,9 +133,11 @@ pub mod longhands { use properties::longhands; use properties::property_bit_field::PropertyBitField; use properties::{ComputedValues, PropertyDeclaration}; + use std::collections::HashMap; use std::sync::Arc; use values::computed::ToComputedValue; use values::{computed, specified}; + use string_cache::Atom; ${caller.body()} #[allow(unused_variables)] pub fn cascade_property(declaration: &PropertyDeclaration, @@ -155,22 +157,25 @@ pub mod longhands { return } seen.set_${property.ident}(); - let computed_value = match *declared_value { - DeclaredValue::Value(ref specified_value) => { - specified_value.to_computed_value(&context) + let computed_value = substitute_variables( + declared_value, &style.custom_properties, |value| match *value { + DeclaredValue::Value(ref specified_value) => { + specified_value.to_computed_value(&context) + } + DeclaredValue::WithVariables { .. } => unreachable!(), + DeclaredValue::Initial => get_initial_value(), + DeclaredValue::Inherit => { + // This is a bit slow, but this is rare so it shouldn't + // matter. + // + // FIXME: is it still? + *cacheable = false; + inherited_style.${THIS_STYLE_STRUCT.ident} + .${property.ident} + .clone() + } } - DeclaredValue::Initial => get_initial_value(), - DeclaredValue::Inherit => { - // This is a bit slow, but this is rare so it shouldn't - // matter. - // - // FIXME: is it still? - *cacheable = false; - inherited_style.${THIS_STYLE_STRUCT.ident} - .${property.ident} - .clone() - } - }; + ); Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} = computed_value; @@ -188,6 +193,29 @@ 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) { @@ -195,7 +223,21 @@ pub mod longhands { Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial), Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${ "Inherit" if THIS_STYLE_STRUCT.inherited else "Initial"}), - Err(()) => parse_specified(context, input), + Err(()) => { + input.look_for_var_functions(); + let start = input.position(); + let specified = parse_specified(context, input); + let var = input.seen_var_functions(); + if specified.is_err() && var { + input.reset(start); + try!(::custom_properties::parse_declaration_value(input, &mut None)); + return Ok(DeclaredValue::WithVariables { + css: input.slice_from(start).to_owned(), + base_url: context.base_url.clone(), + }) + } + specified + } } } % endif @@ -1666,7 +1708,6 @@ pub mod longhands { <%self:longhand name="font-family"> use self::computed_value::FontFamily; - use string_cache::Atom; use values::computed::ComputedValueAsSpecified; pub use self::computed_value::T as SpecifiedValue; @@ -5659,9 +5700,10 @@ impl CSSWideKeyword { } -#[derive(Clone, PartialEq, Eq, Copy, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub enum DeclaredValue { Value(T), + WithVariables { css: String, base_url: Url }, Initial, Inherit, // There is no Unset variant here. @@ -5673,6 +5715,7 @@ 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::Initial => "initial".to_owned(), &DeclaredValue::Inherit => "inherit".to_owned(), } @@ -6092,6 +6135,7 @@ fn cascade_with_cached_declarations( shareable: bool, parent_style: &ComputedValues, cached_style: &ComputedValues, + custom_properties: Option>>, context: &computed::Context) -> ComputedValues { % for style_struct in STYLE_STRUCTS: @@ -6101,10 +6145,7 @@ fn cascade_with_cached_declarations( let mut style_${style_struct.ident} = cached_style.${style_struct.ident}.clone(); % endif % endfor - let mut custom_properties = None; - let mut seen = PropertyBitField::new(); - let mut seen_custom = HashSet::new(); // Declaration blocks are stored in increasing precedence order, // we want them in decreasing order here. for sub_list in applicable_declarations.iter().rev() { @@ -6122,21 +6163,25 @@ fn cascade_with_cached_declarations( continue } seen.set_${property.ident}(); - let computed_value = match *declared_value { - DeclaredValue::Value(ref specified_value) - => specified_value.to_computed_value(context), - DeclaredValue::Initial - => longhands::${property.ident}::get_initial_value(), - DeclaredValue::Inherit => { - // This is a bit slow, but this is rare so it shouldn't - // matter. - // - // FIXME: is it still? - parent_style.${style_struct.ident} - .${property.ident} - .clone() + let computed_value = + longhands::${property.ident}::substitute_variables( + declared_value, &custom_properties, |value| match *value { + DeclaredValue::Value(ref specified_value) + => specified_value.to_computed_value(context), + DeclaredValue::Initial + => longhands::${property.ident}::get_initial_value(), + DeclaredValue::Inherit => { + // This is a bit slow, but this is rare so it shouldn't + // matter. + // + // FIXME: is it still? + parent_style.${style_struct.ident} + .${property.ident} + .clone() + } + DeclaredValue::WithVariables { .. } => unreachable!() } - }; + ); Arc::make_mut(&mut style_${style_struct.ident}) .${property.ident} = computed_value; % endif @@ -6164,11 +6209,7 @@ fn cascade_with_cached_declarations( % endif % endfor % endfor - PropertyDeclaration::Custom(ref name, ref value) => { - ::custom_properties::cascade( - &mut custom_properties, &parent_style.custom_properties, - &mut seen_custom, name, value) - } + PropertyDeclaration::Custom(..) => {} } } } @@ -6183,8 +6224,7 @@ fn cascade_with_cached_declarations( % for style_struct in STYLE_STRUCTS: ${style_struct.ident}: style_${style_struct.ident}, % endfor - custom_properties: ::custom_properties::finish_cascade( - custom_properties, &parent_style.custom_properties), + custom_properties: custom_properties, shareable: shareable, root_font_size: parent_style.root_font_size, } @@ -6247,6 +6287,25 @@ pub fn cascade(viewport_size: Size2D, Some(parent_style) => (false, parent_style), None => (true, initial_values), }; + + let mut custom_properties = None; + let mut seen_custom = HashSet::new(); + for sub_list in applicable_declarations.iter().rev() { + // Declarations are already stored in reverse order. + for declaration in sub_list.declarations.iter() { + match *declaration { + PropertyDeclaration::Custom(ref name, ref value) => { + ::custom_properties::cascade( + &mut custom_properties, &inherited_style.custom_properties, + &mut seen_custom, name, value) + } + _ => {} + } + } + } + let custom_properties = ::custom_properties::finish_cascade( + custom_properties, &inherited_style.custom_properties); + let mut context = { let inherited_font_style = inherited_style.get_font(); computed::Context { @@ -6277,11 +6336,16 @@ 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) => { - match *$declared_value { - DeclaredValue::Value(specified_value) => specified_value, - DeclaredValue::Initial => longhands::$property::get_initial_value(), - DeclaredValue::Inherit => inherited_style.$style_struct_getter().$property.clone(), - } + longhands::$property::substitute_variables( + $declared_value, &custom_properties, |value| match *value { + DeclaredValue::Value(specified_value) => specified_value, + DeclaredValue::Initial => longhands::$property::get_initial_value(), + DeclaredValue::Inherit => { + inherited_style.$style_struct_getter().$property.clone() + } + DeclaredValue::WithVariables { .. } => unreachable!() + } + ) }; ); @@ -6292,31 +6356,37 @@ pub fn cascade(viewport_size: Size2D, for declaration in sub_list.declarations.iter().rev() { match *declaration { PropertyDeclaration::FontSize(ref value) => { - context.font_size = match *value { - DeclaredValue::Value(ref specified_value) => { - match specified_value.0 { - Length::FontRelative(value) => { - value.to_computed_value(context.inherited_font_size, - context.root_font_size) + context.font_size = longhands::font_size::substitute_variables( + value, &custom_properties, |value| match *value { + DeclaredValue::Value(ref specified_value) => { + match specified_value.0 { + Length::FontRelative(value) => { + value.to_computed_value(context.inherited_font_size, + context.root_font_size) + } + Length::ServoCharacterWidth(value) => { + value.to_computed_value(context.inherited_font_size) + } + _ => specified_value.0.to_computed_value(&context) } - Length::ServoCharacterWidth(value) => { - value.to_computed_value(context.inherited_font_size) - } - _ => specified_value.0.to_computed_value(&context) } + DeclaredValue::Initial => longhands::font_size::get_initial_value(), + DeclaredValue::Inherit => context.inherited_font_size, + DeclaredValue::WithVariables { .. } => unreachable!(), } - DeclaredValue::Initial => longhands::font_size::get_initial_value(), - DeclaredValue::Inherit => context.inherited_font_size, - } + ); } PropertyDeclaration::Color(ref value) => { - context.color = match *value { - DeclaredValue::Value(ref specified_value) => { - specified_value.parsed + context.color = longhands::color::substitute_variables( + value, &custom_properties, |value| match *value { + DeclaredValue::Value(ref specified_value) => { + specified_value.parsed + } + DeclaredValue::Initial => longhands::color::get_initial_value(), + DeclaredValue::Inherit => inherited_style.get_color().color.clone(), + DeclaredValue::WithVariables { .. } => unreachable!(), } - DeclaredValue::Initial => longhands::color::get_initial_value(), - DeclaredValue::Inherit => inherited_style.get_color().color.clone(), - }; + ); } PropertyDeclaration::Display(ref value) => { context.display = get_specified!(get_box, display, value); @@ -6368,6 +6438,7 @@ pub fn cascade(viewport_size: Size2D, shareable, parent_style, cached_style, + custom_properties, &context), false) } (_, _) => {} @@ -6384,14 +6455,13 @@ pub fn cascade(viewport_size: Size2D, % endif .${style_struct.ident}.clone(), % endfor - custom_properties: None, - shareable: false, + custom_properties: custom_properties, + shareable: shareable, writing_mode: WritingMode::empty(), root_font_size: context.root_font_size, }; let mut cacheable = true; let mut seen = PropertyBitField::new(); - let mut custom_properties = None; // Declaration blocks are stored in increasing precedence order, we want them in decreasing // order here. // @@ -6399,28 +6469,21 @@ pub fn cascade(viewport_size: Size2D, // of compiled code! To improve i-cache behavior, we outline the individual functions and use // virtual dispatch instead. CASCADE_PROPERTY.with(|cascade_property| { - let mut seen_custom = HashSet::new(); for sub_list in applicable_declarations.iter().rev() { // Declarations are already stored in reverse order. for declaration in sub_list.declarations.iter() { - match *declaration { - PropertyDeclaration::Custom(ref name, ref value) => { - ::custom_properties::cascade( - &mut custom_properties, &inherited_style.custom_properties, - &mut seen_custom, name, value) - } - _ => { - let discriminant = unsafe { - intrinsics::discriminant_value(declaration) as usize - }; - (cascade_property[discriminant].unwrap())(declaration, - &mut style, - inherited_style, - &context, - &mut seen, - &mut cacheable); - } + if let PropertyDeclaration::Custom(..) = *declaration { + continue } + let discriminant = unsafe { + intrinsics::discriminant_value(declaration) as usize + }; + (cascade_property[discriminant].unwrap())(declaration, + &mut style, + inherited_style, + &context, + &mut seen, + &mut cacheable); } } }); @@ -6457,16 +6520,8 @@ pub fn cascade(viewport_size: Size2D, compute_font_hash(&mut *Arc::make_mut(&mut style.font)) } - (ComputedValues { - writing_mode: get_writing_mode(&*style.inheritedbox), - % for style_struct in STYLE_STRUCTS: - ${style_struct.ident}: style.${style_struct.ident}, - % endfor - custom_properties: ::custom_properties::finish_cascade( - custom_properties, &inherited_style.custom_properties), - shareable: shareable, - root_font_size: context.root_font_size, - }, cacheable) + style.writing_mode = get_writing_mode(&*style.inheritedbox); + (style, cacheable) } /// Alters the given style to accommodate replaced content. This is called in flow construction. It diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 09dba1b601b..a1b6fcb972e 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -127,7 +127,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -144,7 +144,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -871,7 +871,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1339,7 +1339,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1397,7 +1397,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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)", @@ -1567,7 +1567,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1695,7 +1695,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 34db28d0323..2937310372f 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -108,7 +108,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -125,7 +125,7 @@ name = "canvas_traits" version = "0.0.1" dependencies = [ "azure 0.1.0 (git+https://github.com/servo/rust-azure)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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)", @@ -250,7 +250,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", @@ -755,7 +755,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1205,7 +1205,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1263,7 +1263,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (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)", @@ -1413,7 +1413,7 @@ name = "style" version = "0.0.1" dependencies = [ "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1530,7 +1530,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.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.6 (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.3 (registry+https://github.com/rust-lang/crates.io-index)",