diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-04-29 08:38:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-29 08:38:50 -0400 |
commit | 799490a02e9bea575bf34c39f045ef0883539f05 (patch) | |
tree | 278cada683564db36997cf3f96c92513b89c3096 /components/script/dom/stylesheetlist.rs | |
parent | d58ea974baff1b51a43d2e2bf4b287ff11991a8d (diff) | |
parent | 37e88e77cdf00e3555599dd4004d03548bd95dcf (diff) | |
download | servo-799490a02e9bea575bf34c39f045ef0883539f05.tar.gz servo-799490a02e9bea575bf34c39f045ef0883539f05.zip |
Auto merge of #22743 - ferjm:shadowdom, r=emilio
Partial ShadowDOM support
This is just an early WIP, not to take it very seriously yet.
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix #22719
- [x] There are tests for these changes
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22743)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/stylesheetlist.rs')
-rw-r--r-- | components/script/dom/stylesheetlist.rs | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/components/script/dom/stylesheetlist.rs b/components/script/dom/stylesheetlist.rs index c1c5c0b2d5f..236f1c9cd9a 100644 --- a/components/script/dom/stylesheetlist.rs +++ b/components/script/dom/stylesheetlist.rs @@ -6,30 +6,85 @@ use crate::dom::bindings::codegen::Bindings::StyleSheetListBinding; use crate::dom::bindings::codegen::Bindings::StyleSheetListBinding::StyleSheetListMethods; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::document::Document; +use crate::dom::element::Element; +use crate::dom::shadowroot::ShadowRoot; use crate::dom::stylesheet::StyleSheet; use crate::dom::window::Window; use dom_struct::dom_struct; +use servo_arc::Arc; +use style::stylesheets::Stylesheet; + +#[must_root] +#[derive(JSTraceable, MallocSizeOf)] +pub enum StyleSheetListOwner { + Document(Dom<Document>), + ShadowRoot(Dom<ShadowRoot>), +} + +impl StyleSheetListOwner { + pub fn stylesheet_count(&self) -> usize { + match *self { + StyleSheetListOwner::Document(ref doc) => doc.stylesheet_count(), + StyleSheetListOwner::ShadowRoot(ref shadow_root) => shadow_root.stylesheet_count(), + } + } + + pub fn stylesheet_at(&self, index: usize) -> Option<DomRoot<CSSStyleSheet>> { + match *self { + StyleSheetListOwner::Document(ref doc) => doc.stylesheet_at(index), + StyleSheetListOwner::ShadowRoot(ref shadow_root) => shadow_root.stylesheet_at(index), + } + } + + pub fn add_stylesheet(&self, owner: &Element, sheet: Arc<Stylesheet>) { + match *self { + StyleSheetListOwner::Document(ref doc) => doc.add_stylesheet(owner, sheet), + StyleSheetListOwner::ShadowRoot(ref shadow_root) => { + shadow_root.add_stylesheet(owner, sheet) + }, + } + } + + pub fn remove_stylesheet(&self, owner: &Element, s: &Arc<Stylesheet>) { + match *self { + StyleSheetListOwner::Document(ref doc) => doc.remove_stylesheet(owner, s), + StyleSheetListOwner::ShadowRoot(ref shadow_root) => { + shadow_root.remove_stylesheet(owner, s) + }, + } + } + + pub fn invalidate_stylesheets(&self) { + match *self { + StyleSheetListOwner::Document(ref doc) => doc.invalidate_stylesheets(), + StyleSheetListOwner::ShadowRoot(ref shadow_root) => { + shadow_root.invalidate_stylesheets() + }, + } + } +} #[dom_struct] pub struct StyleSheetList { reflector_: Reflector, - document: Dom<Document>, + document_or_shadow_root: StyleSheetListOwner, } impl StyleSheetList { #[allow(unrooted_must_root)] - fn new_inherited(doc: Dom<Document>) -> StyleSheetList { + fn new_inherited(doc_or_sr: StyleSheetListOwner) -> StyleSheetList { StyleSheetList { reflector_: Reflector::new(), - document: doc, + document_or_shadow_root: doc_or_sr, } } #[allow(unrooted_must_root)] - pub fn new(window: &Window, document: Dom<Document>) -> DomRoot<StyleSheetList> { + pub fn new(window: &Window, doc_or_sr: StyleSheetListOwner) -> DomRoot<StyleSheetList> { reflect_dom_object( - Box::new(StyleSheetList::new_inherited(document)), + Box::new(StyleSheetList::new_inherited(doc_or_sr)), window, StyleSheetListBinding::Wrap, ) @@ -39,14 +94,14 @@ impl StyleSheetList { impl StyleSheetListMethods for StyleSheetList { // https://drafts.csswg.org/cssom/#dom-stylesheetlist-length fn Length(&self) -> u32 { - self.document.stylesheet_count() as u32 + self.document_or_shadow_root.stylesheet_count() as u32 } // https://drafts.csswg.org/cssom/#dom-stylesheetlist-item fn Item(&self, index: u32) -> Option<DomRoot<StyleSheet>> { // XXXManishearth this doesn't handle the origin clean flag and is a // cors vulnerability - self.document + self.document_or_shadow_root .stylesheet_at(index as usize) .map(DomRoot::upcast) } |