diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2017-01-02 00:11:27 -0800 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2017-01-07 23:17:55 -0800 |
commit | 62bea2803101adb2f1fc08afc51455951a986c35 (patch) | |
tree | 15db5124473604f6e0f9fc0d6ae039f6057ddb5e /components/script/dom/css.rs | |
parent | 56731dc6b52a85be757397cbc31234b42f0b5f50 (diff) | |
download | servo-62bea2803101adb2f1fc08afc51455951a986c35.tar.gz servo-62bea2803101adb2f1fc08afc51455951a986c35.zip |
Add CSS.supports()
Diffstat (limited to 'components/script/dom/css.rs')
-rw-r--r-- | components/script/dom/css.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index 2e04aed50bc..bf264f14322 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -2,11 +2,14 @@ * 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/. */ -use cssparser::serialize_identifier; +use cssparser::{Parser, serialize_identifier}; +use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; use dom::bindings::error::Fallible; use dom::bindings::reflector::Reflector; use dom::bindings::str::DOMString; use dom::window::Window; +use style::parser::ParserContext; +use style::supports::{Declaration, parse_condition_or_declaration}; #[dom_struct] pub struct CSS { @@ -14,10 +17,31 @@ pub struct CSS { } impl CSS { - // http://dev.w3.org/csswg/cssom/#serialize-an-identifier + /// http://dev.w3.org/csswg/cssom/#serialize-an-identifier pub fn Escape(_: &Window, ident: DOMString) -> Fallible<DOMString> { let mut escaped = String::new(); serialize_identifier(&ident, &mut escaped).unwrap(); Ok(DOMString::from(escaped)) } + + /// https://drafts.csswg.org/css-conditional/#dom-css-supports + pub fn Supports(win: &Window, property: DOMString, value: DOMString) -> bool { + let decl = Declaration { prop: property.into(), val: value.into() }; + let url = win.Document().url(); + let context = ParserContext::new_for_cssom(&url); + decl.eval(&context) + } + + /// https://drafts.csswg.org/css-conditional/#dom-css-supports + pub fn Supports_(win: &Window, condition: DOMString) -> bool { + let mut input = Parser::new(&condition); + let cond = parse_condition_or_declaration(&mut input); + if let Ok(cond) = cond { + let url = win.Document().url(); + let context = ParserContext::new_for_cssom(&url); + cond.eval(&context) + } else { + false + } + } } |