Upgrade cssparser to 0.15

This commit is contained in:
Simon Sapin 2017-06-15 21:58:40 +02:00
parent 66c130d55a
commit b83afdedc8
42 changed files with 234 additions and 217 deletions

26
Cargo.lock generated
View file

@ -312,7 +312,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.19.0 (git+https://github.com/servo/rust-azure)", "azure 0.19.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -327,7 +327,7 @@ dependencies = [
name = "canvas_traits" name = "canvas_traits"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -572,7 +572,7 @@ dependencies = [
[[package]] [[package]]
name = "cssparser" name = "cssparser"
version = "0.15.0" version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -999,7 +999,7 @@ name = "geckoservo"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1065,7 +1065,7 @@ dependencies = [
name = "gfx_tests" name = "gfx_tests"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx 0.0.1", "gfx 0.0.1",
"ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
@ -2361,7 +2361,7 @@ dependencies = [
"caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"deny_public_fields 0.0.1", "deny_public_fields 0.0.1",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"dom_struct 0.0.1", "dom_struct 0.0.1",
@ -2434,7 +2434,7 @@ dependencies = [
"app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1", "gfx_traits 0.0.1",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2505,7 +2505,7 @@ name = "selectors"
version = "0.19.0" version = "0.19.0"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2897,7 +2897,7 @@ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2950,7 +2950,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2971,7 +2971,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_units 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2984,7 +2984,7 @@ name = "stylo_tests"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"geckoservo 0.0.1", "geckoservo 0.0.1",
@ -3564,7 +3564,7 @@ dependencies = [
"checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624" "checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624"
"checksum core-graphics 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f841e9637adec70838c537cae52cb4c751cc6514ad05669b51d107c2021c79" "checksum core-graphics 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a9f841e9637adec70838c537cae52cb4c751cc6514ad05669b51d107c2021c79"
"checksum core-text 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74ba2a7abdccb94fb6c00822addef48504182b285aa45a30e78286487888fcb4" "checksum core-text 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74ba2a7abdccb94fb6c00822addef48504182b285aa45a30e78286487888fcb4"
"checksum cssparser 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd54cdee668d71d20e9f8b9676e2e969968d186ab20a101af59c28398393a2b0" "checksum cssparser 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c711c0c610b1e5fc2bf96e325b2d9f85839a8e71f6279a77c194af5dcafa502"
"checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df" "checksum cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "079adec4af52bb5275eadd004292028c79eb3c5f5b4ee8086a36d4197032f6df"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum dbus 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4aee01fb76ada3e5e7ca642ea6664ebf7308a810739ca2aca44909a1191ac254" "checksum dbus 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4aee01fb76ada3e5e7ca642ea6664ebf7308a810739ca2aca44909a1191ac254"

View file

@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies] [dependencies]
azure = {git = "https://github.com/servo/rust-azure"} azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"} canvas_traits = {path = "../canvas_traits"}
cssparser = "0.15" cssparser = "0.16"
euclid = "0.15" euclid = "0.15"
gleam = "0.4" gleam = "0.4"
ipc-channel = "0.8" ipc-channel = "0.8"

View file

@ -10,7 +10,7 @@ name = "canvas_traits"
path = "lib.rs" path = "lib.rs"
[dependencies] [dependencies]
cssparser = "0.15" cssparser = "0.16"
euclid = "0.15" euclid = "0.15"
heapsize = "0.4" heapsize = "0.4"
heapsize_derive = "0.1" heapsize_derive = "0.1"

View file

@ -35,7 +35,7 @@ byteorder = "1.0"
canvas_traits = {path = "../canvas_traits"} canvas_traits = {path = "../canvas_traits"}
caseless = "0.1.0" caseless = "0.1.0"
cookie = "0.6" cookie = "0.6"
cssparser = "0.15" cssparser = "0.16"
deny_public_fields = {path = "../deny_public_fields"} deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"} devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"} dom_struct = {path = "../dom_struct"}

View file

@ -4,6 +4,7 @@
//! The `ByteString` struct. //! The `ByteString` struct.
use cssparser::CompactCowStr;
use html5ever::{LocalName, Namespace}; use html5ever::{LocalName, Namespace};
use servo_atoms::Atom; use servo_atoms::Atom;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
@ -298,6 +299,12 @@ impl<'a> Into<Cow<'a, str>> for DOMString {
} }
} }
impl<'a> Into<CompactCowStr<'a>> for DOMString {
fn into(self) -> CompactCowStr<'a> {
self.0.into()
}
}
impl Extend<char> for DOMString { impl Extend<char> for DOMString {
fn extend<I>(&mut self, iterable: I) where I: IntoIterator<Item=char> { fn extend<I>(&mut self, iterable: I) where I: IntoIterator<Item=char> {
self.0.extend(iterable) self.0.extend(iterable)

View file

@ -13,7 +13,7 @@ path = "lib.rs"
app_units = "0.5" app_units = "0.5"
atomic_refcell = "0.1" atomic_refcell = "0.1"
canvas_traits = {path = "../canvas_traits"} canvas_traits = {path = "../canvas_traits"}
cssparser = "0.15" cssparser = "0.16"
euclid = "0.15" euclid = "0.15"
gfx_traits = {path = "../gfx_traits"} gfx_traits = {path = "../gfx_traits"}
heapsize = "0.4" heapsize = "0.4"

View file

@ -24,7 +24,7 @@ gecko_like_types = []
[dependencies] [dependencies]
bitflags = "0.7" bitflags = "0.7"
matches = "0.1" matches = "0.1"
cssparser = "0.15" cssparser = "0.16"
log = "0.3" log = "0.3"
fnv = "1.0" fnv = "1.0"
phf = "0.7.18" phf = "0.7.18"

View file

@ -5,7 +5,7 @@
use attr::{AttrSelectorWithNamespace, ParsedAttrSelectorOperation, AttrSelectorOperator}; use attr::{AttrSelectorWithNamespace, ParsedAttrSelectorOperation, AttrSelectorOperator};
use attr::{ParsedCaseSensitivity, SELECTOR_WHITESPACE, NamespaceConstraint}; use attr::{ParsedCaseSensitivity, SELECTOR_WHITESPACE, NamespaceConstraint};
use bloom::BLOOM_HASH_MASK; use bloom::BLOOM_HASH_MASK;
use cssparser::{ParseError, BasicParseError}; use cssparser::{ParseError, BasicParseError, CompactCowStr};
use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter}; use cssparser::{Token, Parser as CssParser, parse_nth, ToCss, serialize_identifier, CssStringWriter};
use precomputed_hash::PrecomputedHash; use precomputed_hash::PrecomputedHash;
use servo_arc::{Arc, HeaderWithLength, ThinArc}; use servo_arc::{Arc, HeaderWithLength, ThinArc};
@ -58,7 +58,7 @@ pub enum SelectorParseError<'i, T> {
PseudoElementExpectedColon, PseudoElementExpectedColon,
PseudoElementExpectedIdent, PseudoElementExpectedIdent,
UnsupportedPseudoClass, UnsupportedPseudoClass,
UnexpectedIdent(Cow<'i, str>), UnexpectedIdent(CompactCowStr<'i>),
ExpectedNamespace, ExpectedNamespace,
Custom(T), Custom(T),
} }
@ -133,21 +133,21 @@ pub trait Parser<'i> {
/// This function can return an "Err" pseudo-element in order to support CSS2.1 /// This function can return an "Err" pseudo-element in order to support CSS2.1
/// pseudo-elements. /// pseudo-elements.
fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>) fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass, -> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass,
ParseError<'i, SelectorParseError<'i, Self::Error>>> { ParseError<'i, SelectorParseError<'i, Self::Error>>> {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name))) Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
} }
fn parse_non_ts_functional_pseudo_class<'t> fn parse_non_ts_functional_pseudo_class<'t>
(&self, name: Cow<'i, str>, _arguments: &mut CssParser<'i, 't>) (&self, name: CompactCowStr<'i>, _arguments: &mut CssParser<'i, 't>)
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass, -> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass,
ParseError<'i, SelectorParseError<'i, Self::Error>>> ParseError<'i, SelectorParseError<'i, Self::Error>>>
{ {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name))) Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
} }
fn parse_pseudo_element(&self, name: Cow<'i, str>) fn parse_pseudo_element(&self, name: CompactCowStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::PseudoElement, -> Result<<Self::Impl as SelectorImpl>::PseudoElement,
ParseError<'i, SelectorParseError<'i, Self::Error>>> { ParseError<'i, SelectorParseError<'i, Self::Error>>> {
Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name))) Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name)))
@ -1152,7 +1152,7 @@ fn parse_type_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParser<'i,
Some(name) => { Some(name) => {
sequence.push(Component::LocalName(LocalName { sequence.push(Component::LocalName(LocalName {
lower_name: from_cow_str(to_ascii_lowercase(&name)), lower_name: from_cow_str(to_ascii_lowercase(&name)),
name: from_cow_str(name), name: from_cow_str(name.into()),
})) }))
} }
None => { None => {
@ -1186,7 +1186,7 @@ enum QNamePrefix<Impl: SelectorImpl> {
fn parse_qualified_name<'i, 't, P, E, Impl> fn parse_qualified_name<'i, 't, P, E, Impl>
(parser: &P, input: &mut CssParser<'i, 't>, (parser: &P, input: &mut CssParser<'i, 't>,
in_attr_selector: bool) in_attr_selector: bool)
-> Result<Option<(QNamePrefix<Impl>, Option<Cow<'i, str>>)>, -> Result<Option<(QNamePrefix<Impl>, Option<CompactCowStr<'i>>)>,
ParseError<'i, SelectorParseError<'i, E>>> ParseError<'i, SelectorParseError<'i, E>>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl
{ {
@ -1217,7 +1217,7 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
let position = input.position(); let position = input.position();
match input.next_including_whitespace() { match input.next_including_whitespace() {
Ok(Token::Delim('|')) => { Ok(Token::Delim('|')) => {
let prefix = from_cow_str(value); let prefix = from_cow_str(value.into());
let result = parser.namespace_for_prefix(&prefix); let result = parser.namespace_for_prefix(&prefix);
let url = result.ok_or(ParseError::Custom(SelectorParseError::ExpectedNamespace))?; let url = result.ok_or(ParseError::Custom(SelectorParseError::ExpectedNamespace))?;
explicit_namespace(input, QNamePrefix::ExplicitNamespace(prefix, url)) explicit_namespace(input, QNamePrefix::ExplicitNamespace(prefix, url))
@ -1300,7 +1300,7 @@ fn parse_attribute_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParse
// [foo] // [foo]
Err(_) => { Err(_) => {
let local_name_lower = from_cow_str(to_ascii_lowercase(&local_name)); let local_name_lower = from_cow_str(to_ascii_lowercase(&local_name));
let local_name = from_cow_str(local_name); let local_name = from_cow_str(local_name.into());
if let Some(namespace) = namespace { if let Some(namespace) = namespace {
return Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace { return Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace {
namespace: namespace, namespace: namespace,
@ -1358,7 +1358,7 @@ fn parse_attribute_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParse
let mut case_sensitivity = parse_attribute_flags(input)?; let mut case_sensitivity = parse_attribute_flags(input)?;
let value = from_cow_str(value); let value = from_cow_str(value.into());
let local_name_lower; let local_name_lower;
{ {
let local_name_lower_cow = to_ascii_lowercase(&local_name); let local_name_lower_cow = to_ascii_lowercase(&local_name);
@ -1371,9 +1371,9 @@ fn parse_attribute_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParse
ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument
} }
} }
local_name_lower = from_cow_str(local_name_lower_cow); local_name_lower = from_cow_str(local_name_lower_cow.into());
} }
let local_name = from_cow_str(local_name); let local_name = from_cow_str(local_name.into());
if let Some(namespace) = namespace { if let Some(namespace) = namespace {
Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace { Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace {
namespace: namespace, namespace: namespace,
@ -1551,7 +1551,7 @@ fn parse_compound_selector<'i, 't, P, E, Impl>(
fn parse_functional_pseudo_class<'i, 't, P, E, Impl>(parser: &P, fn parse_functional_pseudo_class<'i, 't, P, E, Impl>(parser: &P,
input: &mut CssParser<'i, 't>, input: &mut CssParser<'i, 't>,
name: Cow<'i, str>, name: CompactCowStr<'i>,
inside_negation: bool) inside_negation: bool)
-> Result<Component<Impl>, -> Result<Component<Impl>,
ParseError<'i, SelectorParseError<'i, E>>> ParseError<'i, SelectorParseError<'i, E>>>
@ -1599,13 +1599,13 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
let start_position = input.position(); let start_position = input.position();
match input.next_including_whitespace() { match input.next_including_whitespace() {
Ok(Token::IDHash(id)) => { Ok(Token::IDHash(id)) => {
let id = Component::ID(from_cow_str(id)); let id = Component::ID(from_cow_str(id.into()));
Ok(Some(SimpleSelectorParseResult::SimpleSelector(id))) Ok(Some(SimpleSelectorParseResult::SimpleSelector(id)))
} }
Ok(Token::Delim('.')) => { Ok(Token::Delim('.')) => {
match input.next_including_whitespace() { match input.next_including_whitespace() {
Ok(Token::Ident(class)) => { Ok(Token::Ident(class)) => {
let class = Component::Class(from_cow_str(class)); let class = Component::Class(from_cow_str(class.into()));
Ok(Some(SimpleSelectorParseResult::SimpleSelector(class))) Ok(Some(SimpleSelectorParseResult::SimpleSelector(class)))
} }
Ok(t) => Err(ParseError::Basic(BasicParseError::UnexpectedToken(t))), Ok(t) => Err(ParseError::Basic(BasicParseError::UnexpectedToken(t))),
@ -1659,7 +1659,7 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
} }
} }
fn parse_simple_pseudo_class<'i, P, E, Impl>(parser: &P, name: Cow<'i, str>) fn parse_simple_pseudo_class<'i, P, E, Impl>(parser: &P, name: CompactCowStr<'i>)
-> Result<Component<Impl>, -> Result<Component<Impl>,
ParseError<'i, SelectorParseError<'i, E>>> ParseError<'i, SelectorParseError<'i, E>>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl
@ -1804,7 +1804,7 @@ pub mod tests {
type Impl = DummySelectorImpl; type Impl = DummySelectorImpl;
type Error = (); type Error = ();
fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>) fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>)
-> Result<PseudoClass, -> Result<PseudoClass,
ParseError<'i, SelectorParseError<'i, ()>>> { ParseError<'i, SelectorParseError<'i, ()>>> {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,
@ -1814,7 +1814,7 @@ pub mod tests {
} }
} }
fn parse_non_ts_functional_pseudo_class<'t>(&self, name: Cow<'i, str>, fn parse_non_ts_functional_pseudo_class<'t>(&self, name: CompactCowStr<'i>,
parser: &mut CssParser<'i, 't>) parser: &mut CssParser<'i, 't>)
-> Result<PseudoClass, -> Result<PseudoClass,
ParseError<'i, SelectorParseError<'i, ()>>> { ParseError<'i, SelectorParseError<'i, ()>>> {
@ -1824,7 +1824,7 @@ pub mod tests {
} }
} }
fn parse_pseudo_element(&self, name: Cow<'i, str>) fn parse_pseudo_element(&self, name: CompactCowStr<'i>)
-> Result<PseudoElement, -> Result<PseudoElement,
ParseError<'i, SelectorParseError<'i, ()>>> { ParseError<'i, SelectorParseError<'i, ()>>> {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,

View file

@ -38,7 +38,7 @@ bitflags = "0.7"
bit-vec = "0.4.3" bit-vec = "0.4.3"
byteorder = "1.0" byteorder = "1.0"
cfg-if = "0.1.0" cfg-if = "0.1.0"
cssparser = "0.15" cssparser = "0.16"
encoding = {version = "0.2", optional = true} encoding = {version = "0.2", optional = true}
euclid = "0.15" euclid = "0.15"
fnv = "1.0" fnv = "1.0"

View file

@ -8,7 +8,7 @@
use Atom; use Atom;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
use cssparser::{Parser, Token, serialize_identifier, BasicParseError}; use cssparser::{Parser, Token, serialize_identifier, BasicParseError, CompactCowStr};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc; #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc;
@ -184,7 +184,7 @@ macro_rules! counter_style_descriptors {
type Declaration = (); type Declaration = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
match_ignore_ascii_case! { &*name, match_ignore_ascii_case! { &*name,
$( $(
@ -430,7 +430,7 @@ impl Parse for Ranges {
fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Option<i32>, ParseError<'i>> { fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Option<i32>, ParseError<'i>> {
match input.next() { match input.next() {
Ok(Token::Number(ref v)) if v.int_value.is_some() => Ok(Some(v.int_value.unwrap())), Ok(Token::Number { int_value: Some(v), .. }) => Ok(Some(v)),
Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("infinite") => Ok(None), Ok(Token::Ident(ref ident)) if ident.eq_ignore_ascii_case("infinite") => Ok(None),
Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()), Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()),
Err(e) => Err(e.into()), Err(e) => Err(e.into()),

View file

@ -281,7 +281,7 @@ fn parse_declaration_value_block<'i, 't>
Token::Hash(ref value) | Token::Hash(ref value) |
Token::IDHash(ref value) | Token::IDHash(ref value) |
Token::UnquotedUrl(ref value) | Token::UnquotedUrl(ref value) |
Token::Dimension(_, ref value) => { Token::Dimension { unit: ref value, .. } => {
if value.ends_with("<EFBFBD>") && input.slice_from(token_start).ends_with("\\") { if value.ends_with("<EFBFBD>") && input.slice_from(token_start).ends_with("\\") {
// Unescaped backslash at EOF in these contexts is interpreted as U+FFFD // Unescaped backslash at EOF in these contexts is interpreted as U+FFFD
// Check the value in case the final backslash was itself escaped. // Check the value in case the final backslash was itself escaped.

View file

@ -6,7 +6,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use cssparser::{Parser, SourcePosition, BasicParseError, Token, NumericValue, PercentageValue}; use cssparser::{Parser, SourcePosition, BasicParseError, Token};
use cssparser::ParseError as CssParseError; use cssparser::ParseError as CssParseError;
use log; use log;
use style_traits::ParseError; use style_traits::ParseError;
@ -54,11 +54,11 @@ impl<'a> ContextualParseError<'a> {
Token::QuotedString(ref s) => format!("quoted string \"{}\"", s), Token::QuotedString(ref s) => format!("quoted string \"{}\"", s),
Token::UnquotedUrl(ref u) => format!("url {}", u), Token::UnquotedUrl(ref u) => format!("url {}", u),
Token::Delim(ref d) => format!("delimiter {}", d), Token::Delim(ref d) => format!("delimiter {}", d),
Token::Number(NumericValue { int_value: Some(i), .. }) => format!("number {}", i), Token::Number { int_value: Some(i), .. } => format!("number {}", i),
Token::Number(ref n) => format!("number {}", n.value), Token::Number { value, .. } => format!("number {}", value),
Token::Percentage(PercentageValue { int_value: Some(i), .. }) => format!("percentage {}", i), Token::Percentage { int_value: Some(i), .. } => format!("percentage {}", i),
Token::Percentage(ref p) => format!("percentage {}", p.unit_value), Token::Percentage { unit_value, .. } => format!("percentage {}", unit_value * 100.),
Token::Dimension(_, ref d) => format!("dimension {}", d), Token::Dimension { value, ref unit, .. } => format!("dimension {}{}", value, unit),
Token::WhiteSpace(_) => format!("whitespace"), Token::WhiteSpace(_) => format!("whitespace"),
Token::Comment(_) => format!("comment"), Token::Comment(_) => format!("comment"),
Token::Colon => format!("colon (:)"), Token::Colon => format!("colon (:)"),

View file

@ -12,14 +12,13 @@
use computed_values::{font_feature_settings, font_stretch, font_style, font_weight}; use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
use computed_values::font_family::FamilyName; use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use cssparser::SourceLocation; use cssparser::{SourceLocation, CompactCowStr};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
#[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors; #[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors;
#[cfg(feature = "gecko")] use cssparser::UnicodeRange; #[cfg(feature = "gecko")] use cssparser::UnicodeRange;
use parser::{ParserContext, log_css_error, Parse}; use parser::{ParserContext, log_css_error, Parse};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::borrow::Cow;
use std::fmt; use std::fmt;
use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError}; use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError};
use values::specified::url::SpecifiedUrl; use values::specified::url::SpecifiedUrl;
@ -256,7 +255,7 @@ macro_rules! font_face_descriptors_common {
type Declaration = (); type Declaration = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
match_ignore_ascii_case! { &*name, match_ignore_ascii_case! { &*name,
$( $(

View file

@ -231,21 +231,20 @@ impl Resolution {
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let (value, unit) = match try!(input.next()) { let (value, unit) = match try!(input.next()) {
Token::Dimension(value, unit) => { Token::Dimension { value, unit, .. } => {
(value, unit) (value, unit)
}, },
t => return Err(BasicParseError::UnexpectedToken(t).into()), t => return Err(BasicParseError::UnexpectedToken(t).into()),
}; };
let inner_value = value.value; if value <= 0. {
if inner_value <= 0. {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
(match_ignore_ascii_case! { &unit, (match_ignore_ascii_case! { &unit,
"dpi" => Ok(Resolution::Dpi(inner_value)), "dpi" => Ok(Resolution::Dpi(value)),
"dppx" => Ok(Resolution::Dppx(inner_value)), "dppx" => Ok(Resolution::Dppx(value)),
"dpcm" => Ok(Resolution::Dpcm(inner_value)), "dpcm" => Ok(Resolution::Dpcm(value)),
_ => Err(()) _ => Err(())
}).map_err(|()| StyleParseError::UnexpectedDimension(unit).into()) }).map_err(|()| StyleParseError::UnexpectedDimension(unit).into())
} }

View file

@ -4,13 +4,12 @@
//! Gecko-specific bits for selector-parsing. //! Gecko-specific bits for selector-parsing.
use cssparser::{Parser, ToCss}; use cssparser::{Parser, ToCss, CompactCowStr};
use element_state::ElementState; use element_state::ElementState;
use gecko_bindings::structs::CSSPseudoClassType; use gecko_bindings::structs::CSSPseudoClassType;
use selector_parser::{SelectorParser, PseudoElementCascadeType}; use selector_parser::{SelectorParser, PseudoElementCascadeType};
use selectors::parser::{Selector, SelectorMethods, SelectorParseError}; use selectors::parser::{Selector, SelectorMethods, SelectorParseError};
use selectors::visitor::SelectorVisitor; use selectors::visitor::SelectorVisitor;
use std::borrow::Cow;
use std::fmt; use std::fmt;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
use style_traits::{ParseError, StyleParseError}; use style_traits::{ParseError, StyleParseError};
@ -249,7 +248,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
type Impl = SelectorImpl; type Impl = SelectorImpl;
type Error = StyleParseError<'i>; type Error = StyleParseError<'i>;
fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>) fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>)
-> Result<NonTSPseudoClass, ParseError<'i>> { -> Result<NonTSPseudoClass, ParseError<'i>> {
macro_rules! pseudo_class_parse { macro_rules! pseudo_class_parse {
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
@ -271,7 +270,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
} }
fn parse_non_ts_functional_pseudo_class<'t>(&self, fn parse_non_ts_functional_pseudo_class<'t>(&self,
name: Cow<'i, str>, name: CompactCowStr<'i>,
parser: &mut Parser<'i, 't>) parser: &mut Parser<'i, 't>)
-> Result<NonTSPseudoClass, ParseError<'i>> { -> Result<NonTSPseudoClass, ParseError<'i>> {
macro_rules! pseudo_class_string_parse { macro_rules! pseudo_class_string_parse {
@ -315,7 +314,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
} }
} }
fn parse_pseudo_element(&self, name: Cow<'i, str>) -> Result<PseudoElement, ParseError<'i>> { fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
.ok_or(SelectorParseError::UnexpectedIdent(name.clone()).into()) .ok_or(SelectorParseError::UnexpectedIdent(name.clone()).into())
} }

View file

@ -9,7 +9,6 @@ use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::structs::root::mozilla::css::ImageValue; use gecko_bindings::structs::root::mozilla::css::ImageValue;
use gecko_bindings::sugar::refptr::RefPtr; use gecko_bindings::sugar::refptr::RefPtr;
use parser::ParserContext; use parser::ParserContext;
use std::borrow::Cow;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use style_traits::{ToCss, ParseError}; use style_traits::{ToCss, ParseError};
use stylearc::Arc; use stylearc::Arc;
@ -36,11 +35,11 @@ impl SpecifiedUrl {
/// URL. /// URL.
/// ///
/// Returns `Err` in the case that extra_data is incomplete. /// Returns `Err` in the case that extra_data is incomplete.
pub fn parse_from_string<'a>(url: Cow<'a, str>, pub fn parse_from_string<'a>(url: String,
context: &ParserContext) context: &ParserContext)
-> Result<Self, ParseError<'a>> { -> Result<Self, ParseError<'a>> {
Ok(SpecifiedUrl { Ok(SpecifiedUrl {
serialization: Arc::new(url.into_owned()), serialization: Arc::new(url),
extra_data: context.url_data.clone(), extra_data: context.url_data.clone(),
image_value: None, image_value: None,
}) })

View file

@ -7,7 +7,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use context::QuirksMode; use context::QuirksMode;
use cssparser::{DeclarationListParser, parse_important, ParserInput}; use cssparser::{DeclarationListParser, parse_important, ParserInput, CompactCowStr};
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter}; use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
use error_reporting::{ParseErrorReporter, ContextualParseError}; use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::{ParserContext, log_css_error}; use parser::{ParserContext, log_css_error};
@ -932,7 +932,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
type Declaration = Importance; type Declaration = Importance;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Importance, ParseError<'i>> { -> Result<Importance, ParseError<'i>> {
let id = try!(PropertyId::parse(name)); let id = try!(PropertyId::parse(name));
input.parse_until_before(Delimiter::Bang, |input| { input.parse_until_before(Delimiter::Bang, |input| {

View file

@ -306,8 +306,8 @@ ${helpers.predefined_type("clip",
fn parse_factor<'i, 't>(input: &mut Parser<'i, 't>) -> Result<::values::CSSFloat, ParseError<'i>> { fn parse_factor<'i, 't>(input: &mut Parser<'i, 't>) -> Result<::values::CSSFloat, ParseError<'i>> {
use cssparser::Token; use cssparser::Token;
match input.next() { match input.next() {
Ok(Token::Number(value)) if value.value.is_sign_positive() => Ok(value.value), Ok(Token::Number { value, .. }) if value.is_sign_positive() => Ok(value),
Ok(Token::Percentage(value)) if value.unit_value.is_sign_positive() => Ok(value.unit_value), Ok(Token::Percentage { unit_value, .. }) if unit_value.is_sign_positive() => Ok(unit_value),
Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()), Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()),
Err(e) => Err(e.into()) Err(e) => Err(e.into())
} }

View file

@ -144,7 +144,7 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
<%helpers:longhand name="quotes" animation_value_type="none" <%helpers:longhand name="quotes" animation_value_type="none"
spec="https://drafts.csswg.org/css-content/#propdef-quotes"> spec="https://drafts.csswg.org/css-content/#propdef-quotes">
use std::borrow::Cow; use cssparser::serialize_string;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified; use values::computed::ComputedValueAsSpecified;
@ -169,12 +169,12 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu
let mut first = true; let mut first = true;
for pair in &self.0 { for pair in &self.0 {
if !first { if !first {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
first = false; first = false;
try!(Token::QuotedString(Cow::from(&*pair.0)).to_css(dest)); serialize_string(&*pair.0, dest)?;
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(Token::QuotedString(Cow::from(&*pair.1)).to_css(dest)); serialize_string(&*pair.1, dest)?;
} }
Ok(()) Ok(())
} }

View file

@ -20,7 +20,7 @@ use stylearc::{Arc, UniqueArc};
use app_units::Au; use app_units::Au;
#[cfg(feature = "servo")] use cssparser::RGBA; #[cfg(feature = "servo")] use cssparser::RGBA;
use cssparser::{Parser, TokenSerializationType, serialize_identifier}; use cssparser::{Parser, TokenSerializationType, serialize_identifier};
use cssparser::ParserInput; use cssparser::{ParserInput, CompactCowStr};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
#[cfg(feature = "servo")] use euclid::SideOffsets2D; #[cfg(feature = "servo")] use euclid::SideOffsets2D;
use computed_values; use computed_values;
@ -491,7 +491,7 @@ impl CSSWideKeyword {
/// Takes the result of cssparser::Parser::expect_ident() and converts it /// Takes the result of cssparser::Parser::expect_ident() and converts it
/// to a CSSWideKeyword. /// to a CSSWideKeyword.
pub fn from_ident<'i>(ident: &Cow<'i, str>) -> Option<Self> { pub fn from_ident<'i>(ident: &str) -> Option<Self> {
match_ignore_ascii_case! { ident, match_ignore_ascii_case! { ident,
// If modifying this set of keyword, also update values::CustomIdent::from_ident // If modifying this set of keyword, also update values::CustomIdent::from_ident
"initial" => Some(CSSWideKeyword::Initial), "initial" => Some(CSSWideKeyword::Initial),
@ -986,7 +986,7 @@ impl PropertyId {
/// Returns a given property from the string `s`. /// Returns a given property from the string `s`.
/// ///
/// Returns Err(()) for unknown non-custom properties /// Returns Err(()) for unknown non-custom properties
pub fn parse<'i>(property_name: Cow<'i, str>) -> Result<Self, ParseError<'i>> { pub fn parse<'i>(property_name: CompactCowStr<'i>) -> Result<Self, ParseError<'i>> {
if let Ok(name) = ::custom_properties::parse_name(&property_name) { if let Ok(name) = ::custom_properties::parse_name(&property_name) {
return Ok(PropertyId::Custom(::custom_properties::Name::from(name))) return Ok(PropertyId::Custom(::custom_properties::Name::from(name)))
} }

View file

@ -8,7 +8,7 @@
use {Atom, Prefix, Namespace, LocalName, CaseSensitivityExt}; use {Atom, Prefix, Namespace, LocalName, CaseSensitivityExt};
use attr::{AttrIdentifier, AttrValue}; use attr::{AttrIdentifier, AttrValue};
use cssparser::{Parser as CssParser, ToCss, serialize_identifier}; use cssparser::{Parser as CssParser, ToCss, serialize_identifier, CompactCowStr};
use dom::{OpaqueNode, TElement, TNode}; use dom::{OpaqueNode, TElement, TNode};
use element_state::ElementState; use element_state::ElementState;
use fnv::FnvHashMap; use fnv::FnvHashMap;
@ -311,7 +311,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
type Impl = SelectorImpl; type Impl = SelectorImpl;
type Error = StyleParseError<'i>; type Error = StyleParseError<'i>;
fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>) fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>)
-> Result<NonTSPseudoClass, ParseError<'i>> { -> Result<NonTSPseudoClass, ParseError<'i>> {
use self::NonTSPseudoClass::*; use self::NonTSPseudoClass::*;
let pseudo_class = match_ignore_ascii_case! { &name, let pseudo_class = match_ignore_ascii_case! { &name,
@ -344,7 +344,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
} }
fn parse_non_ts_functional_pseudo_class<'t>(&self, fn parse_non_ts_functional_pseudo_class<'t>(&self,
name: Cow<'i, str>, name: CompactCowStr<'i>,
parser: &mut CssParser<'i, 't>) parser: &mut CssParser<'i, 't>)
-> Result<NonTSPseudoClass, ParseError<'i>> { -> Result<NonTSPseudoClass, ParseError<'i>> {
use self::NonTSPseudoClass::*; use self::NonTSPseudoClass::*;
@ -356,7 +356,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
if !self.in_user_agent_stylesheet() { if !self.in_user_agent_stylesheet() {
return Err(SelectorParseError::UnexpectedIdent(name.clone()).into()); return Err(SelectorParseError::UnexpectedIdent(name.clone()).into());
} }
ServoCaseSensitiveTypeAttr(Atom::from(parser.expect_ident()?)) ServoCaseSensitiveTypeAttr(Atom::from(Cow::from(parser.expect_ident()?)))
} }
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into()) _ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
}; };
@ -364,7 +364,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
Ok(pseudo_class) Ok(pseudo_class)
} }
fn parse_pseudo_element(&self, name: Cow<'i, str>) -> Result<PseudoElement, ParseError<'i>> { fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
use self::PseudoElement::*; use self::PseudoElement::*;
let pseudo_element = match_ignore_ascii_case! { &name, let pseudo_element = match_ignore_ascii_case! { &name,
"before" => Before, "before" => Before,

View file

@ -7,7 +7,6 @@
use cssparser::CssStringWriter; use cssparser::CssStringWriter;
use parser::ParserContext; use parser::ParserContext;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::borrow::Cow;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
// Note: We use std::sync::Arc rather than stylearc::Arc here because the // Note: We use std::sync::Arc rather than stylearc::Arc here because the
// nonzero optimization is important in keeping the size of SpecifiedUrl below // nonzero optimization is important in keeping the size of SpecifiedUrl below
@ -41,10 +40,10 @@ impl SpecifiedUrl {
/// Try to parse a URL from a string value that is a valid CSS token for a /// Try to parse a URL from a string value that is a valid CSS token for a
/// URL. Never fails - the API is only fallible to be compatible with the /// URL. Never fails - the API is only fallible to be compatible with the
/// gecko version. /// gecko version.
pub fn parse_from_string<'a>(url: Cow<'a, str>, pub fn parse_from_string<'a>(url: String,
context: &ParserContext) context: &ParserContext)
-> Result<Self, ParseError<'a>> { -> Result<Self, ParseError<'a>> {
let serialization = Arc::new(url.into_owned()); let serialization = Arc::new(url);
let resolved = context.url_data.join(&serialization).ok(); let resolved = context.url_data.join(&serialization).ok();
Ok(SpecifiedUrl { Ok(SpecifiedUrl {
original: Some(serialization), original: Some(serialization),

View file

@ -4,7 +4,7 @@
//! Keyframes: https://drafts.csswg.org/css-animations/#keyframes //! Keyframes: https://drafts.csswg.org/css-animations/#keyframes
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput}; use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput, CompactCowStr};
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation}; use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation};
use error_reporting::{NullReporter, ContextualParseError}; use error_reporting::{NullReporter, ContextualParseError};
use parser::{ParserContext, log_css_error}; use parser::{ParserContext, log_css_error};
@ -15,7 +15,6 @@ use properties::animated_properties::AnimatableLonghand;
use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction; use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; use shared_lock::{DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard};
use std::borrow::Cow;
use std::fmt; use std::fmt;
use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseError}; use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseError};
use stylearc::Arc; use stylearc::Arc;
@ -523,7 +522,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
type Declaration = (); type Declaration = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
let id = try!(PropertyId::parse(name.into())); let id = try!(PropertyId::parse(name.into()));
match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) { match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) {

View file

@ -6,7 +6,8 @@
use {Namespace, Prefix}; use {Namespace, Prefix};
use counter_style::{parse_counter_style_body, parse_counter_style_name}; use counter_style::{parse_counter_style_body, parse_counter_style_name};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser, SourceLocation}; use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{CompactCowStr, SourceLocation};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
use font_face::parse_font_face_block; use font_face::parse_font_face_block;
use media_queries::{parse_media_query_list, MediaList}; use media_queries::{parse_media_query_list, MediaList};
@ -144,7 +145,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
fn parse_prelude<'t>( fn parse_prelude<'t>(
&mut self, &mut self,
name: Cow<'i, str>, name: CompactCowStr<'i>,
input: &mut Parser<'i, 't> input: &mut Parser<'i, 't>
) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> { ) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> {
let location = get_location_with_offset(input.current_source_location(), let location = get_location_with_offset(input.current_source_location(),
@ -158,7 +159,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
} }
self.state = State::Imports; self.state = State::Imports;
let url_string = input.expect_url_or_string()?; let url_string = input.expect_url_or_string()?.into_owned();
let specified_url = SpecifiedUrl::parse_from_string(url_string, &self.context)?; let specified_url = SpecifiedUrl::parse_from_string(url_string, &self.context)?;
let media = parse_media_query_list(&self.context, input); let media = parse_media_query_list(&self.context, input);
@ -203,7 +204,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
self.state = State::Namespaces; self.state = State::Namespaces;
let prefix_result = input.try(|input| input.expect_ident()); let prefix_result = input.try(|input| input.expect_ident());
let url = Namespace::from(try!(input.expect_url_or_string())); let url = Namespace::from(Cow::from(input.expect_url_or_string()?));
let id = register_namespace(&url) let id = register_namespace(&url)
.map_err(|()| StyleParseError::UnspecifiedError)?; .map_err(|()| StyleParseError::UnspecifiedError)?;
@ -211,7 +212,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
let mut namespaces = self.namespaces.as_mut().unwrap(); let mut namespaces = self.namespaces.as_mut().unwrap();
let opt_prefix = if let Ok(prefix) = prefix_result { let opt_prefix = if let Ok(prefix) = prefix_result {
let prefix = Prefix::from(prefix); let prefix = Prefix::from(Cow::from(prefix));
namespaces namespaces
.prefixes .prefixes
.insert(prefix.clone(), (url.clone(), id)); .insert(prefix.clone(), (url.clone(), id));
@ -337,7 +338,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
fn parse_prelude<'t>( fn parse_prelude<'t>(
&mut self, &mut self,
name: Cow<'i, str>, name: CompactCowStr<'i>,
input: &mut Parser<'i, 't> input: &mut Parser<'i, 't>
) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> { ) -> Result<AtRuleType<AtRulePrelude, CssRule>, ParseError<'i>> {
let location = let location =

View file

@ -10,7 +10,7 @@
use app_units::Au; use app_units::Au;
use context::QuirksMode; use context::QuirksMode;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
use cssparser::ToCss as ParserToCss; use cssparser::{CompactCowStr, ToCss as ParserToCss};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
use euclid::TypedSize2D; use euclid::TypedSize2D;
use font_metrics::get_metrics_provider_for_product; use font_metrics::get_metrics_provider_for_product;
@ -281,7 +281,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
type Declaration = Vec<ViewportDescriptorDeclaration>; type Declaration = Vec<ViewportDescriptorDeclaration>;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> { -> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
macro_rules! declaration { macro_rules! declaration {
($declaration:ident($parse:expr)) => { ($declaration:ident($parse:expr)) => {

View file

@ -9,7 +9,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use Atom; use Atom;
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, BasicParseError}; pub use cssparser::{RGBA, Token, Parser, serialize_identifier, BasicParseError, CompactCowStr};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
@ -93,7 +93,7 @@ pub struct CustomIdent(pub Atom);
impl CustomIdent { impl CustomIdent {
/// Parse an already-tokenizer identifier /// Parse an already-tokenizer identifier
pub fn from_ident<'i>(ident: Cow<'i, str>, excluding: &[&str]) -> Result<Self, ParseError<'i>> { pub fn from_ident<'i>(ident: CompactCowStr<'i>, excluding: &[&str]) -> Result<Self, ParseError<'i>> {
let valid = match_ignore_ascii_case! { &ident, let valid = match_ignore_ascii_case! { &ident,
"initial" | "inherit" | "unset" | "default" => false, "initial" | "inherit" | "unset" | "default" => false,
_ => true _ => true
@ -104,7 +104,7 @@ impl CustomIdent {
if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) { if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) {
Err(StyleParseError::UnspecifiedError.into()) Err(StyleParseError::UnspecifiedError.into())
} else { } else {
Ok(CustomIdent(ident.into())) Ok(CustomIdent(Atom::from(Cow::from(ident))))
} }
} }
} }
@ -128,9 +128,10 @@ pub enum KeyframesName {
impl KeyframesName { impl KeyframesName {
/// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name /// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
pub fn from_ident(value: String) -> Self { pub fn from_ident(value: String) -> Self {
match CustomIdent::from_ident((&*value).into(), &["none"]) { let custom_ident = CustomIdent::from_ident((&*value).into(), &["none"]).ok();
Ok(ident) => KeyframesName::Ident(ident), match custom_ident {
Err(_) => KeyframesName::QuotedString(value.into()), Some(ident) => KeyframesName::Ident(ident),
None => KeyframesName::QuotedString(value.into()),
} }
} }
@ -161,7 +162,7 @@ impl Parse for KeyframesName {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
match input.next() { match input.next() {
Ok(Token::Ident(s)) => Ok(KeyframesName::Ident(CustomIdent::from_ident(s, &["none"])?)), Ok(Token::Ident(s)) => Ok(KeyframesName::Ident(CustomIdent::from_ident(s, &["none"])?)),
Ok(Token::QuotedString(s)) => Ok(KeyframesName::QuotedString(s.into())), Ok(Token::QuotedString(s)) => Ok(KeyframesName::QuotedString(Atom::from(Cow::from(s)))),
Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()), Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()),
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
} }

View file

@ -150,29 +150,25 @@ impl CalcNode {
-> Result<Self, ParseError<'i>> -> Result<Self, ParseError<'i>>
{ {
match (try!(input.next()), expected_unit) { match (try!(input.next()), expected_unit) {
(Token::Number(ref value), _) => Ok(CalcNode::Number(value.value)), (Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)),
(Token::Dimension(ref value, ref unit), CalcUnit::Length) | (Token::Dimension { value, ref unit, .. }, CalcUnit::Length) |
(Token::Dimension(ref value, ref unit), CalcUnit::LengthOrPercentage) => { (Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => {
NoCalcLength::parse_dimension(context, value.value, unit) NoCalcLength::parse_dimension(context, value, unit)
.map(CalcNode::Length) .map(CalcNode::Length)
.map_err(|()| StyleParseError::UnspecifiedError.into()) .map_err(|()| StyleParseError::UnspecifiedError.into())
} }
(Token::Dimension(ref value, ref unit), CalcUnit::Angle) => { (Token::Dimension { value, ref unit, .. }, CalcUnit::Angle) => {
Angle::parse_dimension(value.value, Angle::parse_dimension(value, unit, /* from_calc = */ true)
unit,
/* from_calc = */ true)
.map(CalcNode::Angle) .map(CalcNode::Angle)
.map_err(|()| StyleParseError::UnspecifiedError.into()) .map_err(|()| StyleParseError::UnspecifiedError.into())
} }
(Token::Dimension(ref value, ref unit), CalcUnit::Time) => { (Token::Dimension { value, ref unit, .. }, CalcUnit::Time) => {
Time::parse_dimension(value.value, Time::parse_dimension(value, unit, /* from_calc = */ true)
unit,
/* from_calc = */ true)
.map(CalcNode::Time) .map(CalcNode::Time)
.map_err(|()| StyleParseError::UnspecifiedError.into()) .map_err(|()| StyleParseError::UnspecifiedError.into())
} }
(Token::Percentage(ref value), CalcUnit::LengthOrPercentage) => { (Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) => {
Ok(CalcNode::Percentage(value.unit_value)) Ok(CalcNode::Percentage(unit_value))
} }
(Token::ParenthesisBlock, _) => { (Token::ParenthesisBlock, _) => {
input.parse_nested_block(|i| { input.parse_nested_block(|i| {

View file

@ -173,12 +173,12 @@ impl Color {
/// ///
/// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk /// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
fn parse_quirky_color<'i, 't>(input: &mut Parser<'i, 't>) -> Result<RGBA, ParseError<'i>> { fn parse_quirky_color<'i, 't>(input: &mut Parser<'i, 't>) -> Result<RGBA, ParseError<'i>> {
let (number, dimension) = match input.next()? { let (value, unit) = match input.next()? {
Token::Number(number) => { Token::Number { int_value: Some(integer), .. } => {
(number, None) (integer, None)
}, },
Token::Dimension(number, dimension) => { Token::Dimension { int_value: Some(integer), unit, .. } => {
(number, Some(dimension)) (integer, Some(unit))
}, },
Token::Ident(ident) => { Token::Ident(ident) => {
if ident.len() != 3 && ident.len() != 6 { if ident.len() != 3 && ident.len() != 6 {
@ -191,7 +191,6 @@ impl Color {
return Err(BasicParseError::UnexpectedToken(t).into()); return Err(BasicParseError::UnexpectedToken(t).into());
}, },
}; };
let value = number.int_value.ok_or(StyleParseError::UnspecifiedError)?;
if value < 0 { if value < 0 {
return Err(StyleParseError::UnspecifiedError.into()); return Err(StyleParseError::UnspecifiedError.into());
} }
@ -210,7 +209,7 @@ impl Color {
} else { } else {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
}; };
let total = length + dimension.as_ref().map_or(0, |d| d.len()); let total = length + unit.as_ref().map_or(0, |d| d.len());
if total > 6 { if total > 6 {
return Err(StyleParseError::UnspecifiedError.into()); return Err(StyleParseError::UnspecifiedError.into());
} }
@ -218,8 +217,8 @@ impl Color {
let space_padding = 6 - total; let space_padding = 6 - total;
let mut written = space_padding; let mut written = space_padding;
written += itoa::write(&mut serialization[written..], value).unwrap(); written += itoa::write(&mut serialization[written..], value).unwrap();
if let Some(dimension) = dimension { if let Some(unit) = unit {
written += (&mut serialization[written..]).write(dimension.as_bytes()).unwrap(); written += (&mut serialization[written..]).write(unit.as_bytes()).unwrap();
} }
debug_assert!(written == 6); debug_assert!(written == 6);
parse_hash_color(&serialization).map_err(|()| StyleParseError::UnspecifiedError.into()) parse_hash_color(&serialization).map_err(|()| StyleParseError::UnspecifiedError.into())

View file

@ -19,8 +19,8 @@ use values::specified::LengthOrPercentage;
/// Parse a single flexible length. /// Parse a single flexible length.
pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseError<'i>> { pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseError<'i>> {
match input.next()? { match input.next()? {
Token::Dimension(ref value, ref unit) if unit.eq_ignore_ascii_case("fr") && value.value.is_sign_positive() Token::Dimension { value, ref unit, .. } if unit.eq_ignore_ascii_case("fr") && value.is_sign_positive()
=> Ok(value.value), => Ok(value),
t => Err(BasicParseError::UnexpectedToken(t).into()), t => Err(BasicParseError::UnexpectedToken(t).into()),
} }
} }

View file

@ -13,6 +13,7 @@ use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::borrow::Cow;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::f32::consts::PI; use std::f32::consts::PI;
use std::fmt; use std::fmt;
@ -137,7 +138,7 @@ impl Image {
input.try(|i| i.expect_function_matching("-moz-element"))?; input.try(|i| i.expect_function_matching("-moz-element"))?;
input.parse_nested_block(|i| { input.parse_nested_block(|i| {
match i.next()? { match i.next()? {
Token::IDHash(id) => Ok(Atom::from(id)), Token::IDHash(id) => Ok(Atom::from(Cow::from(id))),
t => Err(BasicParseError::UnexpectedToken(t).into()), t => Err(BasicParseError::UnexpectedToken(t).into()),
} }
}) })
@ -699,7 +700,7 @@ impl Parse for PaintWorklet {
input.parse_nested_block(|i| { input.parse_nested_block(|i| {
let name = i.expect_ident()?; let name = i.expect_ident()?;
Ok(PaintWorklet { Ok(PaintWorklet {
name: Atom::from(name), name: Atom::from(Cow::from(name)),
}) })
}) })
} }
@ -710,7 +711,7 @@ impl Parse for ImageRect {
input.try(|i| i.expect_function_matching("-moz-image-rect"))?; input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
input.parse_nested_block(|i| { input.parse_nested_block(|i| {
let string = i.expect_url_or_string()?; let string = i.expect_url_or_string()?;
let url = SpecifiedUrl::parse_from_string(string, context)?; let url = SpecifiedUrl::parse_from_string(string.into_owned(), context)?;
i.expect_comma()?; i.expect_comma()?;
let top = NumberOrPercentage::parse_non_negative(context, i)?; let top = NumberOrPercentage::parse_non_negative(context, i)?;
i.expect_comma()?; i.expect_comma()?;

View file

@ -611,20 +611,22 @@ impl Length {
-> Result<Length, ParseError<'i>> { -> Result<Length, ParseError<'i>> {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
Length::parse_dimension(context, value.value, unit), Length::parse_dimension(context, value, unit)
Token::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { }
if value.value != 0. && Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() && !context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) { !allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value.value)))) Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value))))
}, },
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
return input.parse_nested_block(|input| { return input.parse_nested_block(|input| {
CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc))) CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc)))
}), })
}
_ => Err(()) _ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token).into()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into())
} }
@ -720,8 +722,8 @@ impl Percentage {
num_context: AllowedNumericType) num_context: AllowedNumericType)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
match try!(input.next()) { match try!(input.next()) {
Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => { Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Ok(Percentage(value.unit_value)) Ok(Percentage(unit_value))
} }
t => Err(BasicParseError::UnexpectedToken(t).into()) t => Err(BasicParseError::UnexpectedToken(t).into())
} }
@ -804,17 +806,19 @@ impl LengthOrPercentage {
{ {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentage::Length), NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentage::Length)
Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => }
return Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))), Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Token::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { return Ok(LengthOrPercentage::Percentage(Percentage(unit_value)))
if value.value != 0. && }
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() && !context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) { !allow_quirks.allowed(context.quirks_mode) {
Err(()) Err(())
} else { } else {
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value.value))) return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)))
} }
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
@ -822,7 +826,7 @@ impl LengthOrPercentage {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); }));
return Ok(LengthOrPercentage::Calc(Box::new(calc))) return Ok(LengthOrPercentage::Calc(Box::new(calc)))
}, }
_ => Err(()) _ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token).into()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into())
} }
@ -938,28 +942,31 @@ impl LengthOrPercentageOrAuto {
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrAuto::Length), NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrAuto::Length)
Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => }
Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))), Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Token::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { Ok(LengthOrPercentageOrAuto::Percentage(Percentage(unit_value)))
if value.value != 0. && }
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() && !context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) { !allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
Ok(LengthOrPercentageOrAuto::Length( Ok(LengthOrPercentageOrAuto::Length(
NoCalcLength::Absolute(AbsoluteLength::Px(value.value)) NoCalcLength::Absolute(AbsoluteLength::Px(value))
)) ))
} }
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
Ok(LengthOrPercentageOrAuto::Auto), Ok(LengthOrPercentageOrAuto::Auto)
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = try!(input.parse_nested_block(|i| {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); }));
Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc))) Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc)))
}, }
_ => Err(()) _ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token).into()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into())
} }
@ -1034,17 +1041,19 @@ impl LengthOrPercentageOrNone {
{ {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value.value, unit).map(LengthOrPercentageOrNone::Length), NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrNone::Length)
Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => }
Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))), Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Token::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { Ok(LengthOrPercentageOrNone::Percentage(Percentage(unit_value)))
if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && }
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) { !allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
Ok(LengthOrPercentageOrNone::Length( Ok(LengthOrPercentageOrNone::Length(
NoCalcLength::Absolute(AbsoluteLength::Px(value.value)) NoCalcLength::Absolute(AbsoluteLength::Px(value))
)) ))
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
@ -1052,7 +1061,7 @@ impl LengthOrPercentageOrNone {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); }));
Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) Ok(LengthOrPercentageOrNone::Calc(Box::new(calc)))
}, }
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => Token::Ident(ref value) if value.eq_ignore_ascii_case("none") =>
Ok(LengthOrPercentageOrNone::None), Ok(LengthOrPercentageOrNone::None),
_ => Err(()) _ => Err(())
@ -1116,23 +1125,28 @@ impl LengthOrPercentageOrAutoOrContent {
let num_context = AllowedLengthType::NonNegative; let num_context = AllowedLengthType::NonNegative;
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value.value, unit) NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentageOrAutoOrContent::Length), .map(LengthOrPercentageOrAutoOrContent::Length)
Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => }
Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(value.unit_value))), Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Token::Number(ref value) if value.value == 0. => Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(unit_value)))
Ok(Self::zero()), }
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Token::Number { value, .. } if value == 0. => {
Ok(LengthOrPercentageOrAutoOrContent::Auto), Ok(Self::zero())
Token::Ident(ref value) if value.eq_ignore_ascii_case("content") => }
Ok(LengthOrPercentageOrAutoOrContent::Content), Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
Ok(LengthOrPercentageOrAutoOrContent::Auto)
}
Token::Ident(ref value) if value.eq_ignore_ascii_case("content") => {
Ok(LengthOrPercentageOrAutoOrContent::Content)
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = try!(input.parse_nested_block(|i| {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); }));
Ok(LengthOrPercentageOrAutoOrContent::Calc(Box::new(calc))) Ok(LengthOrPercentageOrAutoOrContent::Calc(Box::new(calc)))
}, }
_ => Err(()) _ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token).into()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into())
} }

