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
|
@ -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())
|
||||
|
|
|
@ -51,10 +51,21 @@ impl_arc_ffi!(ComputedValues => ServoComputedValues
|
|||
impl_arc_ffi!(RwLock<PropertyDeclarationBlock> => RawServoDeclarationBlock
|
||||
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
|
||||
|
||||
/// FIXME: Remove once StyleRule is actually in Locked<_>
|
||||
pub trait HackHackHack {
|
||||
fn as_arc<'a>(ptr: &'a &RawServoStyleRule) -> &'a ::std::sync::Arc<RwLock<StyleRule>>;
|
||||
}
|
||||
|
||||
impl HackHackHack for Locked<StyleRule> {
|
||||
fn as_arc<'a>(ptr: &'a &RawServoStyleRule) -> &'a ::std::sync::Arc<RwLock<StyleRule>> {
|
||||
RwLock::<StyleRule>::as_arc(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
impl_arc_ffi!(RwLock<StyleRule> => RawServoStyleRule
|
||||
[Servo_StyleRule_AddRef, Servo_StyleRule_Release]);
|
||||
|
||||
impl_arc_ffi!(RwLock<ImportRule> => RawServoImportRule
|
||||
impl_arc_ffi!(Locked<ImportRule> => RawServoImportRule
|
||||
[Servo_ImportRule_AddRef, Servo_ImportRule_Release]);
|
||||
|
||||
impl_arc_ffi!(AnimationValue => RawServoAnimationValue
|
||||
|
@ -66,8 +77,8 @@ impl_arc_ffi!(RwLock<AnimationValueMap> => RawServoAnimationValueMap
|
|||
impl_arc_ffi!(Locked<MediaList> => RawServoMediaList
|
||||
[Servo_MediaList_AddRef, Servo_MediaList_Release]);
|
||||
|
||||
impl_arc_ffi!(RwLock<MediaRule> => RawServoMediaRule
|
||||
impl_arc_ffi!(Locked<MediaRule> => RawServoMediaRule
|
||||
[Servo_MediaRule_AddRef, Servo_MediaRule_Release]);
|
||||
|
||||
impl_arc_ffi!(RwLock<NamespaceRule> => RawServoNamespaceRule
|
||||
impl_arc_ffi!(Locked<NamespaceRule> => RawServoNamespaceRule
|
||||
[Servo_NamespaceRule_AddRef, Servo_NamespaceRule_Release]);
|
||||
|
|
|
@ -213,14 +213,14 @@ pub enum CssRule {
|
|||
// No Charset here, CSSCharsetRule has been removed from CSSOM
|
||||
// https://drafts.csswg.org/cssom/#changes-from-5-december-2013
|
||||
|
||||
Namespace(Arc<RwLock<NamespaceRule>>),
|
||||
Import(Arc<RwLock<ImportRule>>),
|
||||
Namespace(Arc<Locked<NamespaceRule>>),
|
||||
Import(Arc<Locked<ImportRule>>),
|
||||
Style(Arc<RwLock<StyleRule>>),
|
||||
Media(Arc<RwLock<MediaRule>>),
|
||||
FontFace(Arc<RwLock<FontFaceRule>>),
|
||||
Viewport(Arc<RwLock<ViewportRule>>),
|
||||
Keyframes(Arc<RwLock<KeyframesRule>>),
|
||||
Supports(Arc<RwLock<SupportsRule>>),
|
||||
Media(Arc<Locked<MediaRule>>),
|
||||
FontFace(Arc<Locked<FontFaceRule>>),
|
||||
Viewport(Arc<Locked<ViewportRule>>),
|
||||
Keyframes(Arc<Locked<KeyframesRule>>),
|
||||
Supports(Arc<Locked<SupportsRule>>),
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
|
@ -301,7 +301,7 @@ impl CssRule {
|
|||
where F: FnMut(&[CssRule], Option<&MediaList>) -> R {
|
||||
match *self {
|
||||
CssRule::Import(ref lock) => {
|
||||
let rule = lock.read();
|
||||
let rule = lock.read_with(guard);
|
||||
let media = rule.stylesheet.media.read_with(guard);
|
||||
let rules = rule.stylesheet.rules.read_with(guard);
|
||||
// FIXME(emilio): Include the nested rules if the stylesheet is
|
||||
|
@ -316,13 +316,13 @@ impl CssRule {
|
|||
f(&[], None)
|
||||
}
|
||||
CssRule::Media(ref lock) => {
|
||||
let media_rule = lock.read();
|
||||
let media_rule = lock.read_with(guard);
|
||||
let mq = media_rule.media_queries.read_with(guard);
|
||||
let rules = &media_rule.rules.read_with(guard).0;
|
||||
f(rules, Some(&mq))
|
||||
}
|
||||
CssRule::Supports(ref lock) => {
|
||||
let supports_rule = lock.read();
|
||||
let supports_rule = lock.read_with(guard);
|
||||
let enabled = supports_rule.enabled;
|
||||
if enabled {
|
||||
let rules = &supports_rule.rules.read_with(guard).0;
|
||||
|
@ -378,14 +378,14 @@ impl ToCssWithGuard for CssRule {
|
|||
fn to_css<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write {
|
||||
match *self {
|
||||
CssRule::Namespace(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Import(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Namespace(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Import(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Style(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::FontFace(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Viewport(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Keyframes(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Media(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::Supports(ref lock) => lock.read().to_css(guard, dest),
|
||||
CssRule::FontFace(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Viewport(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Keyframes(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Media(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
CssRule::Supports(ref lock) => lock.read_with(guard).to_css(guard, dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ macro_rules! rule_filter {
|
|||
where F: FnMut(&$rule_type) {
|
||||
self.effective_rules(device, guard, |rule| {
|
||||
if let CssRule::$variant(ref lock) = *rule {
|
||||
let rule = lock.read();
|
||||
let rule = lock.read_with(guard);
|
||||
f(&rule)
|
||||
}
|
||||
})
|
||||
|
@ -736,6 +736,18 @@ rule_filter! {
|
|||
effective_supports_rules(Supports => SupportsRule),
|
||||
}
|
||||
|
||||
/// FIXME: Remove once StyleRule is actually in Locked<_>
|
||||
pub trait RwLockStyleRulePretendLockedStyleRule<T> {
|
||||
/// Pretend we’re Locked<_>
|
||||
fn read_with(&self, guard: &SharedRwLockReadGuard) -> ::parking_lot::RwLockReadGuard<T>;
|
||||
}
|
||||
|
||||
impl RwLockStyleRulePretendLockedStyleRule<StyleRule> for RwLock<StyleRule> {
|
||||
fn read_with(&self, _: &SharedRwLockReadGuard) -> ::parking_lot::RwLockReadGuard<StyleRule> {
|
||||
self.read()
|
||||
}
|
||||
}
|
||||
|
||||
/// The stylesheet loader is the abstraction used to trigger network requests
|
||||
/// for `@import` rules.
|
||||
pub trait StylesheetLoader {
|
||||
|
@ -743,7 +755,7 @@ pub trait StylesheetLoader {
|
|||
///
|
||||
/// The called code is responsible to update the `stylesheet` rules field
|
||||
/// when the sheet is done loading.
|
||||
fn request_stylesheet(&self, import: &Arc<RwLock<ImportRule>>);
|
||||
fn request_stylesheet(&self, import: &Arc<Locked<ImportRule>>);
|
||||
}
|
||||
|
||||
struct TopLevelRuleParser<'a> {
|
||||
|
@ -811,7 +823,7 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
|||
|
||||
let is_valid_url = url.url().is_some();
|
||||
|
||||
let import_rule = Arc::new(RwLock::new(
|
||||
let import_rule = Arc::new(self.shared_lock.wrap(
|
||||
ImportRule {
|
||||
url: url,
|
||||
stylesheet: Arc::new(Stylesheet {
|
||||
|
@ -855,12 +867,12 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
|
|||
None
|
||||
};
|
||||
|
||||
return Ok(AtRuleType::WithoutBlock(CssRule::Namespace(Arc::new(RwLock::new(
|
||||
NamespaceRule {
|
||||
return Ok(AtRuleType::WithoutBlock(CssRule::Namespace(Arc::new(
|
||||
self.shared_lock.wrap(NamespaceRule {
|
||||
prefix: opt_prefix,
|
||||
url: url,
|
||||
}
|
||||
)))))
|
||||
})
|
||||
))))
|
||||
} else {
|
||||
self.state.set(State::Invalid);
|
||||
return Err(()) // "@namespace must be before any rule but @charset and @import"
|
||||
|
@ -973,29 +985,29 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
|||
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
|
||||
match prelude {
|
||||
AtRulePrelude::FontFace => {
|
||||
Ok(CssRule::FontFace(Arc::new(RwLock::new(
|
||||
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
||||
try!(parse_font_face_block(self.context, input))))))
|
||||
}
|
||||
AtRulePrelude::Media(media_queries) => {
|
||||
Ok(CssRule::Media(Arc::new(RwLock::new(MediaRule {
|
||||
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
|
||||
media_queries: media_queries,
|
||||
rules: self.parse_nested_rules(input),
|
||||
}))))
|
||||
}
|
||||
AtRulePrelude::Supports(cond) => {
|
||||
let enabled = cond.eval(self.context);
|
||||
Ok(CssRule::Supports(Arc::new(RwLock::new(SupportsRule {
|
||||
Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule {
|
||||
condition: cond,
|
||||
rules: self.parse_nested_rules(input),
|
||||
enabled: enabled,
|
||||
}))))
|
||||
}
|
||||
AtRulePrelude::Viewport => {
|
||||
Ok(CssRule::Viewport(Arc::new(RwLock::new(
|
||||
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
|
||||
try!(ViewportRule::parse(input, self.context))))))
|
||||
}
|
||||
AtRulePrelude::Keyframes(name) => {
|
||||
Ok(CssRule::Keyframes(Arc::new(RwLock::new(KeyframesRule {
|
||||
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule {
|
||||
name: name,
|
||||
keyframes: parse_keyframe_list(&self.context, input),
|
||||
}))))
|
||||
|
|
|
@ -274,11 +274,11 @@ impl Stylist {
|
|||
}
|
||||
}
|
||||
CssRule::Import(ref import) => {
|
||||
let import = import.read();
|
||||
let import = import.read_with(guard);
|
||||
self.add_stylesheet(&import.stylesheet, guard)
|
||||
}
|
||||
CssRule::Keyframes(ref keyframes_rule) => {
|
||||
let keyframes_rule = keyframes_rule.read();
|
||||
let keyframes_rule = keyframes_rule.read_with(guard);
|
||||
debug!("Found valid keyframes rule: {:?}", *keyframes_rule);
|
||||
let animation = KeyframesAnimation::from_keyframes(&keyframes_rule.keyframes);
|
||||
debug!("Found valid keyframe animation: {:?}", animation);
|
||||
|
|
|
@ -23,6 +23,7 @@ use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInf
|
|||
use style::data::{ElementData, ElementStyles, RestyleData};
|
||||
use style::dom::{ShowSubtreeData, TElement, TNode};
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
use style::gecko::arc_types::HackHackHack;
|
||||
use style::gecko::data::{PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||
use style::gecko::restyle_damage::GeckoRestyleDamage;
|
||||
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
|
||||
|
@ -81,6 +82,7 @@ use style::string_cache::Atom;
|
|||
use style::stylesheets::{CssRule, CssRules, ImportRule, MediaRule, NamespaceRule};
|
||||
use style::stylesheets::{Origin, Stylesheet, StyleRule};
|
||||
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||
use style::stylesheets::RwLockStyleRulePretendLockedStyleRule;
|
||||
use style::supports::parse_condition_or_declaration;
|
||||
use style::thread_state;
|
||||
use style::timer::Timer;
|
||||
|
@ -586,17 +588,19 @@ macro_rules! impl_basic_rule_funcs {
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn $debug(rule: &$raw_type, result: *mut nsACString) {
|
||||
let rule = RwLock::<$rule_type>::as_arc(&rule);
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = Locked::<$rule_type>::as_arc(&rule);
|
||||
let result = unsafe { result.as_mut().unwrap() };
|
||||
write!(result, "{:?}", *rule.read()).unwrap();
|
||||
write!(result, "{:?}", *rule.read_with(&guard)).unwrap();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn $to_css(rule: &$raw_type, result: *mut nsAString) {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = RwLock::<$rule_type>::as_arc(&rule);
|
||||
rule.read().to_css(&guard, unsafe { result.as_mut().unwrap() }).unwrap();
|
||||
let rule = Locked::<$rule_type>::as_arc(&rule);
|
||||
rule.read_with(&guard).to_css(&guard, unsafe { result.as_mut().unwrap() }).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -641,26 +645,34 @@ pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowe
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_MediaRule_GetMedia(rule: RawServoMediaRuleBorrowed) -> RawServoMediaListStrong {
|
||||
let rule = RwLock::<MediaRule>::as_arc(&rule);
|
||||
rule.read().media_queries.clone().into_strong()
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = Locked::<MediaRule>::as_arc(&rule);
|
||||
rule.read_with(&guard).media_queries.clone().into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_MediaRule_GetRules(rule: RawServoMediaRuleBorrowed) -> ServoCssRulesStrong {
|
||||
let rule = RwLock::<MediaRule>::as_arc(&rule);
|
||||
rule.read().rules.clone().into_strong()
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = Locked::<MediaRule>::as_arc(&rule);
|
||||
rule.read_with(&guard).rules.clone().into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom {
|
||||
let rule = RwLock::<NamespaceRule>::as_arc(&rule);
|
||||
rule.read().prefix.as_ref().unwrap_or(&atom!("")).as_ptr()
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = Locked::<NamespaceRule>::as_arc(&rule);
|
||||
rule.read_with(&guard).prefix.as_ref().unwrap_or(&atom!("")).as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_NamespaceRule_GetURI(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom {
|
||||
let rule = RwLock::<NamespaceRule>::as_arc(&rule);
|
||||
rule.read().url.0.as_ptr()
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let rule = Locked::<NamespaceRule>::as_arc(&rule);
|
||||
rule.read_with(&guard).url.0.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1404,8 +1416,10 @@ pub extern "C" fn Servo_NoteExplicitHints(element: RawGeckoElementBorrowed,
|
|||
pub extern "C" fn Servo_ImportRule_GetSheet(import_rule:
|
||||
RawServoImportRuleBorrowed)
|
||||
-> RawServoStyleSheetStrong {
|
||||
let import_rule = RwLock::<ImportRule>::as_arc(&import_rule);
|
||||
import_rule.read().stylesheet.clone().into_strong()
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let import_rule = Locked::<ImportRule>::as_arc(&import_rule);
|
||||
import_rule.read_with(&guard).stylesheet.clone().into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::gecko_bindings::bindings::Gecko_LoadStyleSheet;
|
||||
use style::gecko_bindings::structs::{Loader, ServoStyleSheet};
|
||||
use style::gecko_bindings::sugar::ownership::HasArcFFI;
|
||||
use style::shared_lock::Locked;
|
||||
use style::stylesheets::{ImportRule, StylesheetLoader as StyleStylesheetLoader};
|
||||
use style_traits::ToCss;
|
||||
use super::glue::GLOBAL_STYLE_DATA;
|
||||
|
@ -20,10 +20,10 @@ impl StylesheetLoader {
|
|||
}
|
||||
|
||||
impl StyleStylesheetLoader for StylesheetLoader {
|
||||
fn request_stylesheet(&self, import_rule: &Arc<RwLock<ImportRule>>) {
|
||||
fn request_stylesheet(&self, import_rule: &Arc<Locked<ImportRule>>) {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let import = import_rule.read();
|
||||
let import = import_rule.read_with(&guard);
|
||||
let (spec_bytes, spec_len) = import.url.as_slice_components()
|
||||
.expect("Import only loads valid URLs");
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ fn test_parse_stylesheet() {
|
|||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||
disabled: AtomicBool::new(false),
|
||||
rules: CssRules::new(vec![
|
||||
CssRule::Namespace(Arc::new(RwLock::new(NamespaceRule {
|
||||
CssRule::Namespace(Arc::new(stylesheet.shared_lock.wrap(NamespaceRule {
|
||||
prefix: None,
|
||||
url: NsAtom::from("http://www.w3.org/1999/xhtml")
|
||||
}))),
|
||||
|
@ -235,7 +235,7 @@ fn test_parse_stylesheet() {
|
|||
Importance::Normal),
|
||||
]))),
|
||||
}))),
|
||||
CssRule::Keyframes(Arc::new(RwLock::new(KeyframesRule {
|
||||
CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule {
|
||||
name: "foo".into(),
|
||||
keyframes: vec![
|
||||
Arc::new(RwLock::new(Keyframe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue