mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Allow mutation of CssRules
This commit is contained in:
parent
71a2b379c8
commit
2fe390e237
5 changed files with 11 additions and 10 deletions
|
@ -25,7 +25,7 @@ pub struct CSSRuleList {
|
||||||
impl CSSRuleList {
|
impl CSSRuleList {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new_inherited(sheet: &CSSStyleSheet, rules: CssRules) -> CSSRuleList {
|
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 {
|
CSSRuleList {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
sheet: JS::from_ref(sheet),
|
sheet: JS::from_ref(sheet),
|
||||||
|
@ -49,7 +49,7 @@ impl CSSRuleListMethods for CSSRuleList {
|
||||||
rule.or_init(|| {
|
rule.or_init(|| {
|
||||||
CSSRule::new_specific(self.global().as_window(),
|
CSSRule::new_specific(self.global().as_window(),
|
||||||
&self.sheet,
|
&self.sheet,
|
||||||
self.rules.0[idx as usize].clone())
|
self.rules.0.read()[idx as usize].clone())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,7 @@ impl Stylist {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mq_eval_changed(&rules, before, after)
|
mq_eval_changed(rules, before, after)
|
||||||
}) {
|
}) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ impl Stylist {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
self.is_device_dirty |= stylesheets.iter().any(|stylesheet| {
|
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;
|
self.device = device;
|
||||||
|
|
|
@ -43,11 +43,11 @@ pub enum Origin {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CssRules(pub Arc<Vec<CssRule>>);
|
pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>);
|
||||||
|
|
||||||
impl From<Vec<CssRule>> for CssRules {
|
impl From<Vec<CssRule>> for CssRules {
|
||||||
fn from(other: Vec<CssRule>) -> Self {
|
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) => {
|
CssRule::Media(ref lock) => {
|
||||||
let media_rule = lock.read();
|
let media_rule = lock.read();
|
||||||
let mq = media_rule.media_queries.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.
|
/// examined.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSheet_HasRules(raw_sheet: RawServoStyleSheetBorrowed) -> bool {
|
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]
|
#[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),
|
let stylesheet = Stylesheet::from_str(css, url, Origin::Author, Box::new(CSSErrorReporterTest),
|
||||||
ParserContextExtraData::default());
|
ParserContextExtraData::default());
|
||||||
let mut rule_count = 0;
|
let mut rule_count = 0;
|
||||||
media_queries(&stylesheet.rules.0, &mut |mq| {
|
media_queries(&stylesheet.rules.0.read(), &mut |mq| {
|
||||||
rule_count += 1;
|
rule_count += 1;
|
||||||
callback(mq, css);
|
callback(mq, css);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue