Implement StyleSheet.disabled.

This commit is contained in:
Cameron McCormack 2016-11-23 18:07:16 +08:00
parent 4529435f96
commit 64ff6dc103
10 changed files with 62 additions and 16 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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();

View file

@ -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

View file

@ -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)
}
}

View file

@ -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