mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
* Remove script_plugins * Use crown instead of script_plugins * crown_is_not_used * Use crown in command base * bootstrap crown * tidy happy * disable sccache * Bring crown in tree * Install crown from tree * fix windows ci * fix warning * fix mac libscript_plugins.dylib is not available anymore * Update components/script/lib.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> * Update for nightly-2023-03-18 Mostly just based off https://github.com/servo/servo/pull/30630 * Always install crown it's slow only when there is new version * Run crown test with `mach test-unit` * Small fixups; better trace_in_no_trace tests * Better doc * crown in config.toml * Fix tidy for real * no sccache on rustc_wrapper * document rustc overrides * fixup of compiletest * Make a few minor comment adjustments * Fix a typo in python/servo/platform/base.py Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com> * Proper test types * Ignore tidy on crown/tests --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
109 lines
3.7 KiB
Rust
109 lines
3.7 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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
use dom_struct::dom_struct;
|
|
use servo_arc::Arc;
|
|
use style::stylesheets::Stylesheet;
|
|
|
|
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;
|
|
|
|
#[crown::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_or_shadow_root: StyleSheetListOwner,
|
|
}
|
|
|
|
impl StyleSheetList {
|
|
#[allow(crown::unrooted_must_root)]
|
|
fn new_inherited(doc_or_sr: StyleSheetListOwner) -> StyleSheetList {
|
|
StyleSheetList {
|
|
reflector_: Reflector::new(),
|
|
document_or_shadow_root: doc_or_sr,
|
|
}
|
|
}
|
|
|
|
#[allow(crown::unrooted_must_root)]
|
|
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_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_or_shadow_root
|
|
.stylesheet_at(index as usize)
|
|
.map(DomRoot::upcast)
|
|
}
|
|
|
|
// check-tidy: no specs after this line
|
|
fn IndexedGetter(&self, index: u32) -> Option<DomRoot<StyleSheet>> {
|
|
self.Item(index)
|
|
}
|
|
}
|