--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -95,20 +95,16 @@ pub struct Stylist {
/// Applicable declarations for a given non-eagerly cascaded pseudo-element.
/// These are eagerly computed once, and then used to resolve the new
/// computed values on the fly on layout.
///
/// FIXME(emilio): Use the rule tree!
precomputed_pseudo_element_decls: PerPseudoElementMap<Vec<ApplicableDeclarationBlock>>,
- /// A monotonically increasing counter to represent the order on which a
- /// style rule appears in a stylesheet, needed to sort them by source order.
- rules_source_order: u32,
-
/// The total number of times the stylist has been rebuilt.
num_rebuilds: usize,
}
/// What cascade levels to include when styling elements.
#[derive(Copy, Clone, PartialEq)]
pub enum RuleInclusion {
/// Include rules for style sheets at all cascade levels. This is the
@@ -139,17 +135,16 @@ impl Stylist {
viewport_constraints: None,
device: device,
is_device_dirty: true,
is_cleared: true,
quirks_mode: quirks_mode,
cascade_data: Default::default(),
precomputed_pseudo_element_decls: PerPseudoElementMap::default(),
- rules_source_order: 0,
rule_tree: RuleTree::new(),
num_rebuilds: 0,
}
// FIXME: Add iso-8859-9.css when the document’s encoding is ISO-8859-8.
}
/// Returns the number of selectors.
@@ -212,17 +207,16 @@ impl Stylist {
self.is_cleared = true;
self.viewport_constraints = None;
// preserve current device
self.is_device_dirty = true;
// preserve current quirks_mode value
self.cascade_data.clear();
self.precomputed_pseudo_element_decls.clear();
- self.rules_source_order = 0;
// We want to keep rule_tree around across stylist rebuilds.
// preserve num_rebuilds value, since it should stay across
// clear()/rebuild() cycles.
}
/// rebuild the stylist for the given document stylesheets, and optionally
/// with a set of user agent stylesheets.
///
@@ -375,17 +369,17 @@ impl Stylist {
continue;
}
self.precomputed_pseudo_element_decls
.get_or_insert_with(&pseudo.canonical(), Vec::new)
.expect("Unexpected tree pseudo-element?")
.push(ApplicableDeclarationBlock::new(
StyleSource::Style(locked.clone()),
- self.rules_source_order,
+ origin_cascade_data.rules_source_order,
CascadeLevel::UANormal,
selector.specificity()
));
continue;
}
None => &mut origin_cascade_data.element_map,
Some(pseudo) => {
@@ -398,17 +392,17 @@ impl Stylist {
let hashes =
AncestorHashes::new(&selector, self.quirks_mode);
let rule = Rule::new(
selector.clone(),
hashes.clone(),
locked.clone(),
- self.rules_source_order
+ origin_cascade_data.rules_source_order
);
map.insert(rule, self.quirks_mode);
origin_cascade_data
.invalidation_map
.note_selector(selector, self.quirks_mode);
let mut visitor = StylistSelectorVisitor {
@@ -423,17 +417,17 @@ impl Stylist {
selector.visit(&mut visitor);
if visitor.needs_revalidation {
origin_cascade_data.selectors_for_cache_revalidation.insert(
RevalidationSelectorAndHashes::new(selector.clone(), hashes),
self.quirks_mode);
}
}
- self.rules_source_order += 1;
+ origin_cascade_data.rules_source_order += 1;
}
CssRule::Import(ref lock) => {
let import_rule = lock.read_with(guard);
origin_cascade_data
.effective_media_query_results
.saw_effective(import_rule);
// NOTE: effective_rules visits the inner stylesheet if
@@ -1620,16 +1614,20 @@ struct CascadeData {
/// on state that is not otherwise visible to the cache, like attributes or
/// tree-structural state like child index and pseudos).
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selectors_for_cache_revalidation: SelectorMap<RevalidationSelectorAndHashes>,
/// Effective media query results cached from the last rebuild.
effective_media_query_results: EffectiveMediaQueryResults,
+ /// A monotonically increasing counter to represent the order on which a
+ /// style rule appears in a stylesheet, needed to sort them by source order.
+ rules_source_order: u32,
+
/// The total number of selectors.
num_selectors: usize,
/// The total number of declarations.
num_declarations: usize,
}
impl CascadeData {
@@ -1640,16 +1638,17 @@ impl CascadeData {
animations: Default::default(),
invalidation_map: InvalidationMap::new(),
attribute_dependencies: NonCountingBloomFilter::new(),
style_attribute_dependency: false,
state_dependencies: ElementState::empty(),
mapped_ids: NonCountingBloomFilter::new(),
selectors_for_cache_revalidation: SelectorMap::new(),
effective_media_query_results: EffectiveMediaQueryResults::new(),
+ rules_source_order: 0,
num_selectors: 0,
num_declarations: 0,
}
}
#[inline]
fn borrow_for_pseudo(&self, pseudo: Option<&PseudoElement>) -> Option<&SelectorMap<Rule>> {
match pseudo {
@@ -1670,16 +1669,17 @@ impl PerOriginClear for CascadeData {
self.animations = Default::default();
self.invalidation_map.clear();
self.attribute_dependencies.clear();
self.style_attribute_dependency = false;
self.state_dependencies = ElementState::empty();
self.mapped_ids.clear();
self.selectors_for_cache_revalidation = SelectorMap::new();
self.effective_media_query_results.clear();
+ self.rules_source_order = 0;
self.num_selectors = 0;
self.num_declarations = 0;
}
}
impl Default for CascadeData {
fn default() -> Self {
CascadeData::new()