diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index 50456680193..808c988add8 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -4,7 +4,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; -use style::shared_lock::{Locked, ToCssWithGuard}; +use style::shared_lock::ToCssWithGuard; use style::stylesheets::MediaRule; use style_traits::ToCss; @@ -23,17 +23,13 @@ pub struct CSSMediaRule { cssconditionrule: CSSConditionRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] - mediarule: Arc>, + mediarule: Arc, medialist: MutNullableDom, } impl CSSMediaRule { - fn new_inherited( - parent_stylesheet: &CSSStyleSheet, - mediarule: Arc>, - ) -> CSSMediaRule { - let guard = parent_stylesheet.shared_lock().read(); - let list = mediarule.read_with(&guard).rules.clone(); + fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc) -> CSSMediaRule { + let list = mediarule.rules.clone(); CSSMediaRule { cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list), mediarule: mediarule, @@ -45,7 +41,7 @@ impl CSSMediaRule { pub fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, - mediarule: Arc>, + mediarule: Arc, ) -> DomRoot { reflect_dom_object( Box::new(CSSMediaRule::new_inherited(parent_stylesheet, mediarule)), @@ -55,11 +51,10 @@ impl CSSMediaRule { fn medialist(&self) -> DomRoot { self.medialist.or_init(|| { - let guard = self.cssconditionrule.shared_lock().read(); MediaList::new( self.global().as_window(), self.cssconditionrule.parent_stylesheet(), - self.mediarule.read_with(&guard).media_queries.clone(), + self.mediarule.media_queries.clone(), ) }) } @@ -67,8 +62,7 @@ impl CSSMediaRule { /// pub fn get_condition_text(&self) -> DOMString { let guard = self.cssconditionrule.shared_lock().read(); - let rule = self.mediarule.read_with(&guard); - let list = rule.media_queries.read_with(&guard); + let list = self.mediarule.media_queries.read_with(&guard); list.to_css_string().into() } } @@ -81,10 +75,7 @@ impl SpecificCSSRule for CSSMediaRule { fn get_css(&self) -> DOMString { let guard = self.cssconditionrule.shared_lock().read(); - self.mediarule - .read_with(&guard) - .to_css_string(&guard) - .into() + self.mediarule.to_css_string(&guard).into() } } diff --git a/components/script/dom/cssnamespacerule.rs b/components/script/dom/cssnamespacerule.rs index 173adc54a1a..cd648e1338c 100644 --- a/components/script/dom/cssnamespacerule.rs +++ b/components/script/dom/cssnamespacerule.rs @@ -4,7 +4,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; -use style::shared_lock::{Locked, ToCssWithGuard}; +use style::shared_lock::ToCssWithGuard; use style::stylesheets::NamespaceRule; use crate::dom::bindings::codegen::Bindings::CSSNamespaceRuleBinding::CSSNamespaceRuleMethods; @@ -20,13 +20,13 @@ pub struct CSSNamespaceRule { cssrule: CSSRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] - namespacerule: Arc>, + namespacerule: Arc, } impl CSSNamespaceRule { fn new_inherited( parent_stylesheet: &CSSStyleSheet, - namespacerule: Arc>, + namespacerule: Arc, ) -> CSSNamespaceRule { CSSNamespaceRule { cssrule: CSSRule::new_inherited(parent_stylesheet), @@ -38,7 +38,7 @@ impl CSSNamespaceRule { pub fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, - namespacerule: Arc>, + namespacerule: Arc, ) -> DomRoot { reflect_dom_object( Box::new(CSSNamespaceRule::new_inherited( @@ -53,9 +53,7 @@ impl CSSNamespaceRule { impl CSSNamespaceRuleMethods for CSSNamespaceRule { // https://drafts.csswg.org/cssom/#dom-cssnamespacerule-prefix fn Prefix(&self) -> DOMString { - let guard = self.cssrule.shared_lock().read(); self.namespacerule - .read_with(&guard) .prefix .as_ref() .map(|s| s.to_string().into()) @@ -64,8 +62,7 @@ impl CSSNamespaceRuleMethods for CSSNamespaceRule { // https://drafts.csswg.org/cssom/#dom-cssnamespacerule-namespaceuri fn NamespaceURI(&self) -> DOMString { - let guard = self.cssrule.shared_lock().read(); - (**self.namespacerule.read_with(&guard).url).into() + (**self.namespacerule.url).into() } } @@ -77,9 +74,6 @@ impl SpecificCSSRule for CSSNamespaceRule { fn get_css(&self) -> DOMString { let guard = self.cssrule.shared_lock().read(); - self.namespacerule - .read_with(&guard) - .to_css_string(&guard) - .into() + self.namespacerule.to_css_string(&guard).into() } } diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index 3c9b4e48647..53714358b39 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -4,7 +4,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; -use style::shared_lock::{Locked, ToCssWithGuard}; +use style::shared_lock::ToCssWithGuard; use style::stylesheets::SupportsRule; use style_traits::ToCss; @@ -21,16 +21,15 @@ pub struct CSSSupportsRule { cssconditionrule: CSSConditionRule, #[ignore_malloc_size_of = "Arc"] #[no_trace] - supportsrule: Arc>, + supportsrule: Arc, } impl CSSSupportsRule { fn new_inherited( parent_stylesheet: &CSSStyleSheet, - supportsrule: Arc>, + supportsrule: Arc, ) -> CSSSupportsRule { - let guard = parent_stylesheet.shared_lock().read(); - let list = supportsrule.read_with(&guard).rules.clone(); + let list = supportsrule.rules.clone(); CSSSupportsRule { cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list), supportsrule: supportsrule, @@ -41,7 +40,7 @@ impl CSSSupportsRule { pub fn new( window: &Window, parent_stylesheet: &CSSStyleSheet, - supportsrule: Arc>, + supportsrule: Arc, ) -> DomRoot { reflect_dom_object( Box::new(CSSSupportsRule::new_inherited( @@ -54,9 +53,7 @@ impl CSSSupportsRule { /// pub fn get_condition_text(&self) -> DOMString { - let guard = self.cssconditionrule.shared_lock().read(); - let rule = self.supportsrule.read_with(&guard); - rule.condition.to_css_string().into() + self.supportsrule.condition.to_css_string().into() } } @@ -68,9 +65,6 @@ impl SpecificCSSRule for CSSSupportsRule { fn get_css(&self) -> DOMString { let guard = self.cssconditionrule.shared_lock().read(); - self.supportsrule - .read_with(&guard) - .to_css_string(&guard) - .into() + self.supportsrule.to_css_string(&guard).into() } } diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index 2f0cbdcdfbb..3994e5cab68 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -209,6 +209,26 @@ pub struct Stylesheet { } macro_rules! rule_filter { + ($( $method: ident($variant:ident => $rule_type: ident), )+) => { + $( + #[allow(missing_docs)] + fn $method(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F) + where F: FnMut(&crate::stylesheets::$rule_type), + { + use crate::stylesheets::CssRule; + + for rule in self.effective_rules(device, guard) { + if let CssRule::$variant(ref lock) = *rule { + let rule = lock.read_with(guard); + f(&rule) + } + } + } + )+ + } +} + +macro_rules! rule_filter_for_non_locked { ($( $method: ident($variant:ident => $rule_type: ident), )+) => { $( #[allow(missing_docs)] @@ -283,6 +303,9 @@ pub trait StylesheetInDocument: ::std::fmt::Debug { rule_filter! { effective_font_face_rules(FontFace => FontFaceRule), + } + + rule_filter_for_non_locked! { effective_viewport_rules(Viewport => ViewportRule), } }