aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/stylesheetlist.rs
diff options
context:
space:
mode:
authoryvt <i@yvt.jp>2021-07-10 17:24:27 +0900
committeryvt <i@yvt.jp>2021-07-10 17:55:42 +0900
commit01a7de50ab1843d85295f9dccad7f4c099e7208c (patch)
treeee53fb6e8889deb7b880ee969e6c662e6128d210 /components/script/dom/stylesheetlist.rs
parentff8d2cdbbfc7a9dc7f38b7dd47cb350fde39388f (diff)
parent94b613fbdaa2b98f2179fc0bbda13c64e6fa0d38 (diff)
downloadservo-01a7de50ab1843d85295f9dccad7f4c099e7208c.tar.gz
servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.zip
Merge remote-tracking branch 'upstream/master' into feat-cow-infra
`tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html` was reverted to the upstream version.
Diffstat (limited to 'components/script/dom/stylesheetlist.rs')
-rw-r--r--components/script/dom/stylesheetlist.rs101
1 files changed, 76 insertions, 25 deletions
diff --git a/components/script/dom/stylesheetlist.rs b/components/script/dom/stylesheetlist.rs
index 25d95ae3986..7bd115f5084 100644
--- a/components/script/dom/stylesheetlist.rs
+++ b/components/script/dom/stylesheetlist.rs
@@ -1,57 +1,108 @@
/* 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::StyleSheetListBinding;
-use dom::bindings::codegen::Bindings::StyleSheetListBinding::StyleSheetListMethods;
-use dom::bindings::js::{JS, Root};
-use dom::bindings::reflector::{Reflector, reflect_dom_object};
-use dom::document::Document;
-use dom::stylesheet::StyleSheet;
-use dom::window::Window;
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+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;
+
+#[unrooted_must_root_lint::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: JS<Document>,
+ document_or_shadow_root: StyleSheetListOwner,
}
impl StyleSheetList {
#[allow(unrooted_must_root)]
- fn new_inherited(doc: JS<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: JS<Document>) -> Root<StyleSheetList> {
- reflect_dom_object(box StyleSheetList::new_inherited(document),
- window, StyleSheetListBinding::Wrap)
+ pub fn new(window: &Window, doc_or_sr: StyleSheetListOwner) -> DomRoot<StyleSheetList> {
+ reflect_dom_object(Box::new(StyleSheetList::new_inherited(doc_or_sr)), window)
}
}
impl StyleSheetListMethods for StyleSheetList {
// https://drafts.csswg.org/cssom/#dom-stylesheetlist-length
fn Length(&self) -> u32 {
- self.document.with_style_sheets_in_document(|s| s.len() 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<Root<StyleSheet>> {
- // XXXManishearth this doesn't handle the origin clean flag
- // and is a cors vulnerability
- self.document.with_style_sheets_in_document(|sheets| {
- sheets.get(index as usize)
- .and_then(|sheet| sheet.node.get_cssom_stylesheet())
- .map(Root::upcast)
- })
+ fn Item(&self, index: u32) -> Option<DomRoot<StyleSheet>> {
+ // XXXManishearth this doesn't handle the origin clean flag and is a
+ // cors vulnerability
+ self.document_or_shadow_root
+ .stylesheet_at(index as usize)
+ .map(DomRoot::upcast)
}
// check-tidy: no specs after this line
- fn IndexedGetter(&self, index: u32) -> Option<Root<StyleSheet>> {
+ fn IndexedGetter(&self, index: u32) -> Option<DomRoot<StyleSheet>> {
self.Item(index)
}
}