mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Add CSS.supports()
This commit is contained in:
parent
56731dc6b5
commit
62bea28031
3 changed files with 34 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue