mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Move stylesheets related code to DocumentOrShadowRoot
This commit is contained in:
parent
d2e1a3ab33
commit
0d6bd24245
6 changed files with 208 additions and 193 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue