Skip to content

Commit e4a7301

Browse files
committed
Further changes required by Servo
1 parent 680381a commit e4a7301

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

components/script/dom/cssmediarule.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use dom_struct::dom_struct;
66
use servo_arc::Arc;
7-
use style::shared_lock::{Locked, ToCssWithGuard};
7+
use style::shared_lock::ToCssWithGuard;
88
use style::stylesheets::MediaRule;
99
use style_traits::ToCss;
1010

@@ -23,17 +23,13 @@ pub struct CSSMediaRule {
2323
cssconditionrule: CSSConditionRule,
2424
#[ignore_malloc_size_of = "Arc"]
2525
#[no_trace]
26-
mediarule: Arc<Locked<MediaRule>>,
26+
mediarule: Arc<MediaRule>,
2727
medialist: MutNullableDom<MediaList>,
2828
}
2929

3030
impl CSSMediaRule {
31-
fn new_inherited(
32-
parent_stylesheet: &CSSStyleSheet,
33-
mediarule: Arc<Locked<MediaRule>>,
34-
) -> CSSMediaRule {
35-
let guard = parent_stylesheet.shared_lock().read();
36-
let list = mediarule.read_with(&guard).rules.clone();
31+
fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc<MediaRule>) -> CSSMediaRule {
32+
let list = mediarule.rules.clone();
3733
CSSMediaRule {
3834
cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
3935
mediarule: mediarule,
@@ -45,7 +41,7 @@ impl CSSMediaRule {
4541
pub fn new(
4642
window: &Window,
4743
parent_stylesheet: &CSSStyleSheet,
48-
mediarule: Arc<Locked<MediaRule>>,
44+
mediarule: Arc<MediaRule>,
4945
) -> DomRoot<CSSMediaRule> {
5046
reflect_dom_object(
5147
Box::new(CSSMediaRule::new_inherited(parent_stylesheet, mediarule)),
@@ -55,20 +51,18 @@ impl CSSMediaRule {
5551

5652
fn medialist(&self) -> DomRoot<MediaList> {
5753
self.medialist.or_init(|| {
58-
let guard = self.cssconditionrule.shared_lock().read();
5954
MediaList::new(
6055
self.global().as_window(),
6156
self.cssconditionrule.parent_stylesheet(),
62-
self.mediarule.read_with(&guard).media_queries.clone(),
57+
self.mediarule.media_queries.clone(),
6358
)
6459
})
6560
}
6661

6762
/// <https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface>
6863
pub fn get_condition_text(&self) -> DOMString {
6964
let guard = self.cssconditionrule.shared_lock().read();
70-
let rule = self.mediarule.read_with(&guard);
71-
let list = rule.media_queries.read_with(&guard);
65+
let list = self.mediarule.media_queries.read_with(&guard);
7266
list.to_css_string().into()
7367
}
7468
}
@@ -81,10 +75,7 @@ impl SpecificCSSRule for CSSMediaRule {
8175

8276
fn get_css(&self) -> DOMString {
8377
let guard = self.cssconditionrule.shared_lock().read();
84-
self.mediarule
85-
.read_with(&guard)
86-
.to_css_string(&guard)
87-
.into()
78+
self.mediarule.to_css_string(&guard).into()
8879
}
8980
}
9081

components/script/dom/cssnamespacerule.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use dom_struct::dom_struct;
66
use servo_arc::Arc;
7-
use style::shared_lock::{Locked, ToCssWithGuard};
7+
use style::shared_lock::ToCssWithGuard;
88
use style::stylesheets::NamespaceRule;
99

1010
use crate::dom::bindings::codegen::Bindings::CSSNamespaceRuleBinding::CSSNamespaceRuleMethods;
@@ -20,13 +20,13 @@ pub struct CSSNamespaceRule {
2020
cssrule: CSSRule,
2121
#[ignore_malloc_size_of = "Arc"]
2222
#[no_trace]
23-
namespacerule: Arc<Locked<NamespaceRule>>,
23+
namespacerule: Arc<NamespaceRule>,
2424
}
2525

2626
impl CSSNamespaceRule {
2727
fn new_inherited(
2828
parent_stylesheet: &CSSStyleSheet,
29-
namespacerule: Arc<Locked<NamespaceRule>>,
29+
namespacerule: Arc<NamespaceRule>,
3030
) -> CSSNamespaceRule {
3131
CSSNamespaceRule {
3232
cssrule: CSSRule::new_inherited(parent_stylesheet),
@@ -38,7 +38,7 @@ impl CSSNamespaceRule {
3838
pub fn new(
3939
window: &Window,
4040
parent_stylesheet: &CSSStyleSheet,
41-
namespacerule: Arc<Locked<NamespaceRule>>,
41+
namespacerule: Arc<NamespaceRule>,
4242
) -> DomRoot<CSSNamespaceRule> {
4343
reflect_dom_object(
4444
Box::new(CSSNamespaceRule::new_inherited(
@@ -53,9 +53,7 @@ impl CSSNamespaceRule {
5353
impl CSSNamespaceRuleMethods for CSSNamespaceRule {
5454
// https://drafts.csswg.org/cssom/#dom-cssnamespacerule-prefix
5555
fn Prefix(&self) -> DOMString {
56-
let guard = self.cssrule.shared_lock().read();
5756
self.namespacerule
58-
.read_with(&guard)
5957
.prefix
6058
.as_ref()
6159
.map(|s| s.to_string().into())
@@ -64,8 +62,7 @@ impl CSSNamespaceRuleMethods for CSSNamespaceRule {
6462

6563
// https://drafts.csswg.org/cssom/#dom-cssnamespacerule-namespaceuri
6664
fn NamespaceURI(&self) -> DOMString {
67-
let guard = self.cssrule.shared_lock().read();
68-
(**self.namespacerule.read_with(&guard).url).into()
65+
(**self.namespacerule.url).into()
6966
}
7067
}
7168

@@ -77,9 +74,6 @@ impl SpecificCSSRule for CSSNamespaceRule {
7774

7875
fn get_css(&self) -> DOMString {
7976
let guard = self.cssrule.shared_lock().read();
80-
self.namespacerule
81-
.read_with(&guard)
82-
.to_css_string(&guard)
83-
.into()
77+
self.namespacerule.to_css_string(&guard).into()
8478
}
8579
}

components/script/dom/csssupportsrule.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use dom_struct::dom_struct;
66
use servo_arc::Arc;
7-
use style::shared_lock::{Locked, ToCssWithGuard};
7+
use style::shared_lock::ToCssWithGuard;
88
use style::stylesheets::SupportsRule;
99
use style_traits::ToCss;
1010

@@ -21,16 +21,15 @@ pub struct CSSSupportsRule {
2121
cssconditionrule: CSSConditionRule,
2222
#[ignore_malloc_size_of = "Arc"]
2323
#[no_trace]
24-
supportsrule: Arc<Locked<SupportsRule>>,
24+
supportsrule: Arc<SupportsRule>,
2525
}
2626

2727
impl CSSSupportsRule {
2828
fn new_inherited(
2929
parent_stylesheet: &CSSStyleSheet,
30-
supportsrule: Arc<Locked<SupportsRule>>,
30+
supportsrule: Arc<SupportsRule>,
3131
) -> CSSSupportsRule {
32-
let guard = parent_stylesheet.shared_lock().read();
33-
let list = supportsrule.read_with(&guard).rules.clone();
32+
let list = supportsrule.rules.clone();
3433
CSSSupportsRule {
3534
cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
3635
supportsrule: supportsrule,
@@ -41,7 +40,7 @@ impl CSSSupportsRule {
4140
pub fn new(
4241
window: &Window,
4342
parent_stylesheet: &CSSStyleSheet,
44-
supportsrule: Arc<Locked<SupportsRule>>,
43+
supportsrule: Arc<SupportsRule>,
4544
) -> DomRoot<CSSSupportsRule> {
4645
reflect_dom_object(
4746
Box::new(CSSSupportsRule::new_inherited(
@@ -54,9 +53,7 @@ impl CSSSupportsRule {
5453

5554
/// <https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface>
5655
pub fn get_condition_text(&self) -> DOMString {
57-
let guard = self.cssconditionrule.shared_lock().read();
58-
let rule = self.supportsrule.read_with(&guard);
59-
rule.condition.to_css_string().into()
56+
self.supportsrule.condition.to_css_string().into()
6057
}
6158
}
6259

@@ -68,9 +65,6 @@ impl SpecificCSSRule for CSSSupportsRule {
6865

6966
fn get_css(&self) -> DOMString {
7067
let guard = self.cssconditionrule.shared_lock().read();
71-
self.supportsrule
72-
.read_with(&guard)
73-
.to_css_string(&guard)
74-
.into()
68+
self.supportsrule.to_css_string(&guard).into()
7569
}
7670
}

components/style/stylesheets/stylesheet.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ pub struct Stylesheet {
209209
}
210210

211211
macro_rules! rule_filter {
212+
($( $method: ident($variant:ident => $rule_type: ident), )+) => {
213+
$(
214+
#[allow(missing_docs)]
215+
fn $method<F>(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F)
216+
where F: FnMut(&crate::stylesheets::$rule_type),
217+
{
218+
use crate::stylesheets::CssRule;
219+
220+
for rule in self.effective_rules(device, guard) {
221+
if let CssRule::$variant(ref lock) = *rule {
222+
let rule = lock.read_with(guard);
223+
f(&rule)
224+
}
225+
}
226+
}
227+
)+
228+
}
229+
}
230+
231+
macro_rules! rule_filter_for_non_locked {
212232
($( $method: ident($variant:ident => $rule_type: ident), )+) => {
213233
$(
214234
#[allow(missing_docs)]
@@ -283,6 +303,9 @@ pub trait StylesheetInDocument: ::std::fmt::Debug {
283303

284304
rule_filter! {
285305
effective_font_face_rules(FontFace => FontFaceRule),
306+
}
307+
308+
rule_filter_for_non_locked! {
286309
effective_viewport_rules(Viewport => ViewportRule),
287310
}
288311
}

0 commit comments

Comments
 (0)