mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement StyleSheet.disabled.
This commit is contained in:
parent
4529435f96
commit
64ff6dc103
10 changed files with 62 additions and 16 deletions
|
@ -4,11 +4,13 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding;
|
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding;
|
||||||
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheetMethods;
|
use dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheetMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::error::{ErrorResult, Fallible};
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::js::{JS, Root, MutNullableHeap};
|
use dom::bindings::js::{JS, Root, MutNullableHeap};
|
||||||
use dom::bindings::reflector::{reflect_dom_object, Reflectable};
|
use dom::bindings::reflector::{reflect_dom_object, Reflectable};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::cssrulelist::{CSSRuleList, RulesSource};
|
use dom::cssrulelist::{CSSRuleList, RulesSource};
|
||||||
|
use dom::element::Element;
|
||||||
use dom::stylesheet::StyleSheet;
|
use dom::stylesheet::StyleSheet;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -17,27 +19,34 @@ use style::stylesheets::Stylesheet as StyleStyleSheet;
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct CSSStyleSheet {
|
pub struct CSSStyleSheet {
|
||||||
stylesheet: StyleSheet,
|
stylesheet: StyleSheet,
|
||||||
|
owner: JS<Element>,
|
||||||
rulelist: MutNullableHeap<JS<CSSRuleList>>,
|
rulelist: MutNullableHeap<JS<CSSRuleList>>,
|
||||||
#[ignore_heap_size_of = "Arc"]
|
#[ignore_heap_size_of = "Arc"]
|
||||||
style_stylesheet: Arc<StyleStyleSheet>,
|
style_stylesheet: Arc<StyleStyleSheet>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSSStyleSheet {
|
impl CSSStyleSheet {
|
||||||
fn new_inherited(type_: DOMString, href: Option<DOMString>,
|
fn new_inherited(owner: &Element,
|
||||||
title: Option<DOMString>, stylesheet: Arc<StyleStyleSheet>) -> CSSStyleSheet {
|
type_: DOMString,
|
||||||
|
href: Option<DOMString>,
|
||||||
|
title: Option<DOMString>,
|
||||||
|
stylesheet: Arc<StyleStyleSheet>) -> CSSStyleSheet {
|
||||||
CSSStyleSheet {
|
CSSStyleSheet {
|
||||||
stylesheet: StyleSheet::new_inherited(type_, href, title),
|
stylesheet: StyleSheet::new_inherited(type_, href, title),
|
||||||
|
owner: JS::from_ref(owner),
|
||||||
rulelist: MutNullableHeap::new(None),
|
rulelist: MutNullableHeap::new(None),
|
||||||
style_stylesheet: stylesheet,
|
style_stylesheet: stylesheet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new(window: &Window, type_: DOMString,
|
pub fn new(window: &Window,
|
||||||
|
owner: &Element,
|
||||||
|
type_: DOMString,
|
||||||
href: Option<DOMString>,
|
href: Option<DOMString>,
|
||||||
title: Option<DOMString>,
|
title: Option<DOMString>,
|
||||||
stylesheet: Arc<StyleStyleSheet>) -> Root<CSSStyleSheet> {
|
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,
|
window,
|
||||||
CSSStyleSheetBinding::Wrap)
|
CSSStyleSheetBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +57,16 @@ impl CSSStyleSheet {
|
||||||
RulesSource::Rules(self.style_stylesheet
|
RulesSource::Rules(self.style_stylesheet
|
||||||
.rules.clone())))
|
.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 {
|
impl CSSStyleSheetMethods for CSSStyleSheet {
|
||||||
|
|
|
@ -94,6 +94,7 @@ impl HTMLLinkElement {
|
||||||
self.get_stylesheet().map(|sheet| {
|
self.get_stylesheet().map(|sheet| {
|
||||||
self.cssom_stylesheet.or_init(|| {
|
self.cssom_stylesheet.or_init(|| {
|
||||||
CSSStyleSheet::new(&window_from_node(self),
|
CSSStyleSheet::new(&window_from_node(self),
|
||||||
|
self.upcast::<Element>(),
|
||||||
"text/css".into(),
|
"text/css".into(),
|
||||||
None, // todo handle location
|
None, // todo handle location
|
||||||
None, // todo handle title
|
None, // todo handle title
|
||||||
|
|
|
@ -63,6 +63,7 @@ impl HTMLMetaElement {
|
||||||
self.get_stylesheet().map(|sheet| {
|
self.get_stylesheet().map(|sheet| {
|
||||||
self.cssom_stylesheet.or_init(|| {
|
self.cssom_stylesheet.or_init(|| {
|
||||||
CSSStyleSheet::new(&window_from_node(self),
|
CSSStyleSheet::new(&window_from_node(self),
|
||||||
|
self.upcast::<Element>(),
|
||||||
"text/css".into(),
|
"text/css".into(),
|
||||||
None, // todo handle location
|
None, // todo handle location
|
||||||
None, // todo handle title
|
None, // todo handle title
|
||||||
|
@ -103,6 +104,7 @@ impl HTMLMetaElement {
|
||||||
// Viewport constraints are always recomputed on resize; they don't need to
|
// Viewport constraints are always recomputed on resize; they don't need to
|
||||||
// force all styles to be recomputed.
|
// force all styles to be recomputed.
|
||||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||||
|
disabled: AtomicBool::new(false),
|
||||||
}));
|
}));
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
doc.invalidate_stylesheets();
|
doc.invalidate_stylesheets();
|
||||||
|
|
|
@ -86,6 +86,7 @@ impl HTMLStyleElement {
|
||||||
self.get_stylesheet().map(|sheet| {
|
self.get_stylesheet().map(|sheet| {
|
||||||
self.cssom_stylesheet.or_init(|| {
|
self.cssom_stylesheet.or_init(|| {
|
||||||
CSSStyleSheet::new(&window_from_node(self),
|
CSSStyleSheet::new(&window_from_node(self),
|
||||||
|
self.upcast::<Element>(),
|
||||||
"text/css".into(),
|
"text/css".into(),
|
||||||
None, // todo handle location
|
None, // todo handle location
|
||||||
None, // todo handle title
|
None, // todo handle title
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::StyleSheetBinding;
|
use dom::bindings::codegen::Bindings::StyleSheetBinding;
|
||||||
use dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods;
|
use dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods;
|
||||||
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::cssstylesheet::CSSStyleSheet;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct StyleSheet {
|
pub struct StyleSheet {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -20,12 +21,14 @@ pub struct StyleSheet {
|
||||||
|
|
||||||
impl StyleSheet {
|
impl StyleSheet {
|
||||||
#[allow(unrooted_must_root)]
|
#[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 {
|
StyleSheet {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
type_: type_,
|
type_: type_,
|
||||||
href: href,
|
href: href,
|
||||||
title: title
|
title: title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,5 +58,14 @@ impl StyleSheetMethods for StyleSheet {
|
||||||
fn GetTitle(&self) -> Option<DOMString> {
|
fn GetTitle(&self) -> Option<DOMString> {
|
||||||
self.title.clone()
|
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;
|
readonly attribute DOMString? title;
|
||||||
|
|
||||||
// [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
// [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
||||||
// attribute boolean disabled;
|
attribute boolean disabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#the-linkstyle-interface
|
// https://drafts.csswg.org/cssom/#the-linkstyle-interface
|
||||||
|
|
|
@ -113,6 +113,7 @@ pub struct Stylesheet {
|
||||||
pub media: Arc<RwLock<MediaList>>,
|
pub media: Arc<RwLock<MediaList>>,
|
||||||
pub origin: Origin,
|
pub origin: Origin,
|
||||||
pub dirty_on_viewport_size_change: AtomicBool,
|
pub dirty_on_viewport_size_change: AtomicBool,
|
||||||
|
pub disabled: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,6 +403,7 @@ impl Stylesheet {
|
||||||
rules: rules.into(),
|
rules: rules.into(),
|
||||||
media: Arc::new(RwLock::new(media)),
|
media: Arc::new(RwLock::new(media)),
|
||||||
dirty_on_viewport_size_change: AtomicBool::new(input.seen_viewport_percentages()),
|
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) {
|
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
||||||
effective_rules(&self.rules.0.read(), device, &mut f);
|
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) {
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ fn test_parse_stylesheet() {
|
||||||
origin: Origin::UserAgent,
|
origin: Origin::UserAgent,
|
||||||
media: Default::default(),
|
media: Default::default(),
|
||||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||||
|
disabled: AtomicBool::new(false),
|
||||||
rules: vec![
|
rules: vec![
|
||||||
CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule {
|
CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule {
|
||||||
prefix: None,
|
prefix: None,
|
||||||
|
|
|
@ -114,9 +114,6 @@
|
||||||
[StyleSheet interface: attribute media]
|
[StyleSheet interface: attribute media]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[StyleSheet interface: attribute disabled]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[CSSStyleSheet interface: attribute ownerRule]
|
[CSSStyleSheet interface: attribute ownerRule]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -135,9 +132,6 @@
|
||||||
[StyleSheet interface: style_element.sheet must inherit property "media" with the proper type (5)]
|
[StyleSheet interface: style_element.sheet must inherit property "media" with the proper type (5)]
|
||||||
expected: FAIL
|
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]
|
[StyleSheetList interface: existence and properties of interface prototype object]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue