forked from mirrors/gecko-dev
		
	 d8a79aa1af
			
		
	
	
		d8a79aa1af
		
	
	
	
	
		
			
			This PR is intended to add basic support for all CSSOM interfaces, with the ability to index `document.styleSheets` and css rule lists, and serializing individual css rules. Handling individual interface methods for CSSRule subclasses can probably be done with easy/medium bugs. Mutation safety isn't dealt with here; if the css rule list is mutated the CSSOM will be in an inconsistent state. I intend to deal with this via zero sized tokens, see https://groups.google.com/forum/#!topic/mozilla.dev.servo/AnxJoVmtMXQ . I'll handle that when I start making the CSSOM mutable. (Getting the immutable bit landed first opens this up for easy bugs) This doesn't really change style aside from adding an extra arc in the CSS rule list as discussed in the linked thread. So far this same design can be used by stylo as well when the time comes. f? @SimonSapin @emilio cc @upsuper part of #11420 Todo: - [x] Stubs for rest of the CSSRule subclasses - [x] <s>ToCSS impls for CSSRules.</s> May make into easy bugs and stub out in this PR https://github.com/servo/servo/issues/14195 - [x] Cache CSSStyleSheet on the relevant node Source-Repo: https://github.com/servo/servo Source-Revision: afc60bee2809059b8b754a1c6d6d10c1d36326fb
		
			
				
	
	
		
			67 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
	
		
			2.2 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 dom::bindings::codegen::Bindings::CSSRuleListBinding;
 | |
| use dom::bindings::codegen::Bindings::CSSRuleListBinding::CSSRuleListMethods;
 | |
| use dom::bindings::js::{JS, MutNullableHeap, Root};
 | |
| use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
 | |
| use dom::cssrule::CSSRule;
 | |
| use dom::cssstylesheet::CSSStyleSheet;
 | |
| use dom::window::Window;
 | |
| use style::stylesheets::CssRules;
 | |
| 
 | |
| no_jsmanaged_fields!(CssRules);
 | |
| 
 | |
| #[dom_struct]
 | |
| pub struct CSSRuleList {
 | |
|     reflector_: Reflector,
 | |
|     sheet: JS<CSSStyleSheet>,
 | |
|     #[ignore_heap_size_of = "Arc"]
 | |
|     rules: CssRules,
 | |
|     dom_rules: Vec<MutNullableHeap<JS<CSSRule>>>
 | |
| }
 | |
| 
 | |
| impl CSSRuleList {
 | |
|     #[allow(unrooted_must_root)]
 | |
|     pub fn new_inherited(sheet: &CSSStyleSheet, rules: CssRules) -> CSSRuleList {
 | |
|         let dom_rules = rules.0.read().iter().map(|_| MutNullableHeap::new(None)).collect();
 | |
|         CSSRuleList {
 | |
|             reflector_: Reflector::new(),
 | |
|             sheet: JS::from_ref(sheet),
 | |
|             rules: rules,
 | |
|             dom_rules: dom_rules,
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     #[allow(unrooted_must_root)]
 | |
|     pub fn new(window: &Window, sheet: &CSSStyleSheet, rules: CssRules) -> Root<CSSRuleList> {
 | |
|         reflect_dom_object(box CSSRuleList::new_inherited(sheet, rules),
 | |
|                            window,
 | |
|                            CSSRuleListBinding::Wrap)
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl CSSRuleListMethods for CSSRuleList {
 | |
|     // https://drafts.csswg.org/cssom/#ref-for-dom-cssrulelist-item-1
 | |
|     fn Item(&self, idx: u32) -> Option<Root<CSSRule>> {
 | |
|         self.dom_rules.get(idx as usize).map(|rule| {
 | |
|             rule.or_init(|| {
 | |
|                 CSSRule::new_specific(self.global().as_window(),
 | |
|                                      &self.sheet,
 | |
|                                      self.rules.0.read()[idx as usize].clone())
 | |
|             })
 | |
|         })
 | |
|     }
 | |
| 
 | |
|     // https://drafts.csswg.org/cssom/#dom-cssrulelist-length
 | |
|     fn Length(&self) -> u32 {
 | |
|         self.dom_rules.len() as u32
 | |
|     }
 | |
| 
 | |
|     // check-tidy: no specs after this line
 | |
|     fn IndexedGetter(&self, index: u32) -> Option<Root<CSSRule>> {
 | |
|         self.Item(index)
 | |
|     }
 | |
| }
 | |
| 
 |