style: UrlMatchingFunction -> DocumentMatchingFunction.

Bug: 1475511
Reviewed-by: xidorn
MozReview-Commit-ID: HLcaVmehFW7
This commit is contained in:
Emilio Cobos Álvarez 2018-07-19 12:56:27 +02:00
parent 02d27ad3dd
commit 095841db7f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -71,9 +71,9 @@ impl DeepCloneWithLock for DocumentRule {
} }
} }
/// A URL matching function for a `@document` rule's condition. /// A matching function for a `@document` rule's condition.
#[derive(Clone, Debug, ToCss)] #[derive(Clone, Debug, ToCss)]
pub enum UrlMatchingFunction { pub enum DocumentMatchingFunction {
/// Exact URL matching function. It evaluates to true whenever the /// Exact URL matching function. It evaluates to true whenever the
/// URL of the document being styled is exactly the URL given. /// URL of the document being styled is exactly the URL given.
Url(CssUrl), Url(CssUrl),
@ -116,7 +116,7 @@ macro_rules! parse_quoted_or_unquoted_string {
}; };
} }
impl UrlMatchingFunction { impl DocumentMatchingFunction {
/// Parse a URL matching function for a`@document` rule's condition. /// Parse a URL matching function for a`@document` rule's condition.
pub fn parse<'i, 't>( pub fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
@ -126,14 +126,14 @@ impl UrlMatchingFunction {
.try(|input| input.expect_function_matching("url-prefix")) .try(|input| input.expect_function_matching("url-prefix"))
.is_ok() .is_ok()
{ {
return parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::UrlPrefix); return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix);
} }
if input if input
.try(|input| input.expect_function_matching("domain")) .try(|input| input.expect_function_matching("domain"))
.is_ok() .is_ok()
{ {
return parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::Domain); return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain);
} }
if input if input
@ -141,35 +141,35 @@ impl UrlMatchingFunction {
.is_ok() .is_ok()
{ {
return input.parse_nested_block(|input| { return input.parse_nested_block(|input| {
Ok(UrlMatchingFunction::Regexp( Ok(DocumentMatchingFunction::Regexp(
input.expect_string()?.as_ref().to_owned(), input.expect_string()?.as_ref().to_owned(),
)) ))
}); });
} }
let url = CssUrl::parse(context, input)?; let url = CssUrl::parse(context, input)?;
Ok(UrlMatchingFunction::Url(url)) Ok(DocumentMatchingFunction::Url(url))
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
/// Evaluate a URL matching function. /// Evaluate a URL matching function.
pub fn evaluate(&self, device: &Device) -> bool { pub fn evaluate(&self, device: &Device) -> bool {
use gecko_bindings::bindings::Gecko_DocumentRule_UseForPresentation; use gecko_bindings::bindings::Gecko_DocumentRule_UseForPresentation;
use gecko_bindings::structs::URLMatchingFunction as GeckoUrlMatchingFunction; use gecko_bindings::structs::DocumentMatchingFunction as GeckoDocumentMatchingFunction;
use nsstring::nsCStr; use nsstring::nsCStr;
let func = match *self { let func = match *self {
UrlMatchingFunction::Url(_) => GeckoUrlMatchingFunction::eURL, DocumentMatchingFunction::Url(_) => GeckoDocumentMatchingFunction::URL,
UrlMatchingFunction::UrlPrefix(_) => GeckoUrlMatchingFunction::eURLPrefix, DocumentMatchingFunction::UrlPrefix(_) => GeckoDocumentMatchingFunction::URLPrefix,
UrlMatchingFunction::Domain(_) => GeckoUrlMatchingFunction::eDomain, DocumentMatchingFunction::Domain(_) => GeckoDocumentMatchingFunction::Domain,
UrlMatchingFunction::Regexp(_) => GeckoUrlMatchingFunction::eRegExp, DocumentMatchingFunction::Regexp(_) => GeckoDocumentMatchingFunction::RegExp,
}; };
let pattern = nsCStr::from(match *self { let pattern = nsCStr::from(match *self {
UrlMatchingFunction::Url(ref url) => url.as_str(), DocumentMatchingFunction::Url(ref url) => url.as_str(),
UrlMatchingFunction::UrlPrefix(ref pat) | DocumentMatchingFunction::UrlPrefix(ref pat) |
UrlMatchingFunction::Domain(ref pat) | DocumentMatchingFunction::Domain(ref pat) |
UrlMatchingFunction::Regexp(ref pat) => pat, DocumentMatchingFunction::Regexp(ref pat) => pat,
}); });
unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) } unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) }
} }
@ -190,7 +190,7 @@ impl UrlMatchingFunction {
/// one of those functions evaluates to true. /// one of those functions evaluates to true.
#[css(comma)] #[css(comma)]
#[derive(Clone, Debug, ToCss)] #[derive(Clone, Debug, ToCss)]
pub struct DocumentCondition(#[css(iterable)] Vec<UrlMatchingFunction>); pub struct DocumentCondition(#[css(iterable)] Vec<DocumentMatchingFunction>);
impl DocumentCondition { impl DocumentCondition {
/// Parse a document condition. /// Parse a document condition.
@ -199,7 +199,7 @@ impl DocumentCondition {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let conditions = let conditions =
input.parse_comma_separated(|input| UrlMatchingFunction::parse(context, input))?; input.parse_comma_separated(|input| DocumentMatchingFunction::parse(context, input))?;
let condition = DocumentCondition(conditions); let condition = DocumentCondition(conditions);
if !condition.allowed_in(context) { if !condition.allowed_in(context) {
@ -252,7 +252,7 @@ impl DocumentCondition {
// NOTE(emilio): This technically allows url-prefix("") too, but... // NOTE(emilio): This technically allows url-prefix("") too, but...
match self.0[0] { match self.0[0] {
UrlMatchingFunction::UrlPrefix(ref prefix) => prefix.is_empty(), DocumentMatchingFunction::UrlPrefix(ref prefix) => prefix.is_empty(),
_ => false, _ => false,
} }
} }