Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement StyleSheet.disabled #14340

Merged
merged 1 commit into from Nov 25, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

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

@@ -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,
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.