script/dom/css/
stylesheet.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use super::cssstylesheet::CSSStyleSheet;
8use crate::dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods;
9use crate::dom::bindings::inheritance::Castable;
10use crate::dom::bindings::reflector::Reflector;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::str::DOMString;
13use crate::dom::element::Element;
14use crate::dom::medialist::MediaList;
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct StyleSheet {
19    reflector_: Reflector,
20    type_: DOMString,
21    href: Option<DOMString>,
22    title: Option<DOMString>,
23}
24
25impl StyleSheet {
26    pub(crate) fn new_inherited(
27        type_: DOMString,
28        href: Option<DOMString>,
29        title: Option<DOMString>,
30    ) -> StyleSheet {
31        StyleSheet {
32            reflector_: Reflector::new(),
33            type_,
34            href,
35            title,
36        }
37    }
38}
39
40impl StyleSheetMethods<crate::DomTypeHolder> for StyleSheet {
41    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-type>
42    fn Type(&self) -> DOMString {
43        self.type_.clone()
44    }
45
46    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-href>
47    fn GetHref(&self) -> Option<DOMString> {
48        self.href.clone()
49    }
50
51    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-ownernode>
52    fn GetOwnerNode(&self) -> Option<DomRoot<Element>> {
53        self.downcast::<CSSStyleSheet>()
54            .and_then(|s| s.owner_node())
55    }
56
57    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-media>
58    fn Media(&self) -> DomRoot<MediaList> {
59        self.downcast::<CSSStyleSheet>()
60            .unwrap()
61            .medialist(CanGc::note())
62    }
63
64    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-title>
65    fn GetTitle(&self) -> Option<DOMString> {
66        self.title.clone()
67    }
68
69    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-disabled>
70    fn Disabled(&self) -> bool {
71        self.downcast::<CSSStyleSheet>().unwrap().disabled()
72    }
73
74    /// <https://drafts.csswg.org/cssom/#dom-stylesheet-disabled>
75    fn SetDisabled(&self, disabled: bool) {
76        self.downcast::<CSSStyleSheet>()
77            .unwrap()
78            .set_disabled(disabled)
79    }
80}