diff options
author | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2019-02-04 21:11:56 +0100 |
---|---|---|
committer | Fernando Jiménez Moreno <ferjmoreno@gmail.com> | 2019-04-26 10:17:47 +0200 |
commit | 0d6bd24245df02e8e745a273e37cd53d70c19ce6 (patch) | |
tree | 4d0d7bcc4eba85e4364ddd0da5782134057b27cf /components/script/dom/shadowroot.rs | |
parent | d2e1a3ab33e59bf3debc59d35619f11ff395fa7e (diff) | |
download | servo-0d6bd24245df02e8e745a273e37cd53d70c19ce6.tar.gz servo-0d6bd24245df02e8e745a273e37cd53d70c19ce6.zip |
Move stylesheets related code to DocumentOrShadowRoot
Diffstat (limited to 'components/script/dom/shadowroot.rs')
-rw-r--r-- | components/script/dom/shadowroot.rs | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index 55470a9935d..4a77452a2a5 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -11,10 +11,10 @@ use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom}; use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::document::Document; use crate::dom::documentfragment::DocumentFragment; -use crate::dom::documentorshadowroot::{DocumentOrShadowRoot, DocumentOrShadowRootImpl}; +use crate::dom::documentorshadowroot::DocumentOrShadowRoot; use crate::dom::element::Element; use crate::dom::node::{Node, NodeFlags}; -use crate::dom::stylesheetlist::StyleSheetList; +use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner}; use crate::dom::window::Window; use dom_struct::dom_struct; @@ -22,7 +22,7 @@ use dom_struct::dom_struct; #[dom_struct] pub struct ShadowRoot { document_fragment: DocumentFragment, - document_or_shadow_root: DocumentOrShadowRootImpl, + document_or_shadow_root: DocumentOrShadowRoot, document: Dom<Document>, host: Dom<Element>, stylesheet_list: MutNullableDom<StyleSheetList>, @@ -38,7 +38,7 @@ impl ShadowRoot { .set_flag(NodeFlags::IS_IN_SHADOW_TREE, true); ShadowRoot { document_fragment, - document_or_shadow_root: DocumentOrShadowRootImpl::new(document.window()), + document_or_shadow_root: DocumentOrShadowRoot::new(document.window()), document: Dom::from_ref(document), host: Dom::from_ref(host), stylesheet_list: MutNullableDom::new(None), @@ -58,16 +58,6 @@ impl ShadowRoot { //XXX get retargeted focused element None } - - pub fn stylesheet_count(&self) -> usize { - //XXX handle shadowroot stylesheets - 0 - } - - pub fn stylesheet_at(&self, _index: usize) -> Option<DomRoot<CSSStyleSheet>> { - //XXX handle shadowroot stylesheets - None - } } impl ShadowRootMethods for ShadowRoot { @@ -113,12 +103,8 @@ impl ShadowRootMethods for ShadowRoot { // https://drafts.csswg.org/cssom/#dom-document-stylesheets fn StyleSheets(&self) -> DomRoot<StyleSheetList> { - self.stylesheet_list.or_init(|| { - StyleSheetList::new( - &self.window, - DocumentOrShadowRoot::ShadowRoot(Dom::from_ref(self)), - ) - }) + self.stylesheet_list + .or_init(|| StyleSheetList::new(&self.window, Box::new(Dom::from_ref(self)))) } } @@ -134,3 +120,13 @@ impl LayoutShadowRootHelpers for LayoutDom<ShadowRoot> { (*self.unsafe_get()).host.to_layout() } } + +impl StyleSheetListOwner for Dom<ShadowRoot> { + fn stylesheet_count(&self) -> usize { + self.document_or_shadow_root.stylesheet_count() + } + + fn stylesheet_at(&self, index: usize) -> Option<DomRoot<CSSStyleSheet>> { + self.document_or_shadow_root.stylesheet_at(index) + } +} |