View file

@ -13,6 +13,7 @@ use parser::{ParserContext, Parse};
use self::grid::TrackSizeOrRepeat; use self::grid::TrackSizeOrRepeat;
use self::url::SpecifiedUrl; use self::url::SpecifiedUrl;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::Cow;
use std::f32; use std::f32;
use std::fmt; use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError}; use style_traits::{ToCss, ParseError, StyleParseError};
@ -79,7 +80,7 @@ pub use ::gecko::url::*;
impl Parse for SpecifiedUrl { impl Parse for SpecifiedUrl {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let url = try!(input.expect_url()); let url = try!(input.expect_url());
Self::parse_from_string(url, context) Self::parse_from_string(url.into_owned(), context)
} }
} }
@ -95,7 +96,7 @@ no_viewport_percentage!(SpecifiedUrl);
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Integer, ParseError<'i>> { -> Result<Integer, ParseError<'i>> {
match try!(input.next()) { match try!(input.next()) {
Token::Number(ref value) => value.int_value.ok_or(StyleParseError::UnspecifiedError.into()).map(Integer::new), Token::Number { int_value: Some(v), .. } => Ok(Integer::new(v)),
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let result = try!(input.parse_nested_block(|i| { let result = try!(input.parse_nested_block(|i| {
CalcNode::parse_integer(context, i) CalcNode::parse_integer(context, i)
@ -120,9 +121,9 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
clamping_mode: AllowedNumericType) clamping_mode: AllowedNumericType)
-> Result<Number, ParseError<'i>> { -> Result<Number, ParseError<'i>> {
match try!(input.next()) { match try!(input.next()) {
Token::Number(ref value) if clamping_mode.is_ok(context.parsing_mode, value.value) => { Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
Ok(Number { Ok(Number {
value: value.value.min(f32::MAX).max(f32::MIN), value: value.min(f32::MAX).max(f32::MIN),
calc_clamping_mode: None, calc_clamping_mode: None,
}) })
}, },
@ -226,10 +227,8 @@ impl Parse for Angle {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) => { Token::Dimension { value, ref unit, .. } => {
Angle::parse_dimension(value.value, Angle::parse_dimension(value, unit, /* from_calc = */ false)
unit,
/* from_calc = */ false)
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i)) return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
@ -268,12 +267,10 @@ impl Angle {
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = try!(input.next());
match token { match token {
Token::Dimension(ref value, ref unit) => { Token::Dimension { value, ref unit, .. } => {
Angle::parse_dimension(value.value, Angle::parse_dimension(value, unit, /* from_calc = */ false)
unit,
/* from_calc = */ false)
} }
Token::Number(ref value) if value.value == 0. => Ok(Angle::zero()), Token::Number { value, .. } if value == 0. => Ok(Angle::zero()),
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i)) return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
} }
@ -372,8 +369,8 @@ impl Time {
// values for SMIL regardless of clamping_mode, but in this Time // values for SMIL regardless of clamping_mode, but in this Time
// value case, the value does not animate for SMIL at all, so we use // value case, the value does not animate for SMIL at all, so we use
// PARSING_MODE_DEFAULT directly. // PARSING_MODE_DEFAULT directly.
Ok(Token::Dimension(ref value, ref unit)) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value.value) => { Ok(Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => {
Time::parse_dimension(value.value, &unit, /* from_calc = */ false) Time::parse_dimension(value, unit, /* from_calc = */ false)
.map_err(|()| StyleParseError::UnspecifiedError.into()) .map_err(|()| StyleParseError::UnspecifiedError.into())
} }
Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => { Ok(Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {
@ -1106,7 +1103,7 @@ impl Attr {
}; };
let ns_with_id = if let Some(ns) = first { let ns_with_id = if let Some(ns) = first {
let ns: Namespace = ns.into(); let ns = Namespace::from(Cow::from(ns));
let id: Result<_, ParseError> = let id: Result<_, ParseError> =
get_id_for_namespace(&ns, context) get_id_for_namespace(&ns, context)
.map_err(|()| StyleParseError::UnspecifiedError.into()); .map_err(|()| StyleParseError::UnspecifiedError.into());

View file

@ -16,7 +16,7 @@ gecko = []
[dependencies] [dependencies]
app_units = "0.5" app_units = "0.5"
bitflags = "0.7" bitflags = "0.7"
cssparser = "0.15" cssparser = "0.16"
euclid = "0.15" euclid = "0.15"
heapsize = {version = "0.4", optional = true} heapsize = {version = "0.4", optional = true}
heapsize_derive = {version = "0.1", optional = true} heapsize_derive = {version = "0.1", optional = true}

View file

@ -22,8 +22,8 @@ extern crate euclid;
extern crate selectors; extern crate selectors;
#[cfg(feature = "servo")] #[macro_use] extern crate serde; #[cfg(feature = "servo")] #[macro_use] extern crate serde;
use cssparser::CompactCowStr;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use std::borrow::Cow;
/// Opaque type stored in type-unsafe work queues for parallel layout. /// Opaque type stored in type-unsafe work queues for parallel layout.
/// Must be transmutable to and from `TNode`. /// Must be transmutable to and from `TNode`.
@ -95,11 +95,11 @@ pub enum StyleParseError<'i> {
/// A property declaration value had input remaining after successfully parsing. /// A property declaration value had input remaining after successfully parsing.
PropertyDeclarationValueNotExhausted, PropertyDeclarationValueNotExhausted,
/// An unexpected dimension token was encountered. /// An unexpected dimension token was encountered.
UnexpectedDimension(Cow<'i, str>), UnexpectedDimension(CompactCowStr<'i>),
/// A media query using a ranged expression with no value was encountered. /// A media query using a ranged expression with no value was encountered.
RangedExpressionWithNoValue, RangedExpressionWithNoValue,
/// A function was encountered that was not expected. /// A function was encountered that was not expected.
UnexpectedFunction(Cow<'i, str>), UnexpectedFunction(CompactCowStr<'i>),
/// @namespace must be before any rule but @charset and @import /// @namespace must be before any rule but @charset and @import
UnexpectedNamespaceRule, UnexpectedNamespaceRule,
/// @import must be before any rule but @charset /// @import must be before any rule but @charset
@ -107,7 +107,7 @@ pub enum StyleParseError<'i> {
/// Unexpected @charset rule encountered. /// Unexpected @charset rule encountered.
UnexpectedCharsetRule, UnexpectedCharsetRule,
/// Unsupported @ rule /// Unsupported @ rule
UnsupportedAtRule(Cow<'i, str>), UnsupportedAtRule(CompactCowStr<'i>),
/// A placeholder for many sources of errors that require more specific variants. /// A placeholder for many sources of errors that require more specific variants.
UnspecifiedError, UnspecifiedError,
} }

View file

@ -149,12 +149,15 @@ impl Zoom {
// argument, and pass ParsingMode owned by the ParserContext to // argument, and pass ParsingMode owned by the ParserContext to
// is_ok() instead of using PARSING_MODE_DEFAULT directly. // is_ok() instead of using PARSING_MODE_DEFAULT directly.
// In order to do so, we might want to move these stuff into style::stylesheets::viewport_rule. // In order to do so, we might want to move these stuff into style::stylesheets::viewport_rule.
Token::Percentage(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.unit_value) => Token::Percentage { unit_value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, unit_value) => {
Ok(Zoom::Percentage(value.unit_value)), Ok(Zoom::Percentage(unit_value))
Token::Number(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.value) => }
Ok(Zoom::Number(value.value)), Token::Number { value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, value) => {
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(Zoom::Number(value))
Ok(Zoom::Auto), }
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
Ok(Zoom::Auto)
}
t => Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t))) t => Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t)))
} }
} }

View file

@ -16,7 +16,7 @@ gecko_debug = ["style/gecko_debug"]
[dependencies] [dependencies]
atomic_refcell = "0.1" atomic_refcell = "0.1"
cssparser = "0.15" cssparser = "0.16"
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
libc = "0.2" libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]} log = {version = "0.3.5", features = ["release_max_level_info"]}

