Invalidate and flush shadow tree stylesheets where needed

This commit is contained in:
Fernando Jiménez Moreno 2019-02-13 17:01:30 +01:00
parent 18c1b8f690
commit 519cc2c317
8 changed files with 115 additions and 25 deletions

View file

@ -6,11 +6,13 @@ use crate::dom::bindings::codegen::Bindings::CSSStyleSheetBinding;
use crate::dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheetMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::cssrulelist::{CSSRuleList, RulesSource};
use crate::dom::element::Element;
use crate::dom::node::{shadow_root_from_node, Node};
use crate::dom::stylesheet::StyleSheet;
use crate::dom::window::Window;
use dom_struct::dom_struct;
@ -64,6 +66,10 @@ impl CSSStyleSheet {
)
}
pub fn owner(&self) -> DomRoot<Element> {
DomRoot::from_ref(&*self.owner)
}
fn rulelist(&self) -> DomRoot<CSSRuleList> {
self.rulelist.or_init(|| {
let rules = self.style_stylesheet.contents.rules.clone();
@ -81,10 +87,14 @@ impl CSSStyleSheet {
pub fn set_disabled(&self, disabled: bool) {
if self.style_stylesheet.set_disabled(disabled) {
self.global()
.as_window()
.Document()
.invalidate_stylesheets();
if let Some(shadow_root) = shadow_root_from_node(self.owner.upcast::<Node>()) {
shadow_root.invalidate_stylesheets();
} else {
self.global()
.as_window()
.Document()
.invalidate_stylesheets();
}
}
}