Further changes required by Servo

This commit is contained in:
Oriol Brufau 2023-11-21 22:51:51 +01:00 committed by Martin Robinson
parent 6728158188
commit 68cbe6833d
4 changed files with 44 additions and 42 deletions

View file

@ -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<Locked<MediaRule>>,
mediarule: Arc<MediaRule>,
medialist: MutNullableDom<MediaList>,
}
impl CSSMediaRule {
fn new_inherited(
parent_stylesheet: &CSSStyleSheet,
mediarule: Arc<Locked<MediaRule>>,
) -> CSSMediaRule {
let guard = parent_stylesheet.shared_lock().read();
let list = mediarule.read_with(&guard).rules.clone();
fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc<MediaRule>) -> 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<Locked<MediaRule>>,
mediarule: Arc<MediaRule>,
) -> DomRoot<CSSMediaRule> {
reflect_dom_object(
Box::new(CSSMediaRule::new_inherited(parent_stylesheet, mediarule)),
@ -55,11 +51,10 @@ impl CSSMediaRule {
fn medialist(&self) -> DomRoot<MediaList> {
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 {
/// <https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface>
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()
}
}

View file

@ -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<Locked<NamespaceRule>>,
namespacerule: Arc<NamespaceRule>,
}
impl CSSNamespaceRule {
fn new_inherited(
parent_stylesheet: &CSSStyleSheet,
namespacerule: Arc<Locked<NamespaceRule>>,
namespacerule: Arc<NamespaceRule>,
) -> CSSNamespaceRule {
CSSNamespaceRule {
cssrule: CSSRule::new_inherited(parent_stylesheet),
@ -38,7 +38,7 @@ impl CSSNamespaceRule {
pub fn new(
window: &Window,
parent_stylesheet: &CSSStyleSheet,
namespacerule: Arc<Locked<NamespaceRule>>,
namespacerule: Arc<NamespaceRule>,
) -> DomRoot<CSSNamespaceRule> {
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()
}
}

View file

@ -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<Locked<SupportsRule>>,
supportsrule: Arc<SupportsRule>,
}
impl CSSSupportsRule {
fn new_inherited(
parent_stylesheet: &CSSStyleSheet,
supportsrule: Arc<Locked<SupportsRule>>,
supportsrule: Arc<SupportsRule>,
) -> 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<Locked<SupportsRule>>,
supportsrule: Arc<SupportsRule>,
) -> DomRoot<CSSSupportsRule> {
reflect_dom_object(
Box::new(CSSSupportsRule::new_inherited(
@ -54,9 +53,7 @@ impl CSSSupportsRule {
/// <https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface>
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()
}
}

View file

@ -209,6 +209,26 @@ pub struct Stylesheet {
}
macro_rules! rule_filter {
($( $method: ident($variant:ident => $rule_type: ident), )+) => {
$(
#[allow(missing_docs)]
fn $method<F>(&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),
}
}