Record first and last token type of custom property values.

This commit is contained in:
Simon Sapin 2015-09-09 20:47:49 +02:00
parent b8fd51e940
commit 81dd1ab363
7 changed files with 129 additions and 90 deletions

View file

@ -137,7 +137,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -154,7 +154,7 @@ name = "canvas_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
@ -290,7 +290,7 @@ dependencies = [
[[package]] [[package]]
name = "cssparser" name = "cssparser"
version = "0.3.8" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
@ -929,7 +929,7 @@ dependencies = [
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "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)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"encoding 0.2.32 (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)", "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" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.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)", "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)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1622,7 +1622,7 @@ name = "style"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1647,7 +1647,7 @@ dependencies = [
name = "style_tests" name = "style_tests"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "string_cache 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1662,7 +1662,7 @@ dependencies = [
name = "style_traits" name = "style_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1784,7 +1784,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -23,7 +23,7 @@ git = "https://github.com/servo/rust-selectors"
features = ["unstable"] features = ["unstable"]
[dependencies.cssparser] [dependencies.cssparser]
version = "0.3.8" version = "0.3.9"
features = [ "serde-serialization" ] features = [ "serde-serialization" ]
[dependencies.url] [dependencies.url]

View file

@ -2,12 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, Token, SourcePosition, Delimiter}; use cssparser::{Parser, Token, SourcePosition, Delimiter, TokenSerializationType};
use properties::DeclaredValue; use properties::DeclaredValue;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::sync::Arc; use std::sync::Arc;
use string_cache::Atom; use string_cache::Atom;
use util::mem::HeapSizeOf;
// Does not include the `--` prefix // Does not include the `--` prefix
pub type Name = Atom; pub type Name = Atom;
@ -22,38 +23,51 @@ pub fn parse_name(s: &str) -> Result<Name, ()> {
} }
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
pub struct Value { pub struct SpecifiedValue {
/// In CSS syntax css: String,
value: String,
first_token: TokenSerializationType,
last_token: TokenSerializationType,
/// Custom property names in var() functions. /// Custom property names in var() functions.
references: HashSet<Name>, references: HashSet<Name>,
} }
pub struct BorrowedValue<'a> { pub struct BorrowedSpecifiedValue<'a> {
value: &'a str, css: &'a str,
first_token: TokenSerializationType,
last_token: TokenSerializationType,
references: Option<&'a HashSet<Name>>, references: Option<&'a HashSet<Name>>,
} }
pub fn parse(input: &mut Parser) -> Result<Value, ()> { #[derive(Clone, HeapSizeOf)]
pub struct ComputedValue {
css: String,
first_token: TokenSerializationType,
last_token: TokenSerializationType,
}
pub type ComputedValuesMap = HashMap<Name, ComputedValue>;
pub fn parse(input: &mut Parser) -> Result<SpecifiedValue, ()> {
let start = input.position(); let start = input.position();
let mut references = Some(HashSet::new()); let mut references = Some(HashSet::new());
try!(parse_declaration_value(input, &mut references)); let (first_token, last_token) = try!(parse_declaration_value(input, &mut references));
Ok(Value { Ok(SpecifiedValue {
value: input.slice_from(start).to_owned(), css: input.slice_from(start).to_owned(),
first_token: first_token,
last_token: last_token,
references: references.unwrap(), references: references.unwrap(),
}) })
} }
/// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value /// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value
pub fn parse_declaration_value(input: &mut Parser, references: &mut Option<HashSet<Name>>) pub fn parse_declaration_value(input: &mut Parser, references: &mut Option<HashSet<Name>>)
-> Result<(), ()> { -> Result<(TokenSerializationType, TokenSerializationType), ()> {
input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
// Need at least one token // Need at least one token
let start_position = input.position(); let start_position = input.position();
if input.next_including_whitespace().is_err() { try!(input.next_including_whitespace());
return Err(())
}
input.reset(start_position); input.reset(start_position);
parse_declaration_value_block(input, references) parse_declaration_value_block(input, references)
@ -63,8 +77,16 @@ pub fn parse_declaration_value(input: &mut Parser, references: &mut Option<HashS
/// Like parse_declaration_value, /// Like parse_declaration_value,
/// but accept `!` and `;` since they are only invalid at the top level /// 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>>)
-> Result<(), ()> { -> Result<(TokenSerializationType, TokenSerializationType), ()> {
while let Ok(token) = input.next() { 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 doesnt 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 { match token {
Token::BadUrl | Token::BadUrl |
Token::BadString | Token::BadString |
@ -92,7 +114,7 @@ fn parse_declaration_value_block(input: &mut Parser, references: &mut Option<Has
_ => {} _ => {}
} }
} }
Ok(()) Ok((first_token_type, last_token_type))
} }
// If the var function is valid, return Ok((custom_property_name, fallback)) // If the var function is valid, return Ok((custom_property_name, fallback))
@ -111,30 +133,37 @@ fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, references: &mut Optio
/// Add one custom property declaration to a map, /// Add one custom property declaration to a map,
/// unless another with the same name was already there. /// unless another with the same name was already there.
pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedValue<'a>>>, pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedSpecifiedValue<'a>>>,
inherited: &'a Option<Arc<HashMap<Name, String>>>, inherited: &'a Option<Arc<HashMap<Name, ComputedValue>>>,
seen: &mut HashSet<&'a Name>, seen: &mut HashSet<&'a Name>,
name: &'a Name, name: &'a Name,
value: &'a DeclaredValue<Value>) { specified_value: &'a DeclaredValue<SpecifiedValue>) {
let was_not_already_present = seen.insert(name); let was_not_already_present = seen.insert(name);
if was_not_already_present { if was_not_already_present {
let map = match *custom_properties { let map = match *custom_properties {
Some(ref mut map) => map, Some(ref mut map) => map,
None => { None => {
*custom_properties = Some(match *inherited { *custom_properties = Some(match *inherited {
Some(ref inherited) => inherited.iter().map(|(key, value)| { Some(ref inherited) => inherited.iter().map(|(key, inherited_value)| {
(key, BorrowedValue { value: &value, references: None }) (key, BorrowedSpecifiedValue {
css: &inherited_value.css,
first_token: inherited_value.first_token,
last_token: inherited_value.last_token,
references: None
})
}).collect(), }).collect(),
None => HashMap::new(), None => HashMap::new(),
}); });
custom_properties.as_mut().unwrap() custom_properties.as_mut().unwrap()
} }
}; };
match *value { match *specified_value {
DeclaredValue::Value(ref value) => { DeclaredValue::Value(ref specified_value) => {
map.insert(name, BorrowedValue { map.insert(name, BorrowedSpecifiedValue {
value: &value.value, css: &specified_value.css,
references: Some(&value.references), first_token: specified_value.first_token,
last_token: specified_value.last_token,
references: Some(&specified_value.references),
}); });
}, },
DeclaredValue::WithVariables { .. } => unreachable!(), DeclaredValue::WithVariables { .. } => unreachable!(),
@ -146,9 +175,9 @@ pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedValu
} }
} }
pub fn finish_cascade(custom_properties: Option<HashMap<&Name, BorrowedValue>>, pub fn finish_cascade(custom_properties: Option<HashMap<&Name, BorrowedSpecifiedValue>>,
inherited: &Option<Arc<HashMap<Name, String>>>) inherited: &Option<Arc<HashMap<Name, ComputedValue>>>)
-> Option<Arc<HashMap<Name, String>>> { -> Option<Arc<HashMap<Name, ComputedValue>>> {
if let Some(mut map) = custom_properties { if let Some(mut map) = custom_properties {
remove_cycles(&mut map); remove_cycles(&mut map);
Some(Arc::new(substitute_all(map, inherited))) Some(Arc::new(substitute_all(map, inherited)))
@ -159,7 +188,7 @@ pub fn finish_cascade(custom_properties: Option<HashMap<&Name, BorrowedValue>>,
/// https://drafts.csswg.org/css-variables/#cycles /// https://drafts.csswg.org/css-variables/#cycles
/// The initial value of a custom property is represented by this property not being in the map. /// The initial value of a custom property is represented by this property not being in the map.
fn remove_cycles(map: &mut HashMap<&Name, BorrowedValue>) { fn remove_cycles(map: &mut HashMap<&Name, BorrowedSpecifiedValue>) {
let mut to_remove = HashSet::new(); let mut to_remove = HashSet::new();
{ {
let mut visited = HashSet::new(); let mut visited = HashSet::new();
@ -167,7 +196,7 @@ fn remove_cycles(map: &mut HashMap<&Name, BorrowedValue>) {
for name in map.keys() { for name in map.keys() {
walk(map, name, &mut stack, &mut visited, &mut to_remove); walk(map, name, &mut stack, &mut visited, &mut to_remove);
fn walk<'a>(map: &HashMap<&'a Name, BorrowedValue<'a>>, fn walk<'a>(map: &HashMap<&'a Name, BorrowedSpecifiedValue<'a>>,
name: &'a Name, name: &'a Name,
stack: &mut Vec<&'a Name>, stack: &mut Vec<&'a Name>,
visited: &mut HashSet<&'a Name>, visited: &mut HashSet<&'a Name>,
@ -201,9 +230,9 @@ fn remove_cycles(map: &mut HashMap<&Name, BorrowedValue>) {
} }
/// Replace `var()` functions for all custom properties. /// Replace `var()` functions for all custom properties.
fn substitute_all(custom_properties: HashMap<&Name, BorrowedValue>, fn substitute_all(custom_properties: HashMap<&Name, BorrowedSpecifiedValue>,
inherited: &Option<Arc<HashMap<Name, String>>>) inherited: &Option<Arc<HashMap<Name, ComputedValue>>>)
-> HashMap<Name, String> { -> HashMap<Name, ComputedValue> {
let mut substituted_map = HashMap::new(); let mut substituted_map = HashMap::new();
let mut invalid = HashSet::new(); let mut invalid = HashSet::new();
for (&name, value) in &custom_properties { for (&name, value) in &custom_properties {
@ -219,16 +248,16 @@ fn substitute_all(custom_properties: HashMap<&Name, BorrowedValue>,
/// Also recursively record results for other custom properties referenced by `var()` functions. /// Also recursively record results for other custom properties referenced by `var()` functions.
/// Return `Err(())` for invalid at computed time. /// Return `Err(())` for invalid at computed time.
fn substitute_one(name: &Name, fn substitute_one(name: &Name,
value: &BorrowedValue, specified_value: &BorrowedSpecifiedValue,
custom_properties: &HashMap<&Name, BorrowedValue>, custom_properties: &HashMap<&Name, BorrowedSpecifiedValue>,
inherited: &Option<Arc<HashMap<Name, String>>>, inherited: &Option<Arc<HashMap<Name, ComputedValue>>>,
substituted: Option<&mut String>, substituted: Option<&mut String>,
substituted_map: &mut HashMap<Name, String>, substituted_map: &mut HashMap<Name, ComputedValue>,
invalid: &mut HashSet<Name>) invalid: &mut HashSet<Name>)
-> Result<(), ()> { -> Result<(), ()> {
if let Some(value) = substituted_map.get(name) { if let Some(computed_value) = substituted_map.get(name) {
if let Some(substituted) = substituted { if let Some(substituted) = substituted {
substituted.push_str(value) substituted.push_str(&computed_value.css)
} }
return Ok(()) return Ok(())
} }
@ -236,36 +265,46 @@ fn substitute_one(name: &Name,
if invalid.contains(name) { if invalid.contains(name) {
return Err(()); return Err(());
} }
let value = if value.references.map(|set| set.is_empty()) == Some(false) { let computed_value = if specified_value.references.map(|set| set.is_empty()) == Some(false) {
let mut substituted = String::new(); let mut substituted = String::new();
let mut input = Parser::new(&value.value); let mut input = Parser::new(&specified_value.css);
let mut start = input.position(); let mut start = input.position();
if substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| { if substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| {
if let Some(value) = custom_properties.get(name) { if let Some(other_specified_value) = custom_properties.get(name) {
substitute_one(name, value, custom_properties, inherited, substitute_one(name, other_specified_value, custom_properties, inherited,
Some(substituted), substituted_map, invalid) Some(substituted), substituted_map, invalid)
} else { } else {
Err(()) Err(())
} }
}).is_ok() { }).is_ok() {
substituted.push_str(input.slice_from(start)); substituted.push_str(input.slice_from(start));
substituted ComputedValue {
css: substituted,
// FIXME: what if these are `var(` or the corresponding `)`?
first_token: specified_value.first_token,
last_token: specified_value.last_token,
}
} else { } else {
// Invalid at computed-value time. Use the inherited value. // Invalid at computed-value time. Use the inherited value.
if let Some(value) = inherited.as_ref().and_then(|i| i.get(name)) { if let Some(inherited_value) = inherited.as_ref().and_then(|i| i.get(name)) {
value.clone() inherited_value.clone()
} else { } else {
invalid.insert(name.clone()); invalid.insert(name.clone());
return Err(()) return Err(())
} }
} }
} else { } else {
value.value.to_owned() // The specified value contains no var() reference
ComputedValue {
css: specified_value.css.to_owned(),
first_token: specified_value.first_token,
last_token: specified_value.last_token,
}
}; };
if let Some(substituted) = substituted { if let Some(substituted) = substituted {
substituted.push_str(&value) substituted.push_str(&computed_value.css)
} }
substituted_map.insert(name.clone(), value); substituted_map.insert(name.clone(), computed_value);
Ok(()) Ok(())
} }
@ -334,7 +373,7 @@ fn substitute_block<F>(input: &mut Parser,
/// Replace `var()` functions for a non-custom property. /// Replace `var()` functions for a non-custom property.
/// Return `Err(())` for invalid at computed time. /// Return `Err(())` for invalid at computed time.
pub fn substitute(input: &str, custom_properties: &Option<Arc<HashMap<Name, String>>>) pub fn substitute(input: &str, custom_properties: &Option<Arc<HashMap<Name, ComputedValue>>>)
-> Result<String, ()> { -> Result<String, ()> {
let empty_map; let empty_map;
let custom_properties = if let &Some(ref arc) = custom_properties { let custom_properties = if let &Some(ref arc) = custom_properties {
@ -348,7 +387,7 @@ pub fn substitute(input: &str, custom_properties: &Option<Arc<HashMap<Name, Stri
let mut start = input.position(); let mut start = input.position();
try!(substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| { try!(substitute_block(&mut input, &mut start, &mut substituted, &mut |name, substituted| {
if let Some(value) = custom_properties.get(name) { if let Some(value) = custom_properties.get(name) {
substituted.push_str(value); substituted.push_str(&value.css);
Ok(()) Ok(())
} else { } else {
Err(()) Err(())

View file

@ -6,7 +6,7 @@
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::collections::{HashSet, HashMap}; use std::collections::HashSet;
use std::default::Default; use std::default::Default;
use std::fmt; use std::fmt;
use std::fmt::Debug; use std::fmt::Debug;
@ -23,7 +23,6 @@ use util::logical_geometry::{LogicalMargin, PhysicalSide, WritingMode};
use euclid::SideOffsets2D; use euclid::SideOffsets2D;
use euclid::size::Size2D; use euclid::size::Size2D;
use fnv::FnvHasher; use fnv::FnvHasher;
use string_cache::Atom;
use computed_values; use computed_values;
use parser::{ParserContext, log_css_error}; use parser::{ParserContext, log_css_error};
@ -5604,7 +5603,7 @@ mod property_bit_field {
% if property.derived_from is None: % if property.derived_from is None:
fn substitute_variables_${property.ident}<F, R>( fn substitute_variables_${property.ident}<F, R>(
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>, value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
custom_properties: &Option<Arc<HashMap<Atom, String>>>, custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
f: F) f: F)
-> R -> R
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
@ -5827,7 +5826,7 @@ pub enum PropertyDeclaration {
% for property in LONGHANDS: % for property in LONGHANDS:
${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>), ${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>),
% endfor % endfor
Custom(::custom_properties::Name, DeclaredValue<::custom_properties::Value>), Custom(::custom_properties::Name, DeclaredValue<::custom_properties::SpecifiedValue>),
} }
@ -5988,7 +5987,7 @@ pub struct ComputedValues {
% for style_struct in STYLE_STRUCTS: % for style_struct in STYLE_STRUCTS:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
custom_properties: Option<Arc<HashMap<::custom_properties::Name, String>>>, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool, shareable: bool,
pub writing_mode: WritingMode, pub writing_mode: WritingMode,
pub root_font_size: Au, pub root_font_size: Au,
@ -6222,7 +6221,7 @@ fn cascade_with_cached_declarations(
shareable: bool, shareable: bool,
parent_style: &ComputedValues, parent_style: &ComputedValues,
cached_style: &ComputedValues, cached_style: &ComputedValues,
custom_properties: Option<Arc<HashMap<Atom, String>>>, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
context: &computed::Context) context: &computed::Context)
-> ComputedValues { -> ComputedValues {
% for style_struct in STYLE_STRUCTS: % for style_struct in STYLE_STRUCTS:

View file

@ -15,7 +15,7 @@ use std::sync::Arc;
use azure::azure_hl::Color; use azure::azure_hl::Color;
use cssparser::Color as CSSParserColor; use cssparser::Color as CSSParserColor;
use cssparser::RGBA; use cssparser::{RGBA, TokenSerializationType};
use cursor::Cursor; use cursor::Cursor;
use euclid::length::Length; use euclid::length::Length;
use euclid::scale_factor::ScaleFactor; use euclid::scale_factor::ScaleFactor;
@ -414,6 +414,7 @@ known_heap_size!(0, Rect<T>, Point2D<T>, Size2D<T>, Matrix2D<T>, SideOffsets2D<T
known_heap_size!(0, Length<T, U>, ScaleFactor<T, U, V>); known_heap_size!(0, Length<T, U>, ScaleFactor<T, U, V>);
known_heap_size!(0, Au, WritingMode, CSSParserColor, Color, RGBA, Cursor, Matrix4, Atom, Namespace); known_heap_size!(0, Au, WritingMode, CSSParserColor, Color, RGBA, Cursor, Matrix4, Atom, Namespace);
known_heap_size!(0, JSVal, PagePx, ViewportPx, DevicePixel, QuirksMode, OsRng, RawStatus, LengthOrPercentageOrAuto); known_heap_size!(0, JSVal, PagePx, ViewportPx, DevicePixel, QuirksMode, OsRng, RawStatus);
known_heap_size!(0, TokenSerializationType, LengthOrPercentageOrAuto);
known_heap_size!(0, PseudoElement, Combinator, str); known_heap_size!(0, PseudoElement, Combinator, str);

18
ports/cef/Cargo.lock generated
View file

@ -129,7 +129,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -146,7 +146,7 @@ name = "canvas_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
@ -282,7 +282,7 @@ dependencies = [
[[package]] [[package]]
name = "cssparser" name = "cssparser"
version = "0.3.8" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
@ -880,7 +880,7 @@ dependencies = [
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "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)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"encoding 0.2.32 (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)", "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" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.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)", "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)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1581,7 +1581,7 @@ name = "style"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1606,7 +1606,7 @@ dependencies = [
name = "style_traits" name = "style_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1728,7 +1728,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",

18
ports/gonk/Cargo.lock generated
View file

@ -110,7 +110,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -127,7 +127,7 @@ name = "canvas_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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", "gfx_traits 0.0.1",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
@ -252,7 +252,7 @@ dependencies = [
[[package]] [[package]]
name = "cssparser" name = "cssparser"
version = "0.3.8" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)",
@ -764,7 +764,7 @@ dependencies = [
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)", "clock_ticks 0.0.6 (git+https://github.com/tomaka/clock_ticks)",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "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)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"encoding 0.2.32 (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)", "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" source = "git+https://github.com/servo/rust-selectors#572353b3209af040cd3e6261978b09c7f8122844"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.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)", "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)", "quickersort 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1427,7 +1427,7 @@ name = "style"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.32 (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)", "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)", "fnv 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1452,7 +1452,7 @@ dependencies = [
name = "style_traits" name = "style_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1563,7 +1563,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"bitflags 0.3.2 (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.8 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.2.0 (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)", "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)", "html5ever 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",