Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable CSSOM #14190

Merged
merged 6 commits into from Nov 16, 2016
Merged

Allow mutation of CssRules

  • Loading branch information
Manishearth committed Nov 15, 2016
commit 2fe390e2375dc327e6c598f30155ed3f33d81882
@@ -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())
})
})
}
@@ -380,15 +380,15 @@ impl Stylist {
return true
}
}
mq_eval_changed(&rules, before, after)
mq_eval_changed(rules, before, after)
}) {
return true
}
}
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;
@@ -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);
}
}

@@ -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]
@@ -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);
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.