diff --git a/servo/Cargo.lock b/servo/Cargo.lock index ad3a4b6be035..6934a50ac52b 100644 --- a/servo/Cargo.lock +++ b/servo/Cargo.lock @@ -312,7 +312,7 @@ version = "0.0.1" dependencies = [ "azure 0.19.0 (git+https://github.com/servo/rust-azure)", "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)", "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)", @@ -327,7 +327,7 @@ dependencies = [ name = "canvas_traits" version = "0.0.1" 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)", "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)", @@ -572,7 +572,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cssparser-macros 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -999,7 +999,7 @@ name = "geckoservo" version = "0.0.1" dependencies = [ "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)", "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)", @@ -1065,7 +1065,7 @@ dependencies = [ name = "gfx_tests" version = "0.0.1" 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", "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", @@ -2361,7 +2361,7 @@ dependencies = [ "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)", "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", "devtools_traits 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)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "gfx_traits 0.0.1", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2505,7 +2505,7 @@ name = "selectors" version = "0.19.0" dependencies = [ "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)", "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)", @@ -2897,7 +2897,7 @@ dependencies = [ "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)", "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)", "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)", @@ -2950,7 +2950,7 @@ version = "0.0.1" dependencies = [ "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)", - "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)", "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)", @@ -2971,7 +2971,7 @@ version = "0.0.1" dependencies = [ "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)", - "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)", "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)", @@ -2984,7 +2984,7 @@ name = "stylo_tests" version = "0.0.1" dependencies = [ "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)", "euclid 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "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-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 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 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" diff --git a/servo/components/canvas/Cargo.toml b/servo/components/canvas/Cargo.toml index d14b88c20442..5fb7776fefc9 100644 --- a/servo/components/canvas/Cargo.toml +++ b/servo/components/canvas/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" [dependencies] azure = {git = "https://github.com/servo/rust-azure"} canvas_traits = {path = "../canvas_traits"} -cssparser = "0.15" +cssparser = "0.16" euclid = "0.15" gleam = "0.4" ipc-channel = "0.8" diff --git a/servo/components/canvas_traits/Cargo.toml b/servo/components/canvas_traits/Cargo.toml index a6d9f792955e..94465e168099 100644 --- a/servo/components/canvas_traits/Cargo.toml +++ b/servo/components/canvas_traits/Cargo.toml @@ -10,7 +10,7 @@ name = "canvas_traits" path = "lib.rs" [dependencies] -cssparser = "0.15" +cssparser = "0.16" euclid = "0.15" heapsize = "0.4" heapsize_derive = "0.1" diff --git a/servo/components/script/Cargo.toml b/servo/components/script/Cargo.toml index 31d876318f7b..b9d8a0b1304a 100644 --- a/servo/components/script/Cargo.toml +++ b/servo/components/script/Cargo.toml @@ -35,7 +35,7 @@ byteorder = "1.0" canvas_traits = {path = "../canvas_traits"} caseless = "0.1.0" cookie = "0.6" -cssparser = "0.15" +cssparser = "0.16" deny_public_fields = {path = "../deny_public_fields"} devtools_traits = {path = "../devtools_traits"} dom_struct = {path = "../dom_struct"} diff --git a/servo/components/script/dom/bindings/str.rs b/servo/components/script/dom/bindings/str.rs index 4e579044491b..33f4f1bc57f4 100644 --- a/servo/components/script/dom/bindings/str.rs +++ b/servo/components/script/dom/bindings/str.rs @@ -4,6 +4,7 @@ //! The `ByteString` struct. +use cssparser::CompactCowStr; use html5ever::{LocalName, Namespace}; use servo_atoms::Atom; use std::ascii::AsciiExt; @@ -298,6 +299,12 @@ impl<'a> Into> for DOMString { } } +impl<'a> Into> for DOMString { + fn into(self) -> CompactCowStr<'a> { + self.0.into() + } +} + impl Extend for DOMString { fn extend(&mut self, iterable: I) where I: IntoIterator { self.0.extend(iterable) diff --git a/servo/components/script_layout_interface/Cargo.toml b/servo/components/script_layout_interface/Cargo.toml index b14e9395b21e..fa861a91e6b9 100644 --- a/servo/components/script_layout_interface/Cargo.toml +++ b/servo/components/script_layout_interface/Cargo.toml @@ -13,7 +13,7 @@ path = "lib.rs" app_units = "0.5" atomic_refcell = "0.1" canvas_traits = {path = "../canvas_traits"} -cssparser = "0.15" +cssparser = "0.16" euclid = "0.15" gfx_traits = {path = "../gfx_traits"} heapsize = "0.4" diff --git a/servo/components/selectors/Cargo.toml b/servo/components/selectors/Cargo.toml index 291ff4649bcf..3894e3e21ad0 100644 --- a/servo/components/selectors/Cargo.toml +++ b/servo/components/selectors/Cargo.toml @@ -24,7 +24,7 @@ gecko_like_types = [] [dependencies] bitflags = "0.7" matches = "0.1" -cssparser = "0.15" +cssparser = "0.16" log = "0.3" fnv = "1.0" phf = "0.7.18" diff --git a/servo/components/selectors/parser.rs b/servo/components/selectors/parser.rs index 0899858bd7d9..783ba0cafbc1 100644 --- a/servo/components/selectors/parser.rs +++ b/servo/components/selectors/parser.rs @@ -5,7 +5,7 @@ use attr::{AttrSelectorWithNamespace, ParsedAttrSelectorOperation, AttrSelectorOperator}; use attr::{ParsedCaseSensitivity, SELECTOR_WHITESPACE, NamespaceConstraint}; 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 precomputed_hash::PrecomputedHash; use servo_arc::{Arc, HeaderWithLength, ThinArc}; @@ -58,7 +58,7 @@ pub enum SelectorParseError<'i, T> { PseudoElementExpectedColon, PseudoElementExpectedIdent, UnsupportedPseudoClass, - UnexpectedIdent(Cow<'i, str>), + UnexpectedIdent(CompactCowStr<'i>), ExpectedNamespace, Custom(T), } @@ -133,21 +133,21 @@ pub trait Parser<'i> { /// This function can return an "Err" pseudo-element in order to support CSS2.1 /// pseudo-elements. - 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, SelectorParseError<'i, Self::Error>>> { Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name))) } 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<::NonTSPseudoClass, ParseError<'i, SelectorParseError<'i, Self::Error>>> { Err(ParseError::Custom(SelectorParseError::UnexpectedIdent(name))) } - fn parse_pseudo_element(&self, name: Cow<'i, str>) + fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result<::PseudoElement, ParseError<'i, SelectorParseError<'i, Self::Error>>> { 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) => { sequence.push(Component::LocalName(LocalName { lower_name: from_cow_str(to_ascii_lowercase(&name)), - name: from_cow_str(name), + name: from_cow_str(name.into()), })) } None => { @@ -1186,7 +1186,7 @@ enum QNamePrefix { fn parse_qualified_name<'i, 't, P, E, Impl> (parser: &P, input: &mut CssParser<'i, 't>, in_attr_selector: bool) - -> Result, Option>)>, + -> Result, Option>)>, ParseError<'i, SelectorParseError<'i, E>>> 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(); match input.next_including_whitespace() { Ok(Token::Delim('|')) => { - let prefix = from_cow_str(value); + let prefix = from_cow_str(value.into()); let result = parser.namespace_for_prefix(&prefix); let url = result.ok_or(ParseError::Custom(SelectorParseError::ExpectedNamespace))?; 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] Err(_) => { 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 { return Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace { 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 value = from_cow_str(value); + let value = from_cow_str(value.into()); let local_name_lower; { 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 } } - 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 { Ok(Component::AttributeOther(Box::new(AttrSelectorWithNamespace { 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, input: &mut CssParser<'i, 't>, - name: Cow<'i, str>, + name: CompactCowStr<'i>, inside_negation: bool) -> Result, 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(); match input.next_including_whitespace() { 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(Token::Delim('.')) => { match input.next_including_whitespace() { 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(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, ParseError<'i, SelectorParseError<'i, E>>> where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl @@ -1804,7 +1804,7 @@ pub mod tests { type Impl = DummySelectorImpl; type Error = (); - fn parse_non_ts_pseudo_class(&self, name: Cow<'i, str>) + fn parse_non_ts_pseudo_class(&self, name: CompactCowStr<'i>) -> Result>> { 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>) -> Result>> { @@ -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>> { match_ignore_ascii_case! { &name, diff --git a/servo/components/style/Cargo.toml b/servo/components/style/Cargo.toml index f0f7b28deed4..edaf5d6ea3ad 100644 --- a/servo/components/style/Cargo.toml +++ b/servo/components/style/Cargo.toml @@ -38,7 +38,7 @@ bitflags = "0.7" bit-vec = "0.4.3" byteorder = "1.0" cfg-if = "0.1.0" -cssparser = "0.15" +cssparser = "0.16" encoding = {version = "0.2", optional = true} euclid = "0.15" fnv = "1.0" diff --git a/servo/components/style/counter_style/mod.rs b/servo/components/style/counter_style/mod.rs index 27d0c02950b6..c189429fb909 100644 --- a/servo/components/style/counter_style/mod.rs +++ b/servo/components/style/counter_style/mod.rs @@ -8,7 +8,7 @@ use Atom; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; -use cssparser::{Parser, Token, serialize_identifier, BasicParseError}; +use cssparser::{Parser, Token, serialize_identifier, BasicParseError, CompactCowStr}; use error_reporting::ContextualParseError; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc; @@ -184,7 +184,7 @@ macro_rules! counter_style_descriptors { type Declaration = (); 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>> { match_ignore_ascii_case! { &*name, $( @@ -430,7 +430,7 @@ impl Parse for Ranges { fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result, ParseError<'i>> { 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(t) => Err(BasicParseError::UnexpectedToken(t).into()), Err(e) => Err(e.into()), diff --git a/servo/components/style/custom_properties.rs b/servo/components/style/custom_properties.rs index 810382acd647..f0528e24fc60 100644 --- a/servo/components/style/custom_properties.rs +++ b/servo/components/style/custom_properties.rs @@ -281,7 +281,7 @@ fn parse_declaration_value_block<'i, 't> Token::Hash(ref value) | Token::IDHash(ref value) | Token::UnquotedUrl(ref value) | - Token::Dimension(_, ref value) => { + Token::Dimension { unit: ref value, .. } => { if value.ends_with("�") && input.slice_from(token_start).ends_with("\\") { // Unescaped backslash at EOF in these contexts is interpreted as U+FFFD // Check the value in case the final backslash was itself escaped. diff --git a/servo/components/style/error_reporting.rs b/servo/components/style/error_reporting.rs index d995bec0ba63..e2a28ea0f914 100644 --- a/servo/components/style/error_reporting.rs +++ b/servo/components/style/error_reporting.rs @@ -6,7 +6,7 @@ #![deny(missing_docs)] -use cssparser::{Parser, SourcePosition, BasicParseError, Token, NumericValue, PercentageValue}; +use cssparser::{Parser, SourcePosition, BasicParseError, Token}; use cssparser::ParseError as CssParseError; use log; use style_traits::ParseError; @@ -54,11 +54,11 @@ impl<'a> ContextualParseError<'a> { Token::QuotedString(ref s) => format!("quoted string \"{}\"", s), Token::UnquotedUrl(ref u) => format!("url {}", u), Token::Delim(ref d) => format!("delimiter {}", d), - Token::Number(NumericValue { int_value: Some(i), .. }) => format!("number {}", i), - Token::Number(ref n) => format!("number {}", n.value), - Token::Percentage(PercentageValue { int_value: Some(i), .. }) => format!("percentage {}", i), - Token::Percentage(ref p) => format!("percentage {}", p.unit_value), - Token::Dimension(_, ref d) => format!("dimension {}", d), + Token::Number { int_value: Some(i), .. } => format!("number {}", i), + Token::Number { value, .. } => format!("number {}", value), + Token::Percentage { int_value: Some(i), .. } => format!("percentage {}", i), + Token::Percentage { unit_value, .. } => format!("percentage {}", unit_value * 100.), + Token::Dimension { value, ref unit, .. } => format!("dimension {}{}", value, unit), Token::WhiteSpace(_) => format!("whitespace"), Token::Comment(_) => format!("comment"), Token::Colon => format!("colon (:)"), diff --git a/servo/components/style/font_face.rs b/servo/components/style/font_face.rs index 8346c801d8d6..fe010cf106d5 100644 --- a/servo/components/style/font_face.rs +++ b/servo/components/style/font_face.rs @@ -12,14 +12,13 @@ use computed_values::{font_feature_settings, font_stretch, font_style, font_weight}; use computed_values::font_family::FamilyName; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; -use cssparser::SourceLocation; +use cssparser::{SourceLocation, CompactCowStr}; use error_reporting::ContextualParseError; #[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors; #[cfg(feature = "gecko")] use cssparser::UnicodeRange; use parser::{ParserContext, log_css_error, Parse}; use selectors::parser::SelectorParseError; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; -use std::borrow::Cow; use std::fmt; use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError}; use values::specified::url::SpecifiedUrl; @@ -256,7 +255,7 @@ macro_rules! font_face_descriptors_common { type Declaration = (); 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>> { match_ignore_ascii_case! { &*name, $( diff --git a/servo/components/style/gecko/media_queries.rs b/servo/components/style/gecko/media_queries.rs index 6edd5436adb1..e0af1fb1dbe0 100644 --- a/servo/components/style/gecko/media_queries.rs +++ b/servo/components/style/gecko/media_queries.rs @@ -231,21 +231,20 @@ impl Resolution { fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { let (value, unit) = match try!(input.next()) { - Token::Dimension(value, unit) => { + Token::Dimension { value, unit, .. } => { (value, unit) }, t => return Err(BasicParseError::UnexpectedToken(t).into()), }; - let inner_value = value.value; - if inner_value <= 0. { + if value <= 0. { return Err(StyleParseError::UnspecifiedError.into()) } (match_ignore_ascii_case! { &unit, - "dpi" => Ok(Resolution::Dpi(inner_value)), - "dppx" => Ok(Resolution::Dppx(inner_value)), - "dpcm" => Ok(Resolution::Dpcm(inner_value)), + "dpi" => Ok(Resolution::Dpi(value)), + "dppx" => Ok(Resolution::Dppx(value)), + "dpcm" => Ok(Resolution::Dpcm(value)), _ => Err(()) }).map_err(|()| StyleParseError::UnexpectedDimension(unit).into()) } diff --git a/servo/components/style/gecko/selector_parser.rs b/servo/components/style/gecko/selector_parser.rs index 9729672a1c74..334ba15197ff 100644 --- a/servo/components/style/gecko/selector_parser.rs +++ b/servo/components/style/gecko/selector_parser.rs @@ -4,13 +4,12 @@ //! Gecko-specific bits for selector-parsing. -use cssparser::{Parser, ToCss}; +use cssparser::{Parser, ToCss, CompactCowStr}; use element_state::ElementState; use gecko_bindings::structs::CSSPseudoClassType; use selector_parser::{SelectorParser, PseudoElementCascadeType}; use selectors::parser::{Selector, SelectorMethods, SelectorParseError}; use selectors::visitor::SelectorVisitor; -use std::borrow::Cow; use std::fmt; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use style_traits::{ParseError, StyleParseError}; @@ -249,7 +248,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { type Impl = SelectorImpl; 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> { macro_rules! pseudo_class_parse { (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, - name: Cow<'i, str>, + name: CompactCowStr<'i>, parser: &mut Parser<'i, 't>) -> Result> { 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> { + fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result> { PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) .ok_or(SelectorParseError::UnexpectedIdent(name.clone()).into()) } diff --git a/servo/components/style/gecko/url.rs b/servo/components/style/gecko/url.rs index d083aa9c3daa..28359fba6cdb 100644 --- a/servo/components/style/gecko/url.rs +++ b/servo/components/style/gecko/url.rs @@ -9,7 +9,6 @@ use gecko_bindings::structs::{ServoBundledURI, URLExtraData}; use gecko_bindings::structs::root::mozilla::css::ImageValue; use gecko_bindings::sugar::refptr::RefPtr; use parser::ParserContext; -use std::borrow::Cow; use std::fmt::{self, Write}; use style_traits::{ToCss, ParseError}; use stylearc::Arc; @@ -36,11 +35,11 @@ impl SpecifiedUrl { /// URL. /// /// 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) -> Result> { Ok(SpecifiedUrl { - serialization: Arc::new(url.into_owned()), + serialization: Arc::new(url), extra_data: context.url_data.clone(), image_value: None, }) diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index bcbb26771a9e..248bc0bd0357 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -7,7 +7,7 @@ #![deny(missing_docs)] use context::QuirksMode; -use cssparser::{DeclarationListParser, parse_important, ParserInput}; +use cssparser::{DeclarationListParser, parse_important, ParserInput, CompactCowStr}; use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter}; use error_reporting::{ParseErrorReporter, ContextualParseError}; use parser::{ParserContext, log_css_error}; @@ -932,7 +932,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { type Declaration = Importance; 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> { let id = try!(PropertyId::parse(name)); input.parse_until_before(Delimiter::Bang, |input| { diff --git a/servo/components/style/properties/longhand/effects.mako.rs b/servo/components/style/properties/longhand/effects.mako.rs index ffafde7f0ed0..c79b3ec5b38b 100644 --- a/servo/components/style/properties/longhand/effects.mako.rs +++ b/servo/components/style/properties/longhand/effects.mako.rs @@ -306,8 +306,8 @@ ${helpers.predefined_type("clip", fn parse_factor<'i, 't>(input: &mut Parser<'i, 't>) -> Result<::values::CSSFloat, ParseError<'i>> { use cssparser::Token; match input.next() { - Ok(Token::Number(value)) if value.value.is_sign_positive() => Ok(value.value), - Ok(Token::Percentage(value)) if value.unit_value.is_sign_positive() => Ok(value.unit_value), + Ok(Token::Number { value, .. }) if value.is_sign_positive() => Ok(value), + Ok(Token::Percentage { unit_value, .. }) if unit_value.is_sign_positive() => Ok(unit_value), Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()), Err(e) => Err(e.into()) } diff --git a/servo/components/style/properties/longhand/list.mako.rs b/servo/components/style/properties/longhand/list.mako.rs index 7b5b2879dd92..a578b619c0fa 100644 --- a/servo/components/style/properties/longhand/list.mako.rs +++ b/servo/components/style/properties/longhand/list.mako.rs @@ -144,7 +144,7 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu <%helpers:longhand name="quotes" animation_value_type="none" spec="https://drafts.csswg.org/css-content/#propdef-quotes"> - use std::borrow::Cow; + use cssparser::serialize_string; use std::fmt; use style_traits::ToCss; use values::computed::ComputedValueAsSpecified; @@ -169,12 +169,12 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu let mut first = true; for pair in &self.0 { if !first { - try!(dest.write_str(" ")); + dest.write_str(" ")?; } first = false; - try!(Token::QuotedString(Cow::from(&*pair.0)).to_css(dest)); - try!(dest.write_str(" ")); - try!(Token::QuotedString(Cow::from(&*pair.1)).to_css(dest)); + serialize_string(&*pair.0, dest)?; + dest.write_str(" ")?; + serialize_string(&*pair.1, dest)?; } Ok(()) } diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index 0ba5e29314eb..0cab5745d7c3 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -20,7 +20,7 @@ use stylearc::{Arc, UniqueArc}; use app_units::Au; #[cfg(feature = "servo")] use cssparser::RGBA; use cssparser::{Parser, TokenSerializationType, serialize_identifier}; -use cssparser::ParserInput; +use cssparser::{ParserInput, CompactCowStr}; use error_reporting::ParseErrorReporter; #[cfg(feature = "servo")] use euclid::SideOffsets2D; use computed_values; @@ -491,7 +491,7 @@ impl CSSWideKeyword { /// Takes the result of cssparser::Parser::expect_ident() and converts it /// to a CSSWideKeyword. - pub fn from_ident<'i>(ident: &Cow<'i, str>) -> Option { + pub fn from_ident<'i>(ident: &str) -> Option { match_ignore_ascii_case! { ident, // If modifying this set of keyword, also update values::CustomIdent::from_ident "initial" => Some(CSSWideKeyword::Initial), @@ -986,7 +986,7 @@ impl PropertyId { /// Returns a given property from the string `s`. /// /// Returns Err(()) for unknown non-custom properties - pub fn parse<'i>(property_name: Cow<'i, str>) -> Result> { + pub fn parse<'i>(property_name: CompactCowStr<'i>) -> Result> { if let Ok(name) = ::custom_properties::parse_name(&property_name) { return Ok(PropertyId::Custom(::custom_properties::Name::from(name))) } diff --git a/servo/components/style/servo/selector_parser.rs b/servo/components/style/servo/selector_parser.rs index 652daa5417c4..235f5fc0f805 100644 --- a/servo/components/style/servo/selector_parser.rs +++ b/servo/components/style/servo/selector_parser.rs @@ -8,7 +8,7 @@ use {Atom, Prefix, Namespace, LocalName, CaseSensitivityExt}; 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 element_state::ElementState; use fnv::FnvHashMap; @@ -311,7 +311,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { type Impl = SelectorImpl; 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> { use self::NonTSPseudoClass::*; 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, - name: Cow<'i, str>, + name: CompactCowStr<'i>, parser: &mut CssParser<'i, 't>) -> Result> { use self::NonTSPseudoClass::*; @@ -356,7 +356,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { if !self.in_user_agent_stylesheet() { 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()) }; @@ -364,7 +364,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { Ok(pseudo_class) } - fn parse_pseudo_element(&self, name: Cow<'i, str>) -> Result> { + fn parse_pseudo_element(&self, name: CompactCowStr<'i>) -> Result> { use self::PseudoElement::*; let pseudo_element = match_ignore_ascii_case! { &name, "before" => Before, diff --git a/servo/components/style/servo/url.rs b/servo/components/style/servo/url.rs index 4cf791e55121..fa019d581e69 100644 --- a/servo/components/style/servo/url.rs +++ b/servo/components/style/servo/url.rs @@ -7,7 +7,6 @@ use cssparser::CssStringWriter; use parser::ParserContext; use servo_url::ServoUrl; -use std::borrow::Cow; use std::fmt::{self, Write}; // Note: We use std::sync::Arc rather than stylearc::Arc here because the // 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 /// URL. Never fails - the API is only fallible to be compatible with the /// gecko version. - pub fn parse_from_string<'a>(url: Cow<'a, str>, + pub fn parse_from_string<'a>(url: String, context: &ParserContext) -> Result> { - let serialization = Arc::new(url.into_owned()); + let serialization = Arc::new(url); let resolved = context.url_data.join(&serialization).ok(); Ok(SpecifiedUrl { original: Some(serialization), diff --git a/servo/components/style/stylesheets/keyframes_rule.rs b/servo/components/style/stylesheets/keyframes_rule.rs index da5311f3da70..d182cdcb39c5 100644 --- a/servo/components/style/stylesheets/keyframes_rule.rs +++ b/servo/components/style/stylesheets/keyframes_rule.rs @@ -4,7 +4,7 @@ //! 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 error_reporting::{NullReporter, ContextualParseError}; 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 selectors::parser::SelectorParseError; use shared_lock::{DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; -use std::borrow::Cow; use std::fmt; use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseError}; use stylearc::Arc; @@ -523,7 +522,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> { type Declaration = (); 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>> { let id = try!(PropertyId::parse(name.into())); match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) { diff --git a/servo/components/style/stylesheets/rule_parser.rs b/servo/components/style/stylesheets/rule_parser.rs index 4da562e7dcb1..6892de64fa29 100644 --- a/servo/components/style/stylesheets/rule_parser.rs +++ b/servo/components/style/stylesheets/rule_parser.rs @@ -6,7 +6,8 @@ use {Namespace, Prefix}; 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 font_face::parse_font_face_block; use media_queries::{parse_media_query_list, MediaList}; @@ -144,7 +145,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { fn parse_prelude<'t>( &mut self, - name: Cow<'i, str>, + name: CompactCowStr<'i>, input: &mut Parser<'i, 't> ) -> Result, ParseError<'i>> { 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; - 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 media = parse_media_query_list(&self.context, input); @@ -203,7 +204,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { self.state = State::Namespaces; 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) .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 opt_prefix = if let Ok(prefix) = prefix_result { - let prefix = Prefix::from(prefix); + let prefix = Prefix::from(Cow::from(prefix)); namespaces .prefixes .insert(prefix.clone(), (url.clone(), id)); @@ -337,7 +338,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> { fn parse_prelude<'t>( &mut self, - name: Cow<'i, str>, + name: CompactCowStr<'i>, input: &mut Parser<'i, 't> ) -> Result, ParseError<'i>> { let location = diff --git a/servo/components/style/stylesheets/viewport_rule.rs b/servo/components/style/stylesheets/viewport_rule.rs index 8f48ac15bb57..6e5ae31d6e48 100644 --- a/servo/components/style/stylesheets/viewport_rule.rs +++ b/servo/components/style/stylesheets/viewport_rule.rs @@ -10,7 +10,7 @@ use app_units::Au; use context::QuirksMode; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important}; -use cssparser::ToCss as ParserToCss; +use cssparser::{CompactCowStr, ToCss as ParserToCss}; use error_reporting::ContextualParseError; use euclid::TypedSize2D; 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; 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>> { macro_rules! declaration { ($declaration:ident($parse:expr)) => { diff --git a/servo/components/style/values/mod.rs b/servo/components/style/values/mod.rs index 962f8ecc0eb2..84cc853f2fb8 100644 --- a/servo/components/style/values/mod.rs +++ b/servo/components/style/values/mod.rs @@ -9,7 +9,7 @@ #![deny(missing_docs)] 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 selectors::parser::SelectorParseError; use std::ascii::AsciiExt; @@ -93,7 +93,7 @@ pub struct CustomIdent(pub Atom); impl CustomIdent { /// Parse an already-tokenizer identifier - pub fn from_ident<'i>(ident: Cow<'i, str>, excluding: &[&str]) -> Result> { + pub fn from_ident<'i>(ident: CompactCowStr<'i>, excluding: &[&str]) -> Result> { let valid = match_ignore_ascii_case! { &ident, "initial" | "inherit" | "unset" | "default" => false, _ => true @@ -104,7 +104,7 @@ impl CustomIdent { if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) { Err(StyleParseError::UnspecifiedError.into()) } else { - Ok(CustomIdent(ident.into())) + Ok(CustomIdent(Atom::from(Cow::from(ident)))) } } } @@ -128,9 +128,10 @@ pub enum KeyframesName { impl KeyframesName { /// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name pub fn from_ident(value: String) -> Self { - match CustomIdent::from_ident((&*value).into(), &["none"]) { - Ok(ident) => KeyframesName::Ident(ident), - Err(_) => KeyframesName::QuotedString(value.into()), + let custom_ident = CustomIdent::from_ident((&*value).into(), &["none"]).ok(); + match custom_ident { + 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> { match input.next() { 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()), Err(e) => Err(e.into()), } diff --git a/servo/components/style/values/specified/calc.rs b/servo/components/style/values/specified/calc.rs index c4a2bae3f078..365bad098ed2 100644 --- a/servo/components/style/values/specified/calc.rs +++ b/servo/components/style/values/specified/calc.rs @@ -150,29 +150,25 @@ impl CalcNode { -> Result> { match (try!(input.next()), expected_unit) { - (Token::Number(ref value), _) => Ok(CalcNode::Number(value.value)), - (Token::Dimension(ref value, ref unit), CalcUnit::Length) | - (Token::Dimension(ref value, ref unit), CalcUnit::LengthOrPercentage) => { - NoCalcLength::parse_dimension(context, value.value, unit) + (Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)), + (Token::Dimension { value, ref unit, .. }, CalcUnit::Length) | + (Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => { + NoCalcLength::parse_dimension(context, value, unit) .map(CalcNode::Length) .map_err(|()| StyleParseError::UnspecifiedError.into()) } - (Token::Dimension(ref value, ref unit), CalcUnit::Angle) => { - Angle::parse_dimension(value.value, - unit, - /* from_calc = */ true) + (Token::Dimension { value, ref unit, .. }, CalcUnit::Angle) => { + Angle::parse_dimension(value, unit, /* from_calc = */ true) .map(CalcNode::Angle) .map_err(|()| StyleParseError::UnspecifiedError.into()) } - (Token::Dimension(ref value, ref unit), CalcUnit::Time) => { - Time::parse_dimension(value.value, - unit, - /* from_calc = */ true) + (Token::Dimension { value, ref unit, .. }, CalcUnit::Time) => { + Time::parse_dimension(value, unit, /* from_calc = */ true) .map(CalcNode::Time) .map_err(|()| StyleParseError::UnspecifiedError.into()) } - (Token::Percentage(ref value), CalcUnit::LengthOrPercentage) => { - Ok(CalcNode::Percentage(value.unit_value)) + (Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) => { + Ok(CalcNode::Percentage(unit_value)) } (Token::ParenthesisBlock, _) => { input.parse_nested_block(|i| { diff --git a/servo/components/style/values/specified/color.rs b/servo/components/style/values/specified/color.rs index 7969106c8d83..fdf6212151f2 100644 --- a/servo/components/style/values/specified/color.rs +++ b/servo/components/style/values/specified/color.rs @@ -173,12 +173,12 @@ impl Color { /// /// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk fn parse_quirky_color<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - let (number, dimension) = match input.next()? { - Token::Number(number) => { - (number, None) + let (value, unit) = match input.next()? { + Token::Number { int_value: Some(integer), .. } => { + (integer, None) }, - Token::Dimension(number, dimension) => { - (number, Some(dimension)) + Token::Dimension { int_value: Some(integer), unit, .. } => { + (integer, Some(unit)) }, Token::Ident(ident) => { if ident.len() != 3 && ident.len() != 6 { @@ -191,7 +191,6 @@ impl Color { return Err(BasicParseError::UnexpectedToken(t).into()); }, }; - let value = number.int_value.ok_or(StyleParseError::UnspecifiedError)?; if value < 0 { return Err(StyleParseError::UnspecifiedError.into()); } @@ -210,7 +209,7 @@ impl Color { } else { 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 { return Err(StyleParseError::UnspecifiedError.into()); } @@ -218,8 +217,8 @@ impl Color { let space_padding = 6 - total; let mut written = space_padding; written += itoa::write(&mut serialization[written..], value).unwrap(); - if let Some(dimension) = dimension { - written += (&mut serialization[written..]).write(dimension.as_bytes()).unwrap(); + if let Some(unit) = unit { + written += (&mut serialization[written..]).write(unit.as_bytes()).unwrap(); } debug_assert!(written == 6); parse_hash_color(&serialization).map_err(|()| StyleParseError::UnspecifiedError.into()) diff --git a/servo/components/style/values/specified/grid.rs b/servo/components/style/values/specified/grid.rs index 501d2ee6d2ab..d19ab3703c3c 100644 --- a/servo/components/style/values/specified/grid.rs +++ b/servo/components/style/values/specified/grid.rs @@ -19,8 +19,8 @@ use values::specified::LengthOrPercentage; /// Parse a single flexible length. pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { match input.next()? { - Token::Dimension(ref value, ref unit) if unit.eq_ignore_ascii_case("fr") && value.value.is_sign_positive() - => Ok(value.value), + Token::Dimension { value, ref unit, .. } if unit.eq_ignore_ascii_case("fr") && value.is_sign_positive() + => Ok(value), t => Err(BasicParseError::UnexpectedToken(t).into()), } } diff --git a/servo/components/style/values/specified/image.rs b/servo/components/style/values/specified/image.rs index 6b091d6aea95..a02d14207540 100644 --- a/servo/components/style/values/specified/image.rs +++ b/servo/components/style/values/specified/image.rs @@ -13,6 +13,7 @@ use parser::{Parse, ParserContext}; use selectors::parser::SelectorParseError; #[cfg(feature = "servo")] use servo_url::ServoUrl; +use std::borrow::Cow; use std::cmp::Ordering; use std::f32::consts::PI; use std::fmt; @@ -137,7 +138,7 @@ impl Image { input.try(|i| i.expect_function_matching("-moz-element"))?; input.parse_nested_block(|i| { 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()), } }) @@ -699,7 +700,7 @@ impl Parse for PaintWorklet { input.parse_nested_block(|i| { let name = i.expect_ident()?; 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.parse_nested_block(|i| { 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()?; let top = NumberOrPercentage::parse_non_negative(context, i)?; i.expect_comma()?; diff --git a/servo/components/style/values/specified/length.rs b/servo/components/style/values/specified/length.rs index cc1655ce33e6..04543f7723dd 100644 --- a/servo/components/style/values/specified/length.rs +++ b/servo/components/style/values/specified/length.rs @@ -611,20 +611,22 @@ impl Length { -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => - Length::parse_dimension(context, value.value, unit), - Token::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { - if value.value != 0. && + Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { + Length::parse_dimension(context, value, unit) + } + 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) { 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| { CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc))) - }), + }) + } _ => Err(()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into()) } @@ -720,8 +722,8 @@ impl Percentage { num_context: AllowedNumericType) -> Result> { match try!(input.next()) { - Token::Percentage(ref value) if num_context.is_ok(context.parsing_mode, value.unit_value) => { - Ok(Percentage(value.unit_value)) + Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { + Ok(Percentage(unit_value)) } t => Err(BasicParseError::UnexpectedToken(t).into()) } @@ -804,17 +806,19 @@ impl LengthOrPercentage { { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => - NoCalcLength::parse_dimension(context, value.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::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { - if value.value != 0. && + Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { + NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentage::Length) + } + Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { + return Ok(LengthOrPercentage::Percentage(Percentage(unit_value))) + } + 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) { Err(()) } 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") => { @@ -822,7 +826,7 @@ impl LengthOrPercentage { CalcNode::parse_length_or_percentage(context, i, num_context) })); return Ok(LengthOrPercentage::Calc(Box::new(calc))) - }, + } _ => Err(()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into()) } @@ -938,28 +942,31 @@ impl LengthOrPercentageOrAuto { -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => - NoCalcLength::parse_dimension(context, value.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::Number(ref value) if num_context.is_ok(context.parsing_mode, value.value) => { - if value.value != 0. && + Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { + NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrAuto::Length) + } + Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { + Ok(LengthOrPercentageOrAuto::Percentage(Percentage(unit_value))) + } + 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) { return Err(StyleParseError::UnspecifiedError.into()) } 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") => - Ok(LengthOrPercentageOrAuto::Auto), + Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => { + Ok(LengthOrPercentageOrAuto::Auto) + } Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { let calc = try!(input.parse_nested_block(|i| { CalcNode::parse_length_or_percentage(context, i, num_context) })); Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc))) - }, + } _ => Err(()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into()) } @@ -1034,17 +1041,19 @@ impl LengthOrPercentageOrNone { { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => - NoCalcLength::parse_dimension(context, value.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::Number(value) if num_context.is_ok(context.parsing_mode, value.value) => { - if value.value != 0. && !context.parsing_mode.allows_unitless_lengths() && + Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { + NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrNone::Length) + } + Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { + Ok(LengthOrPercentageOrNone::Percentage(Percentage(unit_value))) + } + 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) { return Err(StyleParseError::UnspecifiedError.into()) } 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") => { @@ -1052,7 +1061,7 @@ impl LengthOrPercentageOrNone { CalcNode::parse_length_or_percentage(context, i, num_context) })); Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) - }, + } Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => Ok(LengthOrPercentageOrNone::None), _ => Err(()) @@ -1116,23 +1125,28 @@ impl LengthOrPercentageOrAutoOrContent { let num_context = AllowedLengthType::NonNegative; let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) if num_context.is_ok(context.parsing_mode, value.value) => - NoCalcLength::parse_dimension(context, value.value, unit) - .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::Number(ref value) if value.value == 0. => - Ok(Self::zero()), - 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::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { + NoCalcLength::parse_dimension(context, value, unit) + .map(LengthOrPercentageOrAutoOrContent::Length) + } + Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { + Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(unit_value))) + } + Token::Number { value, .. } if value == 0. => { + Ok(Self::zero()) + } + 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") => { let calc = try!(input.parse_nested_block(|i| { CalcNode::parse_length_or_percentage(context, i, num_context) })); Ok(LengthOrPercentageOrAutoOrContent::Calc(Box::new(calc))) - }, + } _ => Err(()) }.map_err(|()| BasicParseError::UnexpectedToken(token).into()) } diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 112a3c38bc65..a1f3692d4f52 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -13,6 +13,7 @@ use parser::{ParserContext, Parse}; use self::grid::TrackSizeOrRepeat; use self::url::SpecifiedUrl; use std::ascii::AsciiExt; +use std::borrow::Cow; use std::f32; use std::fmt; use style_traits::{ToCss, ParseError, StyleParseError}; @@ -79,7 +80,7 @@ pub use ::gecko::url::*; impl Parse for SpecifiedUrl { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { 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>) -> Result> { 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") => { let result = try!(input.parse_nested_block(|i| { CalcNode::parse_integer(context, i) @@ -120,9 +121,9 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext, clamping_mode: AllowedNumericType) -> Result> { 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 { - value: value.value.min(f32::MAX).max(f32::MIN), + value: value.min(f32::MAX).max(f32::MIN), calc_clamping_mode: None, }) }, @@ -226,10 +227,8 @@ impl Parse for Angle { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) => { - Angle::parse_dimension(value.value, - unit, - /* from_calc = */ false) + Token::Dimension { value, ref unit, .. } => { + Angle::parse_dimension(value, unit, /* from_calc = */ false) } Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { return input.parse_nested_block(|i| CalcNode::parse_angle(context, i)) @@ -268,12 +267,10 @@ impl Angle { -> Result> { let token = try!(input.next()); match token { - Token::Dimension(ref value, ref unit) => { - Angle::parse_dimension(value.value, - unit, - /* from_calc = */ false) + Token::Dimension { value, ref unit, .. } => { + Angle::parse_dimension(value, 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") => { 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 // value case, the value does not animate for SMIL at all, so we use // PARSING_MODE_DEFAULT directly. - Ok(Token::Dimension(ref value, ref unit)) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value.value) => { - Time::parse_dimension(value.value, &unit, /* from_calc = */ false) + Ok(Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => { + Time::parse_dimension(value, unit, /* from_calc = */ false) .map_err(|()| StyleParseError::UnspecifiedError.into()) } 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: Namespace = ns.into(); + let ns = Namespace::from(Cow::from(ns)); let id: Result<_, ParseError> = get_id_for_namespace(&ns, context) .map_err(|()| StyleParseError::UnspecifiedError.into()); diff --git a/servo/components/style_traits/Cargo.toml b/servo/components/style_traits/Cargo.toml index 84089411781a..3be76bbfdbb7 100644 --- a/servo/components/style_traits/Cargo.toml +++ b/servo/components/style_traits/Cargo.toml @@ -16,7 +16,7 @@ gecko = [] [dependencies] app_units = "0.5" bitflags = "0.7" -cssparser = "0.15" +cssparser = "0.16" euclid = "0.15" heapsize = {version = "0.4", optional = true} heapsize_derive = {version = "0.1", optional = true} diff --git a/servo/components/style_traits/lib.rs b/servo/components/style_traits/lib.rs index 41a8fe224fc5..a9934e5b56f8 100644 --- a/servo/components/style_traits/lib.rs +++ b/servo/components/style_traits/lib.rs @@ -22,8 +22,8 @@ extern crate euclid; extern crate selectors; #[cfg(feature = "servo")] #[macro_use] extern crate serde; +use cssparser::CompactCowStr; use selectors::parser::SelectorParseError; -use std::borrow::Cow; /// Opaque type stored in type-unsafe work queues for parallel layout. /// 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. PropertyDeclarationValueNotExhausted, /// 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. RangedExpressionWithNoValue, /// 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 UnexpectedNamespaceRule, /// @import must be before any rule but @charset @@ -107,7 +107,7 @@ pub enum StyleParseError<'i> { /// Unexpected @charset rule encountered. UnexpectedCharsetRule, /// Unsupported @ rule - UnsupportedAtRule(Cow<'i, str>), + UnsupportedAtRule(CompactCowStr<'i>), /// A placeholder for many sources of errors that require more specific variants. UnspecifiedError, } diff --git a/servo/components/style_traits/viewport.rs b/servo/components/style_traits/viewport.rs index c3061a30d222..23802789c7c5 100644 --- a/servo/components/style_traits/viewport.rs +++ b/servo/components/style_traits/viewport.rs @@ -149,12 +149,15 @@ impl Zoom { // argument, and pass ParsingMode owned by the ParserContext to // 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. - Token::Percentage(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.unit_value) => - Ok(Zoom::Percentage(value.unit_value)), - Token::Number(ref value) if NonNegative.is_ok(PARSING_MODE_DEFAULT, value.value) => - Ok(Zoom::Number(value.value)), - Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => - Ok(Zoom::Auto), + Token::Percentage { unit_value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, unit_value) => { + Ok(Zoom::Percentage(unit_value)) + } + Token::Number { value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, value) => { + Ok(Zoom::Number(value)) + } + Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => { + Ok(Zoom::Auto) + } t => Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t))) } } diff --git a/servo/ports/geckolib/Cargo.toml b/servo/ports/geckolib/Cargo.toml index ded378c5b836..8827d1dba7de 100644 --- a/servo/ports/geckolib/Cargo.toml +++ b/servo/ports/geckolib/Cargo.toml @@ -16,7 +16,7 @@ gecko_debug = ["style/gecko_debug"] [dependencies] atomic_refcell = "0.1" -cssparser = "0.15" +cssparser = "0.16" env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 9d8f068be355..2b973124977c 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -7,7 +7,6 @@ use cssparser::{Parser, ParserInput}; use cssparser::ToCss as ParserToCss; use env_logger::LogBuilder; use selectors::Element; -use std::borrow::Cow; use std::env; use std::fmt::Write; use std::ptr; @@ -1652,7 +1651,9 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString, QuirksMode::NoQuirks); let easing = unsafe { (*easing).to_string() }; 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) => { *output = parsed_easing.into(); true @@ -1826,7 +1827,7 @@ pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDe macro_rules! get_property_id_from_property { ($property: ident, $ret: expr) => {{ 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, Err(_) => { return $ret; } } @@ -2351,7 +2352,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations: let string = unsafe { (*value).to_string() }; let mut input = ParserInput::new(&string); 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() { let decl = PropertyDeclaration::FontFamily(Box::new(family)); write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { diff --git a/servo/tests/unit/gfx/Cargo.toml b/servo/tests/unit/gfx/Cargo.toml index a2c4b9d4b496..b75bd6718fc4 100644 --- a/servo/tests/unit/gfx/Cargo.toml +++ b/servo/tests/unit/gfx/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" doctest = false [dependencies] -cssparser = "0.15" +cssparser = "0.16" gfx = {path = "../../../components/gfx"} ipc-channel = "0.8" style = {path = "../../../components/style"} diff --git a/servo/tests/unit/style/Cargo.toml b/servo/tests/unit/style/Cargo.toml index 70bab52c50f7..45bb6b3e608e 100644 --- a/servo/tests/unit/style/Cargo.toml +++ b/servo/tests/unit/style/Cargo.toml @@ -15,7 +15,7 @@ testing = ["style/testing"] [dependencies] byteorder = "1.0" app_units = "0.5" -cssparser = "0.15" +cssparser = "0.16" euclid = "0.15" html5ever = "0.18" parking_lot = "0.3" diff --git a/servo/tests/unit/style/parsing/mod.rs b/servo/tests/unit/style/parsing/mod.rs index 12cfe611992a..13998022ed53 100644 --- a/servo/tests/unit/style/parsing/mod.rs +++ b/servo/tests/unit/style/parsing/mod.rs @@ -87,13 +87,14 @@ macro_rules! assert_roundtrip_with_context { }, &mut input).unwrap(); 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) .expect(&format!("Failed to parse serialization {}", $input)); let re_serialized = ToCss::to_css_string(&re_parsed); assert_eq!(serialized, re_serialized); Ok(()) - }, &mut input).unwrap() + }, &mut input).unwrap(); + unwrapped }} } diff --git a/servo/tests/unit/style/properties/mod.rs b/servo/tests/unit/style/properties/mod.rs index 96d66655f56c..241352741e24 100644 --- a/servo/tests/unit/style/properties/mod.rs +++ b/servo/tests/unit/style/properties/mod.rs @@ -40,13 +40,14 @@ macro_rules! assert_roundtrip_with_context { }, $input).unwrap(); let mut input = ::cssparser::ParserInput::new(&serialized); - parse_input(|context, i| { + let unwrapped = parse_input(|context, i| { let re_parsed = $fun(context, i) .expect(&format!("Failed to parse serialization {}", $input)); let re_serialized = ToCss::to_css_string(&re_parsed); assert_eq!(serialized, re_serialized); Ok(()) - }, &mut input).unwrap() + }, &mut input).unwrap(); + unwrapped }} } diff --git a/servo/tests/unit/stylo/Cargo.toml b/servo/tests/unit/stylo/Cargo.toml index 9e4b41479e44..7427a60f3a8f 100644 --- a/servo/tests/unit/stylo/Cargo.toml +++ b/servo/tests/unit/stylo/Cargo.toml @@ -16,7 +16,7 @@ testing = ["style/testing"] [dependencies] atomic_refcell = "0.1" -cssparser = "0.15" +cssparser = "0.16" env_logger = "0.4" euclid = "0.15" geckoservo = {path = "../../../ports/geckolib"}