View file

@ -7,7 +7,6 @@ use cssparser::{Parser, ParserInput};
use cssparser::ToCss as ParserToCss; use cssparser::ToCss as ParserToCss;
use env_logger::LogBuilder; use env_logger::LogBuilder;
use selectors::Element; use selectors::Element;
use std::borrow::Cow;
use std::env; use std::env;
use std::fmt::Write; use std::fmt::Write;
use std::ptr; use std::ptr;
@ -1652,7 +1651,9 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let easing = unsafe { (*easing).to_string() }; let easing = unsafe { (*easing).to_string() };
let mut input = ParserInput::new(&easing); let mut input = ParserInput::new(&easing);
match transition_timing_function::single_value::parse(&context, &mut Parser::new(&mut input)) { let mut parser = Parser::new(&mut input);
let result = transition_timing_function::single_value::parse(&context, &mut parser);
match result {
Ok(parsed_easing) => { Ok(parsed_easing) => {
*output = parsed_easing.into(); *output = parsed_easing.into();
true true
@ -1826,7 +1827,7 @@ pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDe
macro_rules! get_property_id_from_property { macro_rules! get_property_id_from_property {
($property: ident, $ret: expr) => {{ ($property: ident, $ret: expr) => {{
let property = unsafe { $property.as_ref().unwrap().as_str_unchecked() }; let property = unsafe { $property.as_ref().unwrap().as_str_unchecked() };
match PropertyId::parse(Cow::Borrowed(property)) { match PropertyId::parse(property.into()) {
Ok(property_id) => property_id, Ok(property_id) => property_id,
Err(_) => { return $ret; } Err(_) => { return $ret; }
} }
@ -2351,7 +2352,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations:
let string = unsafe { (*value).to_string() }; let string = unsafe { (*value).to_string() };
let mut input = ParserInput::new(&string); let mut input = ParserInput::new(&string);
let mut parser = Parser::new(&mut input); let mut parser = Parser::new(&mut input);
if let Ok(family) = FontFamily::parse(&mut parser) { let result = FontFamily::parse(&mut parser);
if let Ok(family) = result {
if parser.is_exhausted() { if parser.is_exhausted() {
let decl = PropertyDeclaration::FontFamily(Box::new(family)); let decl = PropertyDeclaration::FontFamily(Box::new(family));
write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {

View file

@ -10,7 +10,7 @@ path = "lib.rs"
doctest = false doctest = false
[dependencies] [dependencies]
cssparser = "0.15" cssparser = "0.16"
gfx = {path = "../../../components/gfx"} gfx = {path = "../../../components/gfx"}
ipc-channel = "0.8" ipc-channel = "0.8"
style = {path = "../../../components/style"} style = {path = "../../../components/style"}

View file

@ -15,7 +15,7 @@ testing = ["style/testing"]
[dependencies] [dependencies]
byteorder = "1.0" byteorder = "1.0"
app_units = "0.5" app_units = "0.5"
cssparser = "0.15" cssparser = "0.16"
euclid = "0.15" euclid = "0.15"
html5ever = "0.18" html5ever = "0.18"
parking_lot = "0.3" parking_lot = "0.3"

View file

@ -87,13 +87,14 @@ macro_rules! assert_roundtrip_with_context {
}, &mut input).unwrap(); }, &mut input).unwrap();
let mut input = ::cssparser::ParserInput::new(&serialized); let mut input = ::cssparser::ParserInput::new(&serialized);
super::parse_input(|context, i| { let unwrapped = super::parse_input(|context, i| {
let re_parsed = $fun(context, i) let re_parsed = $fun(context, i)
.expect(&format!("Failed to parse serialization {}", $input)); .expect(&format!("Failed to parse serialization {}", $input));
let re_serialized = ToCss::to_css_string(&re_parsed); let re_serialized = ToCss::to_css_string(&re_parsed);
assert_eq!(serialized, re_serialized); assert_eq!(serialized, re_serialized);
Ok(()) Ok(())
}, &mut input).unwrap() }, &mut input).unwrap();
unwrapped
}} }}
} }

View file

@ -40,13 +40,14 @@ macro_rules! assert_roundtrip_with_context {
}, $input).unwrap(); }, $input).unwrap();
let mut input = ::cssparser::ParserInput::new(&serialized); let mut input = ::cssparser::ParserInput::new(&serialized);
parse_input(|context, i| { let unwrapped = parse_input(|context, i| {
let re_parsed = $fun(context, i) let re_parsed = $fun(context, i)
.expect(&format!("Failed to parse serialization {}", $input)); .expect(&format!("Failed to parse serialization {}", $input));
let re_serialized = ToCss::to_css_string(&re_parsed); let re_serialized = ToCss::to_css_string(&re_parsed);
assert_eq!(serialized, re_serialized); assert_eq!(serialized, re_serialized);
Ok(()) Ok(())
}, &mut input).unwrap() }, &mut input).unwrap();
unwrapped
}} }}
} }

View file

@ -16,7 +16,7 @@ testing = ["style/testing"]
[dependencies] [dependencies]
atomic_refcell = "0.1" atomic_refcell = "0.1"
cssparser = "0.15" cssparser = "0.16"
env_logger = "0.4" env_logger = "0.4"
euclid = "0.15" euclid = "0.15"
geckoservo = {path = "../../../ports/geckolib"} geckoservo = {path = "../../../ports/geckolib"}