forked from mirrors/gecko-dev
		
	 1f87774d78
			
		
	
	
		1f87774d78
		
	
	
	
	
		
			
			This requires https://github.com/servo/rust-cssparser/pull/143 for the final commit. There's no better way to split that work up, unfortunately, and it's extremely easy to bitrot. I would appreciate if we could expedite reviewing this work. This is the work necessary to enable https://bugzilla.mozilla.org/show_bug.cgi?id=1352669. It makes sense to merge it separately because it's so much effort to keep it up to date with the ongoing Stylo work. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [x] There are tests for these changes Source-Repo: https://github.com/servo/servo Source-Revision: 061cb5f48e5c93a5decf39e530aea4a566e97341 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 683cf352b472110df4b28c191e8850763334134d
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| /* 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/. */
 | |
| 
 | |
| use cssparser::{Parser, ParserInput, 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 dom_struct::dom_struct;
 | |
| use style::context::QuirksMode;
 | |
| use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
 | |
| use style::stylesheets::CssRuleType;
 | |
| use style::stylesheets::supports_rule::{Declaration, parse_condition_or_declaration};
 | |
| 
 | |
| #[dom_struct]
 | |
| pub struct CSS {
 | |
|     reflector_: Reflector,
 | |
| }
 | |
| 
 | |
| impl CSS {
 | |
|     /// 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, win.css_error_reporter(), Some(CssRuleType::Supports),
 | |
|                                                    PARSING_MODE_DEFAULT,
 | |
|                                                    QuirksMode::NoQuirks);
 | |
|         decl.eval(&context)
 | |
|     }
 | |
| 
 | |
|     /// https://drafts.csswg.org/css-conditional/#dom-css-supports
 | |
|     pub fn Supports_(win: &Window, condition: DOMString) -> bool {
 | |
|         let mut input = ParserInput::new(&condition);
 | |
|         let mut input = Parser::new(&mut input);
 | |
|         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, win.css_error_reporter(), Some(CssRuleType::Supports),
 | |
|                                                        PARSING_MODE_DEFAULT,
 | |
|                                                        QuirksMode::NoQuirks);
 | |
|             cond.eval(&context)
 | |
|         } else {
 | |
|             false
 | |
|         }
 | |
|     }
 | |
| }
 |