diff options
-rw-r--r-- | components/script/dom/cssstylesheet.rs | 27 | ||||
-rw-r--r-- | components/script/dom/htmllinkelement.rs | 1 | ||||
-rw-r--r-- | components/script/dom/htmlmetaelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmlstyleelement.rs | 1 | ||||
-rw-r--r-- | components/script/dom/stylesheet.rs | 20 | ||||
-rw-r--r-- | components/script/dom/webidls/StyleSheet.webidl | 2 | ||||
-rw-r--r-- | components/style/stylesheets.rs | 16 | ||||
-rw-r--r-- | components/style/stylist.rs | 2 | ||||
-rw-r--r-- | tests/unit/style/stylesheets.rs | 1 | ||||
-rw-r--r-- | tests/wpt/metadata-css/cssom-1_dev/html/interfaces.htm.ini | 6 |
10 files changed, 62 insertions, 16 deletions
diff --git a/components/script/dom/cssstylesheet.rs b/components/script/dom/cssstylesheet.rs index 2e2ac45d867..32413ea0298 100644 --- a/components/script/dom/cssstylesheet.rs +++ b/components/script/dom/cssstylesheet.rs @@ -4,11 +4,13 @@ use dom::bindings::codegen::Bindings::CSSStyleSheetBinding; use dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheetMethods; +use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::js::{JS, Root, MutNullableHeap}; use dom::bindings::reflector::{reflect_dom_object, Reflectable}; use dom::bindings::str::DOMString; use dom::cssrulelist::{CSSRuleList, RulesSource}; +use dom::element::Element; use dom::stylesheet::StyleSheet; use dom::window::Window; use std::sync::Arc; @@ -17,27 +19,34 @@ use style::stylesheets::Stylesheet as StyleStyleSheet; #[dom_struct] pub struct CSSStyleSheet { stylesheet: StyleSheet, + owner: JS<Element>, rulelist: MutNullableHeap<JS<CSSRuleList>>, #[ignore_heap_size_of = "Arc"] style_stylesheet: Arc<StyleStyleSheet>, } impl CSSStyleSheet { - fn new_inherited(type_: DOMString, href: Option<DOMString>, - title: Option<DOMString>, stylesheet: Arc<StyleStyleSheet>) -> CSSStyleSheet { + fn new_inherited(owner: &Element, + type_: DOMString, + href: Option<DOMString>, + title: Option<DOMString>, + stylesheet: Arc<StyleStyleSheet>) -> CSSStyleSheet { CSSStyleSheet { stylesheet: StyleSheet::new_inherited(type_, href, title), + owner: JS::from_ref(owner), rulelist: MutNullableHeap::new(None), style_stylesheet: stylesheet, } } #[allow(unrooted_must_root)] - pub fn new(window: &Window, type_: DOMString, + pub fn new(window: &Window, + owner: &Element, + type_: DOMString, href: Option<DOMString>, title: Option<DOMString>, stylesheet: Arc<StyleStyleSheet>) -> Root<CSSStyleSheet> { - reflect_dom_object(box CSSStyleSheet::new_inherited(type_, href, title, stylesheet), + reflect_dom_object(box CSSStyleSheet::new_inherited(owner, type_, href, title, stylesheet), window, CSSStyleSheetBinding::Wrap) } @@ -48,6 +57,16 @@ impl CSSStyleSheet { RulesSource::Rules(self.style_stylesheet .rules.clone()))) } + + pub fn disabled(&self) -> bool { + self.style_stylesheet.disabled() + } + + pub fn set_disabled(&self, disabled: bool) { + if self.style_stylesheet.set_disabled(disabled) { + self.global().as_window().Document().invalidate_stylesheets(); + } + } } impl CSSStyleSheetMethods for CSSStyleSheet { diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index f311d022470..f0518c55f88 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -94,6 +94,7 @@ impl HTMLLinkElement { self.get_stylesheet().map(|sheet| { self.cssom_stylesheet.or_init(|| { CSSStyleSheet::new(&window_from_node(self), + self.upcast::<Element>(), "text/css".into(), None, // todo handle location None, // todo handle title diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 2a71965305d..fa2fe7846c1 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -63,6 +63,7 @@ impl HTMLMetaElement { self.get_stylesheet().map(|sheet| { self.cssom_stylesheet.or_init(|| { CSSStyleSheet::new(&window_from_node(self), + self.upcast::<Element>(), "text/css".into(), None, // todo handle location None, // todo handle title @@ -103,6 +104,7 @@ impl HTMLMetaElement { // Viewport constraints are always recomputed on resize; they don't need to // force all styles to be recomputed. dirty_on_viewport_size_change: AtomicBool::new(false), + disabled: AtomicBool::new(false), })); let doc = document_from_node(self); doc.invalidate_stylesheets(); diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 6a20bf06cdd..5a61d6f5b3a 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -86,6 +86,7 @@ impl HTMLStyleElement { self.get_stylesheet().map(|sheet| { self.cssom_stylesheet.or_init(|| { CSSStyleSheet::new(&window_from_node(self), + self.upcast::<Element>(), "text/css".into(), None, // todo handle location None, // todo handle title diff --git a/components/script/dom/stylesheet.rs b/components/script/dom/stylesheet.rs index 7def8f1ba6c..91a6b186f27 100644 --- a/components/script/dom/stylesheet.rs +++ b/components/script/dom/stylesheet.rs @@ -4,12 +4,13 @@ use dom::bindings::codegen::Bindings::StyleSheetBinding; use dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods; +use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; +use dom::cssstylesheet::CSSStyleSheet; use dom::window::Window; - #[dom_struct] pub struct StyleSheet { reflector_: Reflector, @@ -20,12 +21,14 @@ pub struct StyleSheet { impl StyleSheet { #[allow(unrooted_must_root)] - pub fn new_inherited(type_: DOMString, href: Option<DOMString>, title: Option<DOMString>) -> StyleSheet { + pub fn new_inherited(type_: DOMString, + href: Option<DOMString>, + title: Option<DOMString>) -> StyleSheet { StyleSheet { reflector_: Reflector::new(), type_: type_, href: href, - title: title + title: title, } } @@ -55,5 +58,14 @@ impl StyleSheetMethods for StyleSheet { fn GetTitle(&self) -> Option<DOMString> { self.title.clone() } -} + // https://drafts.csswg.org/cssom/#dom-stylesheet-disabled + fn Disabled(&self) -> bool { + self.downcast::<CSSStyleSheet>().unwrap().disabled() + } + + // https://drafts.csswg.org/cssom/#dom-stylesheet-disabled + fn SetDisabled(&self, disabled: bool) { + self.downcast::<CSSStyleSheet>().unwrap().set_disabled(disabled) + } +} diff --git a/components/script/dom/webidls/StyleSheet.webidl b/components/script/dom/webidls/StyleSheet.webidl index 336bc6b282c..1ef0533abdc 100644 --- a/components/script/dom/webidls/StyleSheet.webidl +++ b/components/script/dom/webidls/StyleSheet.webidl @@ -13,7 +13,7 @@ interface StyleSheet { readonly attribute DOMString? title; // [SameObject, PutForwards=mediaText] readonly attribute MediaList media; - // attribute boolean disabled; + attribute boolean disabled; }; // https://drafts.csswg.org/cssom/#the-linkstyle-interface diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 12ca0423cfa..1d898eac115 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -113,6 +113,7 @@ pub struct Stylesheet { pub media: Arc<RwLock<MediaList>>, pub origin: Origin, pub dirty_on_viewport_size_change: AtomicBool, + pub disabled: AtomicBool, } @@ -402,6 +403,7 @@ impl Stylesheet { rules: rules.into(), media: Arc::new(RwLock::new(media)), dirty_on_viewport_size_change: AtomicBool::new(input.seen_viewport_percentages()), + disabled: AtomicBool::new(false), } } @@ -442,6 +444,20 @@ impl Stylesheet { pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) { effective_rules(&self.rules.0.read(), device, &mut f); } + + /// Returns whether the stylesheet has been explicitly disabled through the CSSOM. + pub fn disabled(&self) -> bool { + self.disabled.load(Ordering::SeqCst) + } + + /// Records that the stylesheet has been explicitly disabled through the CSSOM. + /// Returns whether the the call resulted in a change in disabled state. + /// + /// Disabled stylesheets remain in the document, but their rules are not added to + /// the Stylist. + pub fn set_disabled(&self, disabled: bool) -> bool { + self.disabled.swap(disabled, Ordering::SeqCst) != disabled + } } fn effective_rules<F>(rules: &[CssRule], device: &Device, f: &mut F) where F: FnMut(&CssRule) { diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 2f756717869..b5d36066238 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -169,7 +169,7 @@ impl Stylist { } fn add_stylesheet(&mut self, stylesheet: &Stylesheet) { - if !stylesheet.is_effective_for_device(&self.device) { + if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device) { return; } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index 9bbde985a46..629bef96d28 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -57,6 +57,7 @@ fn test_parse_stylesheet() { origin: Origin::UserAgent, media: Default::default(), dirty_on_viewport_size_change: AtomicBool::new(false), + disabled: AtomicBool::new(false), rules: vec![ CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule { prefix: None, diff --git a/tests/wpt/metadata-css/cssom-1_dev/html/interfaces.htm.ini b/tests/wpt/metadata-css/cssom-1_dev/html/interfaces.htm.ini index 8f0e47d7557..ae5a08878e2 100644 --- a/tests/wpt/metadata-css/cssom-1_dev/html/interfaces.htm.ini +++ b/tests/wpt/metadata-css/cssom-1_dev/html/interfaces.htm.ini @@ -114,9 +114,6 @@ [StyleSheet interface: attribute media] expected: FAIL - [StyleSheet interface: attribute disabled] - expected: FAIL - [CSSStyleSheet interface: attribute ownerRule] expected: FAIL @@ -135,9 +132,6 @@ [StyleSheet interface: style_element.sheet must inherit property "media" with the proper type (5)] expected: FAIL - [StyleSheet interface: style_element.sheet must inherit property "disabled" with the proper type (6)] - expected: FAIL - [StyleSheetList interface: existence and properties of interface prototype object] expected: FAIL |