mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Derive ToCss for UrlMatchingFunction
This commit is contained in:
parent
0eb8b1f4c0
commit
ba1d3d4b81
1 changed files with 8 additions and 33 deletions
|
@ -71,7 +71,7 @@ impl DeepCloneWithLock for DocumentRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A URL matching function for a `@document` rule's condition.
|
/// A URL matching function for a `@document` rule's condition.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, ToCss)]
|
||||||
pub enum UrlMatchingFunction {
|
pub enum UrlMatchingFunction {
|
||||||
/// 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.
|
||||||
|
@ -81,6 +81,7 @@ pub enum UrlMatchingFunction {
|
||||||
/// function as an initial substring (which is true when the two
|
/// function as an initial substring (which is true when the two
|
||||||
/// strings are equal). When the argument is the empty string,
|
/// strings are equal). When the argument is the empty string,
|
||||||
/// it evaluates to true for all documents.
|
/// it evaluates to true for all documents.
|
||||||
|
#[css(function)]
|
||||||
UrlPrefix(String),
|
UrlPrefix(String),
|
||||||
/// Domain matching function. It evaluates to true whenever the URL
|
/// Domain matching function. It evaluates to true whenever the URL
|
||||||
/// of the document being styled has a host subcomponent and that
|
/// of the document being styled has a host subcomponent and that
|
||||||
|
@ -88,11 +89,13 @@ pub enum UrlMatchingFunction {
|
||||||
/// function or a final substring of the host component is a
|
/// function or a final substring of the host component is a
|
||||||
/// period (U+002E) immediately followed by the argument to the
|
/// period (U+002E) immediately followed by the argument to the
|
||||||
/// ‘domain()’ function.
|
/// ‘domain()’ function.
|
||||||
|
#[css(function)]
|
||||||
Domain(String),
|
Domain(String),
|
||||||
/// Regular expression matching function. It evaluates to true
|
/// Regular expression matching function. It evaluates to true
|
||||||
/// whenever the regular expression matches the entirety of the URL
|
/// whenever the regular expression matches the entirety of the URL
|
||||||
/// of the document being styled.
|
/// of the document being styled.
|
||||||
RegExp(String),
|
#[css(function)]
|
||||||
|
Regexp(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_quoted_or_unquoted_string {
|
macro_rules! parse_quoted_or_unquoted_string {
|
||||||
|
@ -125,7 +128,7 @@ impl UrlMatchingFunction {
|
||||||
parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::Domain)
|
parse_quoted_or_unquoted_string!(input, UrlMatchingFunction::Domain)
|
||||||
} else if input.try(|input| input.expect_function_matching("regexp")).is_ok() {
|
} else if input.try(|input| input.expect_function_matching("regexp")).is_ok() {
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
Ok(UrlMatchingFunction::RegExp(input.expect_string()?.as_ref().to_owned()))
|
Ok(UrlMatchingFunction::Regexp(input.expect_string()?.as_ref().to_owned()))
|
||||||
})
|
})
|
||||||
} else if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
} else if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||||
Ok(UrlMatchingFunction::Url(url))
|
Ok(UrlMatchingFunction::Url(url))
|
||||||
|
@ -145,14 +148,14 @@ impl UrlMatchingFunction {
|
||||||
UrlMatchingFunction::Url(_) => GeckoUrlMatchingFunction::eURL,
|
UrlMatchingFunction::Url(_) => GeckoUrlMatchingFunction::eURL,
|
||||||
UrlMatchingFunction::UrlPrefix(_) => GeckoUrlMatchingFunction::eURLPrefix,
|
UrlMatchingFunction::UrlPrefix(_) => GeckoUrlMatchingFunction::eURLPrefix,
|
||||||
UrlMatchingFunction::Domain(_) => GeckoUrlMatchingFunction::eDomain,
|
UrlMatchingFunction::Domain(_) => GeckoUrlMatchingFunction::eDomain,
|
||||||
UrlMatchingFunction::RegExp(_) => GeckoUrlMatchingFunction::eRegExp,
|
UrlMatchingFunction::Regexp(_) => GeckoUrlMatchingFunction::eRegExp,
|
||||||
};
|
};
|
||||||
|
|
||||||
let pattern = nsCStr::from(match *self {
|
let pattern = nsCStr::from(match *self {
|
||||||
UrlMatchingFunction::Url(ref url) => url.as_str(),
|
UrlMatchingFunction::Url(ref url) => url.as_str(),
|
||||||
UrlMatchingFunction::UrlPrefix(ref pat) |
|
UrlMatchingFunction::UrlPrefix(ref pat) |
|
||||||
UrlMatchingFunction::Domain(ref pat) |
|
UrlMatchingFunction::Domain(ref pat) |
|
||||||
UrlMatchingFunction::RegExp(ref pat) => pat,
|
UrlMatchingFunction::Regexp(ref pat) => pat,
|
||||||
});
|
});
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func)
|
Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func)
|
||||||
|
@ -166,34 +169,6 @@ impl UrlMatchingFunction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for UrlMatchingFunction {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
UrlMatchingFunction::Url(ref url) => {
|
|
||||||
url.to_css(dest)
|
|
||||||
},
|
|
||||||
UrlMatchingFunction::UrlPrefix(ref url_prefix) => {
|
|
||||||
dest.write_str("url-prefix(")?;
|
|
||||||
url_prefix.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
UrlMatchingFunction::Domain(ref domain) => {
|
|
||||||
dest.write_str("domain(")?;
|
|
||||||
domain.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
UrlMatchingFunction::RegExp(ref regex) => {
|
|
||||||
dest.write_str("regexp(")?;
|
|
||||||
regex.to_css(dest)?;
|
|
||||||
dest.write_str(")")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `@document` rule's condition.
|
/// A `@document` rule's condition.
|
||||||
///
|
///
|
||||||
/// <https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document>
|
/// <https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue