Allow mutation of CssRules

This commit is contained in:
Manish Goregaokar 2016-11-14 15:37:48 -08:00
parent 71a2b379c8
commit 2fe390e237
5 changed files with 11 additions and 10 deletions

View file

@ -25,7 +25,7 @@ pub struct CSSRuleList {
impl CSSRuleList {
#[allow(unrooted_must_root)]
pub fn new_inherited(sheet: &CSSStyleSheet, rules: CssRules) -> CSSRuleList {
let dom_rules = rules.0.iter().map(|_| MutNullableHeap::new(None)).collect();
let dom_rules = rules.0.read().iter().map(|_| MutNullableHeap::new(None)).collect();
CSSRuleList {
reflector_: Reflector::new(),
sheet: JS::from_ref(sheet),
@ -49,7 +49,7 @@ impl CSSRuleListMethods for CSSRuleList {
rule.or_init(|| {
CSSRule::new_specific(self.global().as_window(),
&self.sheet,
self.rules.0[idx as usize].clone())
self.rules.0.read()[idx as usize].clone())
})
})
}

View file

@ -380,7 +380,7 @@ impl Stylist {
return true
}
}
mq_eval_changed(&rules, before, after)
mq_eval_changed(rules, before, after)
}) {
return true
}
@ -388,7 +388,7 @@ impl Stylist {
false
}
self.is_device_dirty |= stylesheets.iter().any(|stylesheet| {
mq_eval_changed(&stylesheet.rules.0, &self.device, &device)
mq_eval_changed(&stylesheet.rules.0.read(), &self.device, &device)
});
self.device = device;

View file

@ -43,11 +43,11 @@ pub enum Origin {
}
#[derive(Debug, Clone)]
pub struct CssRules(pub Arc<Vec<CssRule>>);
pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>);
impl From<Vec<CssRule>> for CssRules {
fn from(other: Vec<CssRule>) -> Self {
CssRules(Arc::new(other))
CssRules(Arc::new(RwLock::new(other)))
}
}
@ -100,7 +100,8 @@ impl CssRule {
CssRule::Media(ref lock) => {
let media_rule = lock.read();
let mq = media_rule.media_queries.read();
f(&media_rule.rules.0, Some(&mq))
let rules = media_rule.rules.0.read();
f(&rules, Some(&mq))
}
}
}
@ -254,7 +255,7 @@ impl Stylesheet {
/// examined.
#[inline]
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
effective_rules(&self.rules.0, device, &mut f);
effective_rules(&self.rules.0.read(), device, &mut f);
}
}

View file

@ -255,7 +255,7 @@ pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorr
#[no_mangle]
pub extern "C" fn Servo_StyleSheet_HasRules(raw_sheet: RawServoStyleSheetBorrowed) -> bool {
!Stylesheet::as_arc(&raw_sheet).rules.0.is_empty()
!Stylesheet::as_arc(&raw_sheet).rules.0.read().is_empty()
}
#[no_mangle]

View file

@ -29,7 +29,7 @@ fn test_media_rule<F>(css: &str, callback: F) where F: Fn(&MediaList, &str) {
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
ParserContextExtraData::default());
let mut rule_count = 0;
media_queries(&stylesheet.rules.0, &mut |mq| {
media_queries(&stylesheet.rules.0.read(), &mut |mq| {
rule_count += 1;
callback(mq, css);
});