diff options
Diffstat (limited to 'components/style/stylist.rs')
-rw-r--r-- | components/style/stylist.rs | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/components/style/stylist.rs b/components/style/stylist.rs index a110e4f7abb..2166e81946a 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -28,7 +28,7 @@ use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONA use selectors::matching::{ElementSelectorFlags, StyleRelations, matches_complex_selector}; use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector}; use selectors::parser::SelectorMethods; -use shared_lock::SharedRwLockReadGuard; +use shared_lock::{Locked, SharedRwLockReadGuard, ReadGuards}; use sink::Push; use smallvec::VecLike; use std::borrow::Borrow; @@ -159,7 +159,7 @@ impl Stylist { /// device is dirty, which means we need to re-evaluate media queries. pub fn update(&mut self, doc_stylesheets: &[Arc<Stylesheet>], - doc_guard: &SharedRwLockReadGuard, + guards: &ReadGuards, ua_stylesheets: Option<&UserAgentStylesheets>, stylesheets_changed: bool) -> bool { if !(self.is_device_dirty || stylesheets_changed) { @@ -168,7 +168,7 @@ impl Stylist { let cascaded_rule = ViewportRule { declarations: viewport::Cascade::from_stylesheets( - doc_stylesheets, doc_guard, &self.device + doc_stylesheets, guards.author, &self.device ).finish(), }; @@ -196,18 +196,17 @@ impl Stylist { self.non_common_style_affecting_attributes_selectors.clear(); if let Some(ua_stylesheets) = ua_stylesheets { - let ua_guard = ua_stylesheets.shared_lock.read(); for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets { - self.add_stylesheet(&stylesheet, &ua_guard); + self.add_stylesheet(&stylesheet, guards.ua_or_user); } if self.quirks_mode { - self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet, &ua_guard); + self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet, guards.ua_or_user); } } for ref stylesheet in doc_stylesheets.iter() { - self.add_stylesheet(stylesheet, doc_guard); + self.add_stylesheet(stylesheet, guards.author); } debug!("Stylist stats:"); @@ -221,8 +220,9 @@ impl Stylist { SelectorImpl::each_precomputed_pseudo_element(|pseudo| { if let Some(map) = self.pseudos_map.remove(&pseudo) { let declarations = - map.user_agent.get_universal_rules(CascadeLevel::UANormal, - CascadeLevel::UAImportant); + map.user_agent.get_universal_rules( + guards.ua_or_user, CascadeLevel::UANormal, CascadeLevel::UAImportant + ); self.precomputed_pseudo_element_decls.insert(pseudo, declarations); } }); @@ -241,9 +241,9 @@ impl Stylist { stylesheet.effective_rules(&device, guard, |rule| { match *rule { - CssRule::Style(ref style_rule) => { - let guard = style_rule.read(); - for selector in &guard.selectors.0 { + CssRule::Style(ref locked) => { + let style_rule = locked.read_with(&guard); + for selector in &style_rule.selectors.0 { let map = if let Some(ref pseudo) = selector.pseudo_element { self.pseudos_map .entry(pseudo.clone()) @@ -255,14 +255,14 @@ impl Stylist { map.insert(Rule { selector: selector.complex_selector.clone(), - style_rule: style_rule.clone(), + style_rule: locked.clone(), specificity: selector.specificity, source_order: self.rules_source_order, }); } self.rules_source_order += 1; - for selector in &guard.selectors.0 { + for selector in &style_rule.selectors.0 { self.state_deps.note_selector(&selector.complex_selector); if selector.affects_siblings() { self.sibling_affecting_selectors.push(selector.clone()); @@ -300,6 +300,7 @@ impl Stylist { /// values. The flow constructor uses this flag when constructing anonymous /// flows. pub fn precomputed_values_for_pseudo(&self, + guards: &ReadGuards, pseudo: &PseudoElement, parent: Option<&Arc<ComputedValues>>, cascade_flags: CascadeFlags) @@ -333,6 +334,7 @@ impl Stylist { let computed = properties::cascade(&self.device, &rule_node, + guards, parent.map(|p| &**p), parent.map(|p| &**p), None, @@ -344,6 +346,7 @@ impl Stylist { /// Returns the style for an anonymous box of the given type. #[cfg(feature = "servo")] pub fn style_for_anonymous_box(&self, + guards: &ReadGuards, pseudo: &PseudoElement, parent_style: &Arc<ComputedValues>) -> Arc<ComputedValues> { @@ -368,7 +371,7 @@ impl Stylist { if inherit_all { cascade_flags.insert(INHERIT_ALL); } - self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), cascade_flags) + self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags) .values.unwrap() } @@ -380,6 +383,7 @@ impl Stylist { /// Check the documentation on lazy pseudo-elements in /// docs/components/style.md pub fn lazily_compute_pseudo_element_style<E>(&self, + guards: &ReadGuards, element: &E, pseudo: &PseudoElement, parent: &Arc<ComputedValues>) @@ -401,6 +405,7 @@ impl Stylist { None, AnimationRules(None, None), Some(pseudo), + guards, &mut declarations, &mut flags); @@ -415,6 +420,7 @@ impl Stylist { let computed = properties::cascade(&self.device, &rule_node, + guards, Some(&**parent), Some(&**parent), None, @@ -539,6 +545,7 @@ impl Stylist { style_attribute: Option<&Arc<RwLock<PropertyDeclarationBlock>>>, animation_rules: AnimationRules, pseudo_element: Option<&PseudoElement>, + guards: &ReadGuards, applicable_declarations: &mut V, flags: &mut ElementSelectorFlags) -> StyleRelations where E: TElement + @@ -564,6 +571,7 @@ impl Stylist { // Step 1: Normal user-agent rules. map.user_agent.get_all_matching_rules(element, parent_bf, + guards.ua_or_user, applicable_declarations, &mut relations, flags, @@ -588,6 +596,7 @@ impl Stylist { // Step 3: User and author normal rules. map.user.get_all_matching_rules(element, parent_bf, + guards.ua_or_user, applicable_declarations, &mut relations, flags, @@ -595,6 +604,7 @@ impl Stylist { debug!("user normal: {:?}", relations); map.author.get_all_matching_rules(element, parent_bf, + guards.author, applicable_declarations, &mut relations, flags, @@ -629,6 +639,7 @@ impl Stylist { // Step 6: Author-supplied `!important` rules. map.author.get_all_matching_rules(element, parent_bf, + guards.author, applicable_declarations, &mut relations, flags, @@ -652,6 +663,7 @@ impl Stylist { // Step 8: User `!important` rules. map.user.get_all_matching_rules(element, parent_bf, + guards.ua_or_user, applicable_declarations, &mut relations, flags, @@ -665,6 +677,7 @@ impl Stylist { // Step 9: UA `!important` rules. map.user_agent.get_all_matching_rules(element, parent_bf, + guards.ua_or_user, applicable_declarations, &mut relations, flags, @@ -903,6 +916,7 @@ impl SelectorMap { pub fn get_all_matching_rules<E, V>(&self, element: &E, parent_bf: Option<&BloomFilter>, + guard: &SharedRwLockReadGuard, matching_rules_list: &mut V, relations: &mut StyleRelations, flags: &mut ElementSelectorFlags, @@ -921,6 +935,7 @@ impl SelectorMap { parent_bf, &self.id_hash, &id, + guard, matching_rules_list, relations, flags, @@ -932,6 +947,7 @@ impl SelectorMap { parent_bf, &self.class_hash, class, + guard, matching_rules_list, relations, flags, @@ -947,6 +963,7 @@ impl SelectorMap { parent_bf, local_name_hash, element.get_local_name(), + guard, matching_rules_list, relations, flags, @@ -955,6 +972,7 @@ impl SelectorMap { SelectorMap::get_matching_rules(element, parent_bf, &self.other_rules, + guard, matching_rules_list, relations, flags, @@ -968,6 +986,7 @@ impl SelectorMap { /// Append to `rule_list` all universal Rules (rules with selector `*|*`) in /// `self` sorted by specificity and source order. pub fn get_universal_rules(&self, + guard: &SharedRwLockReadGuard, cascade_level: CascadeLevel, important_cascade_level: CascadeLevel) -> Vec<ApplicableDeclarationBlock> { @@ -985,8 +1004,8 @@ impl SelectorMap { for rule in self.other_rules.iter() { if rule.selector.compound_selector.is_empty() && rule.selector.next.is_none() { - let guard = rule.style_rule.read(); - let block = guard.block.read(); + let style_rule = rule.style_rule.read_with(guard); + let block = style_rule.block.read(); if block.any_normal() { matching_rules_list.push( rule.to_applicable_declaration_block(cascade_level)); @@ -1014,6 +1033,7 @@ impl SelectorMap { parent_bf: Option<&BloomFilter>, hash: &FnvHashMap<Str, Vec<Rule>>, key: &BorrowedStr, + guard: &SharedRwLockReadGuard, matching_rules: &mut Vector, relations: &mut StyleRelations, flags: &mut ElementSelectorFlags, @@ -1027,6 +1047,7 @@ impl SelectorMap { SelectorMap::get_matching_rules(element, parent_bf, rules, + guard, matching_rules, relations, flags, @@ -1038,6 +1059,7 @@ impl SelectorMap { fn get_matching_rules<E, V>(element: &E, parent_bf: Option<&BloomFilter>, rules: &[Rule], + guard: &SharedRwLockReadGuard, matching_rules: &mut V, relations: &mut StyleRelations, flags: &mut ElementSelectorFlags, @@ -1046,8 +1068,8 @@ impl SelectorMap { V: VecLike<ApplicableDeclarationBlock> { for rule in rules.iter() { - let guard = rule.style_rule.read(); - let block = guard.block.read(); + let style_rule = rule.style_rule.read_with(guard); + let block = style_rule.block.read(); let any_declaration_for_importance = if cascade_level.is_important() { block.any_important() } else { @@ -1145,7 +1167,7 @@ pub struct Rule { pub selector: Arc<ComplexSelector<SelectorImpl>>, /// The actual style rule. #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] - pub style_rule: Arc<RwLock<StyleRule>>, + pub style_rule: Arc<Locked<StyleRule>>, /// The source order this style rule appears in. pub source_order: usize, /// The specificity of the rule this selector represents. |