mirror of
https://github.com/servo/servo.git
synced 2025-06-20 07:08:59 +01: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
|
@ -502,7 +502,7 @@ unsafe impl JSTraceable for Mutex<Option<SharedRt>> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<FontFaceRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<FontFaceRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
@ -520,31 +520,31 @@ unsafe impl JSTraceable for RwLock<Keyframe> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<KeyframesRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<KeyframesRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<ImportRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<ImportRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<SupportsRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<SupportsRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<MediaRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<MediaRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<NamespaceRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<NamespaceRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ unsafe impl JSTraceable for RwLock<StyleRule> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<ViewportRule> {
|
||||
unsafe impl JSTraceable for StyleLocked<ViewportRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
|
|
@ -10,20 +10,19 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::font_face::FontFaceRule;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSFontFaceRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
fontfacerule: Arc<RwLock<FontFaceRule>>,
|
||||
fontfacerule: Arc<Locked<FontFaceRule>>,
|
||||
}
|
||||
|
||||
impl CSSFontFaceRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, fontfacerule: Arc<RwLock<FontFaceRule>>)
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, fontfacerule: Arc<Locked<FontFaceRule>>)
|
||||
-> CSSFontFaceRule {
|
||||
CSSFontFaceRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
|
@ -33,7 +32,7 @@ impl CSSFontFaceRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
fontfacerule: Arc<RwLock<FontFaceRule>>) -> Root<CSSFontFaceRule> {
|
||||
fontfacerule: Arc<Locked<FontFaceRule>>) -> Root<CSSFontFaceRule> {
|
||||
reflect_dom_object(box CSSFontFaceRule::new_inherited(parent_stylesheet, fontfacerule),
|
||||
window,
|
||||
CSSFontFaceRuleBinding::Wrap)
|
||||
|
@ -48,6 +47,6 @@ impl SpecificCSSRule for CSSFontFaceRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.fontfacerule.read().to_css_string(&guard).into()
|
||||
self.fontfacerule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,20 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::ImportRule;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSImportRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
import_rule: Arc<RwLock<ImportRule>>,
|
||||
import_rule: Arc<Locked<ImportRule>>,
|
||||
}
|
||||
|
||||
impl CSSImportRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet,
|
||||
import_rule: Arc<RwLock<ImportRule>>)
|
||||
import_rule: Arc<Locked<ImportRule>>)
|
||||
-> Self {
|
||||
CSSImportRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
|
@ -35,7 +34,7 @@ impl CSSImportRule {
|
|||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window,
|
||||
parent_stylesheet: &CSSStyleSheet,
|
||||
import_rule: Arc<RwLock<ImportRule>>) -> Root<Self> {
|
||||
import_rule: Arc<Locked<ImportRule>>) -> Root<Self> {
|
||||
reflect_dom_object(box Self::new_inherited(parent_stylesheet, import_rule),
|
||||
window,
|
||||
CSSImportRuleBinding::Wrap)
|
||||
|
@ -50,6 +49,6 @@ impl SpecificCSSRule for CSSImportRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.import_rule.read().to_css_string(&guard).into()
|
||||
self.import_rule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,24 +16,23 @@ use dom::cssrulelist::{CSSRuleList, RulesSource};
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use servo_atoms::Atom;
|
||||
use std::sync::Arc;
|
||||
use style::keyframes::{Keyframe, KeyframeSelector};
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::KeyframesRule;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSKeyframesRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
keyframesrule: Arc<RwLock<KeyframesRule>>,
|
||||
keyframesrule: Arc<Locked<KeyframesRule>>,
|
||||
rulelist: MutNullableJS<CSSRuleList>,
|
||||
}
|
||||
|
||||
impl CSSKeyframesRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, keyframesrule: Arc<RwLock<KeyframesRule>>)
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, keyframesrule: Arc<Locked<KeyframesRule>>)
|
||||
-> CSSKeyframesRule {
|
||||
CSSKeyframesRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
|
@ -44,7 +43,7 @@ impl CSSKeyframesRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
keyframesrule: Arc<RwLock<KeyframesRule>>) -> Root<CSSKeyframesRule> {
|
||||
keyframesrule: Arc<Locked<KeyframesRule>>) -> Root<CSSKeyframesRule> {
|
||||
reflect_dom_object(box CSSKeyframesRule::new_inherited(parent_stylesheet, keyframesrule),
|
||||
window,
|
||||
CSSKeyframesRuleBinding::Wrap)
|
||||
|
@ -63,9 +62,10 @@ impl CSSKeyframesRule {
|
|||
fn find_rule(&self, selector: &str) -> Option<usize> {
|
||||
let mut input = Parser::new(selector);
|
||||
if let Ok(sel) = KeyframeSelector::parse(&mut input) {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
// This finds the *last* element matching a selector
|
||||
// because that's the rule that applies. Thus, rposition
|
||||
self.keyframesrule.read()
|
||||
self.keyframesrule.read_with(&guard)
|
||||
.keyframes.iter().rposition(|frame| {
|
||||
frame.read().selector == sel
|
||||
})
|
||||
|
@ -86,7 +86,8 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
|||
let rule = Keyframe::parse(&rule, self.cssrule.parent_stylesheet().style_stylesheet(),
|
||||
ParserContextExtraData::default());
|
||||
if let Ok(rule) = rule {
|
||||
self.keyframesrule.write().keyframes.push(rule);
|
||||
let mut guard = self.cssrule.shared_lock().write();
|
||||
self.keyframesrule.write_with(&mut guard).keyframes.push(rule);
|
||||
self.rulelist().append_lazy_dom_rule();
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +108,8 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
|||
|
||||
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
|
||||
fn Name(&self) -> DOMString {
|
||||
DOMString::from(&*self.keyframesrule.read().name)
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
DOMString::from(&*self.keyframesrule.read_with(&guard).name)
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
|
||||
|
@ -122,7 +124,8 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule {
|
|||
"none" => return Err(Error::Syntax),
|
||||
_ => ()
|
||||
}
|
||||
self.keyframesrule.write().name = Atom::from(value);
|
||||
let mut guard = self.cssrule.shared_lock().write();
|
||||
self.keyframesrule.write_with(&mut guard).name = Atom::from(value);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +138,7 @@ impl SpecificCSSRule for CSSKeyframesRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.keyframesrule.read().to_css_string(&guard).into()
|
||||
self.keyframesrule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
|
||||
fn deparent_children(&self) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,20 +11,19 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::NamespaceRule;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSNamespaceRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
namespacerule: Arc<RwLock<NamespaceRule>>,
|
||||
namespacerule: Arc<Locked<NamespaceRule>>,
|
||||
}
|
||||
|
||||
impl CSSNamespaceRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, namespacerule: Arc<RwLock<NamespaceRule>>)
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, namespacerule: Arc<Locked<NamespaceRule>>)
|
||||
-> CSSNamespaceRule {
|
||||
CSSNamespaceRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
|
@ -34,7 +33,7 @@ impl CSSNamespaceRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
namespacerule: Arc<RwLock<NamespaceRule>>) -> Root<CSSNamespaceRule> {
|
||||
namespacerule: Arc<Locked<NamespaceRule>>) -> Root<CSSNamespaceRule> {
|
||||
reflect_dom_object(box CSSNamespaceRule::new_inherited(parent_stylesheet, namespacerule),
|
||||
window,
|
||||
CSSNamespaceRuleBinding::Wrap)
|
||||
|
@ -44,14 +43,16 @@ impl CSSNamespaceRule {
|
|||
impl CSSNamespaceRuleMethods for CSSNamespaceRule {
|
||||
// https://drafts.csswg.org/cssom/#dom-cssnamespacerule-prefix
|
||||
fn Prefix(&self) -> DOMString {
|
||||
self.namespacerule.read().prefix
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.namespacerule.read_with(&guard).prefix
|
||||
.as_ref().map(|s| s.to_string().into())
|
||||
.unwrap_or(DOMString::new())
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-cssnamespacerule-namespaceuri
|
||||
fn NamespaceURI(&self) -> DOMString {
|
||||
(*self.namespacerule.read().url).into()
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
(*self.namespacerule.read_with(&guard).url).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +64,6 @@ impl SpecificCSSRule for CSSNamespaceRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.namespacerule.read().to_css_string(&guard).into()
|
||||
self.namespacerule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ use dom::cssrule::CSSRule;
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::Locked;
|
||||
use style::stylesheets::{CssRules, KeyframesRule, RulesMutateError};
|
||||
|
@ -45,19 +44,19 @@ pub struct CSSRuleList {
|
|||
|
||||
pub enum RulesSource {
|
||||
Rules(Arc<Locked<CssRules>>),
|
||||
Keyframes(Arc<RwLock<KeyframesRule>>),
|
||||
Keyframes(Arc<Locked<KeyframesRule>>),
|
||||
}
|
||||
|
||||
impl CSSRuleList {
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new_inherited(parent_stylesheet: &CSSStyleSheet, rules: RulesSource) -> CSSRuleList {
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
let dom_rules = match rules {
|
||||
RulesSource::Rules(ref rules) => {
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
rules.read_with(&guard).0.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
}
|
||||
RulesSource::Keyframes(ref rules) => {
|
||||
rules.read().keyframes.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
rules.read_with(&guard).keyframes.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -104,10 +103,10 @@ impl CSSRuleList {
|
|||
// In case of a keyframe rule, index must be valid.
|
||||
pub fn remove_rule(&self, index: u32) -> ErrorResult {
|
||||
let index = index as usize;
|
||||
let mut guard = self.parent_stylesheet.shared_lock().write();
|
||||
|
||||
match self.rules {
|
||||
RulesSource::Rules(ref css_rules) => {
|
||||
let mut guard = self.parent_stylesheet.shared_lock().write();
|
||||
css_rules.write_with(&mut guard).remove_rule(index)?;
|
||||
let mut dom_rules = self.dom_rules.borrow_mut();
|
||||
dom_rules[index].get().map(|r| r.detach());
|
||||
|
@ -119,7 +118,7 @@ impl CSSRuleList {
|
|||
let mut dom_rules = self.dom_rules.borrow_mut();
|
||||
dom_rules[index].get().map(|r| r.detach());
|
||||
dom_rules.remove(index);
|
||||
kf.write().keyframes.remove(index);
|
||||
kf.write_with(&mut guard).keyframes.remove(index);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -136,9 +135,9 @@ impl CSSRuleList {
|
|||
self.dom_rules.borrow().get(idx as usize).map(|rule| {
|
||||
rule.or_init(|| {
|
||||
let parent_stylesheet = &self.parent_stylesheet;
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
match self.rules {
|
||||
RulesSource::Rules(ref rules) => {
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
CSSRule::new_specific(self.global().as_window(),
|
||||
parent_stylesheet,
|
||||
rules.read_with(&guard).0[idx as usize].clone())
|
||||
|
@ -146,7 +145,7 @@ impl CSSRuleList {
|
|||
RulesSource::Keyframes(ref rules) => {
|
||||
Root::upcast(CSSKeyframeRule::new(self.global().as_window(),
|
||||
parent_stylesheet,
|
||||
rules.read()
|
||||
rules.read_with(&guard)
|
||||
.keyframes[idx as usize]
|
||||
.clone()))
|
||||
}
|
||||
|
|
|
@ -13,10 +13,9 @@ use dom::cssrule::SpecificCSSRule;
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::parser::ParserContext;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::stylesheets::SupportsRule;
|
||||
use style::supports::SupportsCondition;
|
||||
use style_traits::ToCss;
|
||||
|
@ -25,13 +24,14 @@ use style_traits::ToCss;
|
|||
pub struct CSSSupportsRule {
|
||||
cssconditionrule: CSSConditionRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
supportsrule: Arc<RwLock<SupportsRule>>,
|
||||
supportsrule: Arc<Locked<SupportsRule>>,
|
||||
}
|
||||
|
||||
impl CSSSupportsRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, supportsrule: Arc<RwLock<SupportsRule>>)
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, supportsrule: Arc<Locked<SupportsRule>>)
|
||||
-> CSSSupportsRule {
|
||||
let list = supportsrule.read().rules.clone();
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
let list = supportsrule.read_with(&guard).rules.clone();
|
||||
CSSSupportsRule {
|
||||
cssconditionrule: CSSConditionRule::new_inherited(parent_stylesheet, list),
|
||||
supportsrule: supportsrule,
|
||||
|
@ -40,7 +40,7 @@ impl CSSSupportsRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
supportsrule: Arc<RwLock<SupportsRule>>) -> Root<CSSSupportsRule> {
|
||||
supportsrule: Arc<Locked<SupportsRule>>) -> Root<CSSSupportsRule> {
|
||||
reflect_dom_object(box CSSSupportsRule::new_inherited(parent_stylesheet, supportsrule),
|
||||
window,
|
||||
CSSSupportsRuleBinding::Wrap)
|
||||
|
@ -48,7 +48,8 @@ impl CSSSupportsRule {
|
|||
|
||||
/// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
|
||||
pub fn get_condition_text(&self) -> DOMString {
|
||||
let rule = self.supportsrule.read();
|
||||
let guard = self.cssconditionrule.shared_lock().read();
|
||||
let rule = self.supportsrule.read_with(&guard);
|
||||
rule.condition.to_css_string().into()
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,8 @@ impl CSSSupportsRule {
|
|||
let url = win.Document().url();
|
||||
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter());
|
||||
let enabled = cond.eval(&context);
|
||||
let mut rule = self.supportsrule.write();
|
||||
let mut guard = self.cssconditionrule.shared_lock().write();
|
||||
let rule = self.supportsrule.write_with(&mut guard);
|
||||
rule.condition = cond;
|
||||
rule.enabled = enabled;
|
||||
}
|
||||
|
@ -77,6 +79,6 @@ impl SpecificCSSRule for CSSSupportsRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssconditionrule.shared_lock().read();
|
||||
self.supportsrule.read().to_css_string(&guard).into()
|
||||
self.supportsrule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,19 @@ use dom::cssrule::{CSSRule, SpecificCSSRule};
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::ToCssWithGuard;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
use style::viewport::ViewportRule;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSViewportRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
viewportrule: Arc<RwLock<ViewportRule>>,
|
||||
viewportrule: Arc<Locked<ViewportRule>>,
|
||||
}
|
||||
|
||||
impl CSSViewportRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, viewportrule: Arc<RwLock<ViewportRule>>) -> CSSViewportRule {
|
||||
fn new_inherited(parent_stylesheet: &CSSStyleSheet, viewportrule: Arc<Locked<ViewportRule>>) -> CSSViewportRule {
|
||||
CSSViewportRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
viewportrule: viewportrule,
|
||||
|
@ -32,7 +31,7 @@ impl CSSViewportRule {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
|
||||
viewportrule: Arc<RwLock<ViewportRule>>) -> Root<CSSViewportRule> {
|
||||
viewportrule: Arc<Locked<ViewportRule>>) -> Root<CSSViewportRule> {
|
||||
reflect_dom_object(box CSSViewportRule::new_inherited(parent_stylesheet, viewportrule),
|
||||
window,
|
||||
CSSViewportRuleBinding::Wrap)
|
||||
|
@ -47,6 +46,6 @@ impl SpecificCSSRule for CSSViewportRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.viewportrule.read().to_css_string(&guard).into()
|
||||
self.viewportrule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ use dom::node::{Node, UnbindContext, document_from_node, window_from_node};
|
|||
use dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever_atoms::LocalName;
|
||||
use parking_lot::RwLock;
|
||||
use servo_config::prefs::PREFS;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::sync::Arc;
|
||||
|
@ -101,7 +100,7 @@ impl HTMLMetaElement {
|
|||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||
let document = self.upcast::<Node>().owner_doc();
|
||||
let shared_lock = document.style_shared_lock();
|
||||
let rule = CssRule::Viewport(Arc::new(RwLock::new(translated_rule)));
|
||||
let rule = CssRule::Viewport(Arc::new(shared_lock.wrap(translated_rule)));
|
||||
*self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet {
|
||||
rules: CssRules::new(vec![rule], shared_lock),
|
||||
origin: Origin::Author,
|
||||
|
|
|
@ -22,13 +22,13 @@ use ipc_channel::router::ROUTER;
|
|||
use net_traits::{FetchResponseListener, FetchMetadata, FilteredMetadata, Metadata, NetworkError, ReferrerPolicy};
|
||||
use net_traits::request::{CorsSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType};
|
||||
use network_listener::{NetworkListener, PreInvoke};
|
||||
use parking_lot::RwLock;
|
||||
use script_layout_interface::message::Msg;
|
||||
use servo_url::ServoUrl;
|
||||
use std::mem;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContextExtraData;
|
||||
use style::shared_lock::Locked as StyleLocked;
|
||||
use style::stylesheets::{ImportRule, Stylesheet, Origin};
|
||||
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||
|
||||
|
@ -55,15 +55,16 @@ pub trait StylesheetOwner {
|
|||
pub enum StylesheetContextSource {
|
||||
// NB: `media` is just an option so we avoid cloning it.
|
||||
LinkElement { media: Option<MediaList>, url: ServoUrl },
|
||||
Import(Arc<RwLock<ImportRule>>),
|
||||
Import(Arc<StyleLocked<ImportRule>>),
|
||||
}
|
||||
|
||||
impl StylesheetContextSource {
|
||||
fn url(&self) -> ServoUrl {
|
||||
fn url(&self, document: &Document) -> ServoUrl {
|
||||
match *self {
|
||||
StylesheetContextSource::LinkElement { ref url, .. } => url.clone(),
|
||||
StylesheetContextSource::Import(ref import) => {
|
||||
let import = import.read();
|
||||
let guard = document.style_shared_lock().read();
|
||||
let import = import.read_with(&guard);
|
||||
// Look at the parser in style::stylesheets, where we don't
|
||||
// trigger a load if the url is invalid.
|
||||
import.url.url()
|
||||
|
@ -174,9 +175,16 @@ impl FetchResponseListener for StylesheetContext {
|
|||
}
|
||||
}
|
||||
StylesheetContextSource::Import(ref import) => {
|
||||
let import = import.read();
|
||||
let mut guard = document.style_shared_lock().write();
|
||||
Stylesheet::update_from_bytes(&import.stylesheet,
|
||||
|
||||
// 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 stylesheet = Arc::clone(&import.write_with(&mut guard).stylesheet);
|
||||
|
||||
Stylesheet::update_from_bytes(&stylesheet,
|
||||
&data,
|
||||
protocol_encoding_label,
|
||||
Some(environment_encoding),
|
||||
|
@ -201,7 +209,7 @@ impl FetchResponseListener for StylesheetContext {
|
|||
document.decrement_script_blocking_stylesheet_count();
|
||||
}
|
||||
|
||||
let url = self.source.url();
|
||||
let url = self.source.url(&document);
|
||||
document.finish_load(LoadType::Stylesheet(url));
|
||||
|
||||
if let Some(any_failed) = owner.load_finished(successful) {
|
||||
|
@ -226,8 +234,8 @@ impl<'a> StylesheetLoader<'a> {
|
|||
impl<'a> StylesheetLoader<'a> {
|
||||
pub fn load(&self, source: StylesheetContextSource, cors_setting: Option<CorsSettings>,
|
||||
integrity_metadata: String) {
|
||||
let url = source.url();
|
||||
let document = document_from_node(self.elem);
|
||||
let url = source.url(&document);
|
||||
let gen = self.elem.downcast::<HTMLLinkElement>()
|
||||
.map(HTMLLinkElement::get_request_generation_id);
|
||||
let context = Arc::new(Mutex::new(StylesheetContext {
|
||||
|
@ -289,7 +297,7 @@ impl<'a> StylesheetLoader<'a> {
|
|||
}
|
||||
|
||||
impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
|
||||
fn request_stylesheet(&self, import: &Arc<RwLock<ImportRule>>) {
|
||||
fn request_stylesheet(&self, import: &Arc<StyleLocked<ImportRule>>) {
|
||||
//TODO (mrnayak) : Whether we should use the original loader's CORS setting?
|
||||
//Fix this when spec has more details.
|
||||
self.load(StylesheetContextSource::Import(import.clone()), None, "".to_owned())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue