mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Wrap most CSS rules in Locked<_> instead of RwLock<_>
This commit is contained in:
parent
f35b4e27b3
commit
adb97d4cbe
17 changed files with 194 additions and 139 deletions
|
@ -14,10 +14,9 @@ use dom::cssstylesheet::CSSStyleSheet;
|
|||
use dom::medialist::MediaList;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::media_queries::parse_media_query_list;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::MediaRule;
|
||||
use style_traits::ToCss;
|
||||
|
||||
|
@ -25,14 +24,15 @@ use style_traits::ToCss;
|
|||
pub struct CSSMediaRule {
|
||||
cssconditionrule: CSSConditionRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
mediarule: Arc<RwLock<MediaRule>>,
|
||||
mediarule: Arc<Locked<MediaRule>>,
|
||||
medialist: MutNullableJS<MediaList>,
|
||||
}
|
||||
|
||||
impl CSSMediaRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc<RwLock<MediaRule>>)
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc<Locked<MediaRule>>)
|
||||
-> CSSMediaRule {
|
||||
let list = mediarule.read().rules.clone();
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
let list = mediarule.read_with(&guard).rules.clone();
|
||||
CSSMediaRule {
|
||||
cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
|
||||
mediarule: mediarule,
|
||||
|
@ -42,34 +42,43 @@ impl CSSMediaRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
mediarule: Arc<RwLock<MediaRule>>) -> Root<CSSMediaRule> {
|
||||
mediarule: Arc<Locked<MediaRule>>) -> Root<CSSMediaRule> {
|
||||
reflect_dom_object(box CSSMediaRule::new_inherited(parent_stylesheet, mediarule),
|
||||
window,
|
||||
CSSMediaRuleBinding::Wrap)
|
||||
}
|
||||
|
||||
fn medialist(&self) -> Root<MediaList> {
|
||||
self.medialist.or_init(|| MediaList::new(self.global().as_window(),
|
||||
self.cssconditionrule.parent_stylesheet(),
|
||||
self.mediarule.read().media_queries.clone()))
|
||||
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())
|
||||
})
|
||||
}
|
||||
|
||||
/// 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();
|
||||
let rule = self.mediarule.read_with(&guard);
|
||||
let list = rule.media_queries.read_with(&guard);
|
||||
list.to_css_string().into()
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface
|
||||
pub fn set_condition_text(&self, text: DOMString) {
|
||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||
let mut input = Parser::new(&text);
|
||||
let new_medialist = parse_media_query_list(&mut input);
|
||||
let rule = self.mediarule.read();
|
||||
let mut list = rule.media_queries.write_with(&mut guard);
|
||||
*list = new_medialist;
|
||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||
|
||||
// Clone an Arc because we can’t borrow `guard` twice at the same time.
|
||||
|
||||
// FIXME(SimonSapin): allow access to multiple objects with one write guard?
|
||||
// Would need a set of usize pointer addresses or something,
|
||||
// the same object is not accessed more than once.
|
||||
let mqs = Arc::clone(&self.mediarule.write_with(&mut guard).media_queries);
|
||||
|
||||
*mqs.write_with(&mut guard) = new_medialist;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +90,7 @@ impl SpecificCSSRule for CSSMediaRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssconditionrule.shared_lock().read();
|
||||
self.mediarule.read().to_css_string(&guard).into()
|
||||
self.mediarule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue