--- a/servo/components/style/stylesheets/document_rule.rs
+++ b/servo/components/style/stylesheets/document_rule.rs
@@ -1,26 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! [@document rules](https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document)
//! initially in CSS Conditional Rules Module Level 3, @document has been postponed to the level 4.
//! We implement the prefixed `@-moz-document`.
-use cssparser::{Parser, Token, SourceLocation};
+use cssparser::{Parser, SourceLocation};
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use media_queries::Device;
use parser::{Parse, ParserContext};
use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt::{self, Write};
use str::CssStringWriter;
-use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
+use style_traits::{CssWriter, ParseError, ToCss};
use stylesheets::CssRules;
use values::CssUrl;
#[derive(Debug)]
/// A @-moz-document rule
pub struct DocumentRule {
/// The parsed condition
pub condition: DocumentCondition,
@@ -98,48 +98,48 @@ pub enum UrlMatchingFunction {
Regexp(String),
}
macro_rules! parse_quoted_or_unquoted_string {
($input:ident, $url_matching_function:expr) => {
$input.parse_nested_block(|input| {
let start = input.position();
input.parse_entirely(|input| {
- let location = input.current_source_location();
- match *input.next()? {
- Token::QuotedString(ref value) => {
- Ok($url_matching_function(value.as_ref().to_owned()))
- },
- ref t => Err(location.new_unexpected_token_error(t.clone())),
- }
+ let string = input.expect_string()?;
+ Ok($url_matching_function(string.as_ref().to_owned()))
}).or_else(|_: ParseError| {
while let Ok(_) = input.next() {}
Ok($url_matching_function(input.slice_from(start).to_string()))
})
})
}
}
impl UrlMatchingFunction {
/// Parse a URL matching function for a`@document` rule's condition.
- pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
- -> Result<UrlMatchingFunction, ParseError<'i>> {
+ pub fn parse<'i, 't>(
+ context: &ParserContext,
+ input: &mut Parser<'i, 't>,
+ ) -> Result<Self, ParseError<'i>> {
if input.try(|input| input.expect_function_matching("url-prefix")).is_ok() {
- parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::UrlPrefix)
- } else if input.try(|input| input.expect_function_matching("domain")).is_ok() {
- parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::Domain)
- } else if input.try(|input| input.expect_function_matching("regexp")).is_ok() {
- input.parse_nested_block(|input| {
+ return parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::UrlPrefix)
+ }
+
+ if input.try(|input| input.expect_function_matching("domain")).is_ok() {
+ return parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::Domain)
+ }
+
+ if input.try(|input| input.expect_function_matching("regexp")).is_ok() {
+ return input.parse_nested_block(|input| {
Ok(UrlMatchingFunction::Regexp(input.expect_string()?.as_ref().to_owned()))
- })
- } else if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) {
- Ok(UrlMatchingFunction::Url(url))
- } else {
- Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
+ });
}
+
+ let url = CssUrl::parse(context, input)?;
+ Ok(UrlMatchingFunction::Url(url))
}
#[cfg(feature = "gecko")]
/// Evaluate a URL matching function.
pub fn evaluate(&self, device: &Device) -> bool {
use gecko_bindings::bindings::Gecko_DocumentRule_UseForPresentation;
use gecko_bindings::structs::URLMatchingFunction as GeckoUrlMatchingFunction;
use nsstring::nsCStr;
@@ -177,21 +177,23 @@ impl UrlMatchingFunction {
/// URL matching functions, and the condition evaluates to true whenever any
/// one of those functions evaluates to true.
#[css(comma)]
#[derive(Clone, Debug, ToCss)]
pub struct DocumentCondition(#[css(iterable)] Vec<UrlMatchingFunction>);
impl DocumentCondition {
/// Parse a document condition.
- pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
- -> Result<Self, ParseError<'i>> {
+ pub fn parse<'i, 't>(
+ context: &ParserContext,
+ input: &mut Parser<'i, 't>,
+ ) -> Result<Self, ParseError<'i>> {
input.parse_comma_separated(|input| UrlMatchingFunction::parse(context, input))
.map(DocumentCondition)
}
/// Evaluate a document condition.
pub fn evaluate(&self, device: &Device) -> bool {
- self.0.iter().any(|ref url_matching_function|
+ self.0.iter().any(|url_matching_function| {
url_matching_function.evaluate(device)
- )
+ })
}
}