style: Don't require a full SharedStyleContext for TreeStyleInvalidator.

We only use it to get the quirks mode, and a shared style context is a pretty
heavy-weight struct.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-10-16 17:04:47 +02:00
parent 1715329eb1
commit 40d9cd99b5
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 31 additions and 20 deletions

View file

@ -259,11 +259,12 @@ impl ElementData {
return InvalidationResult::empty();
}
let mut processor = StateAndAttrInvalidationProcessor;
let mut processor =
StateAndAttrInvalidationProcessor::new(shared_context);
let invalidator = TreeStyleInvalidator::new(
element,
Some(self),
shared_context,
shared_context.quirks_mode(),
stack_limit_checker,
nth_index_cache,
&mut processor,

View file

@ -51,9 +51,18 @@ where
/// An invalidation processor for style changes due to state and attribute
/// changes.
pub struct StateAndAttrInvalidationProcessor;
pub struct StateAndAttrInvalidationProcessor<'a, 'b: 'a> {
shared_context: &'a SharedStyleContext<'b>,
}
impl<E> InvalidationProcessor<E> for StateAndAttrInvalidationProcessor
impl<'a, 'b: 'a> StateAndAttrInvalidationProcessor<'a, 'b> {
/// Creates a new StateAndAttrInvalidationProcessor.
pub fn new(shared_context: &'a SharedStyleContext<'b>) -> Self {
Self { shared_context }
}
}
impl<'a, 'b: 'a, E> InvalidationProcessor<E> for StateAndAttrInvalidationProcessor<'a, 'b>
where
E: TElement,
{
@ -67,15 +76,16 @@ where
element: E,
mut data: Option<&mut ElementData>,
nth_index_cache: Option<&mut NthIndexCache>,
shared_context: &SharedStyleContext,
quirks_mode: QuirksMode,
descendant_invalidations: &mut InvalidationVector,
sibling_invalidations: &mut InvalidationVector,
) -> bool {
debug_assert!(element.has_snapshot(), "Why bothering?");
debug_assert!(data.is_some(), "How exactly?");
debug_assert_eq!(quirks_mode, self.shared_context.quirks_mode(), "How exactly?");
let wrapper =
ElementWrapper::new(element, &*shared_context.snapshot_map);
ElementWrapper::new(element, &*self.shared_context.snapshot_map);
let state_changes = wrapper.state_changes();
let snapshot = wrapper.snapshot().expect("has_snapshot lied");
@ -140,7 +150,7 @@ where
state_changes,
element,
snapshot: &snapshot,
quirks_mode: shared_context.quirks_mode(),
quirks_mode: self.shared_context.quirks_mode(),
removed_id: id_removed.as_ref(),
added_id: id_added.as_ref(),
classes_removed: &classes_removed,
@ -150,7 +160,7 @@ where
invalidates_self: false,
};
shared_context.stylist.each_invalidation_map(|invalidation_map| {
self.shared_context.stylist.each_invalidation_map(|invalidation_map| {
collector.collect_dependencies_in_invalidation_map(invalidation_map);
});

View file

@ -5,12 +5,12 @@
//! The struct that takes care of encapsulating all the logic on where and how
//! element styles need to be invalidated.
use context::{SharedStyleContext, StackLimitChecker};
use context::StackLimitChecker;
use data::ElementData;
use dom::{TElement, TNode};
use selector_parser::SelectorImpl;
use selectors::NthIndexCache;
use selectors::matching::{MatchingContext, MatchingMode, VisitedHandlingMode};
use selectors::matching::{MatchingContext, MatchingMode, QuirksMode, VisitedHandlingMode};
use selectors::matching::CompoundSelectorMatchingResult;
use selectors::matching::matches_compound_selector;
use selectors::parser::{Combinator, Component, Selector};
@ -38,7 +38,7 @@ where
element: E,
data: Option<&mut ElementData>,
nth_index_cache: Option<&mut NthIndexCache>,
shared_context: &SharedStyleContext,
quirks_mode: QuirksMode,
descendant_invalidations: &mut InvalidationVector,
sibling_invalidations: &mut InvalidationVector,
) -> bool;
@ -77,7 +77,7 @@ where
/// The struct that takes care of encapsulating all the logic on where and how
/// element styles need to be invalidated.
pub struct TreeStyleInvalidator<'a, 'b: 'a, E, P: 'a>
pub struct TreeStyleInvalidator<'a, E, P: 'a>
where
E: TElement,
P: InvalidationProcessor<E>
@ -93,7 +93,7 @@ where
// Seems like we could at least avoid running invalidation for the
// descendants if an element has no data, though.
data: Option<&'a mut ElementData>,
shared_context: &'a SharedStyleContext<'b>,
quirks_mode: QuirksMode,
stack_limit_checker: Option<&'a StackLimitChecker>,
nth_index_cache: Option<&'a mut NthIndexCache>,
processor: &'a mut P,
@ -224,7 +224,7 @@ impl InvalidationResult {
}
}
impl<'a, 'b: 'a, E, P: 'a> TreeStyleInvalidator<'a, 'b, E, P>
impl<'a, E, P: 'a> TreeStyleInvalidator<'a, E, P>
where
E: TElement,
P: InvalidationProcessor<E>,
@ -233,7 +233,7 @@ where
pub fn new(
element: E,
data: Option<&'a mut ElementData>,
shared_context: &'a SharedStyleContext<'b>,
quirks_mode: QuirksMode,
stack_limit_checker: Option<&'a StackLimitChecker>,
nth_index_cache: Option<&'a mut NthIndexCache>,
processor: &'a mut P,
@ -241,7 +241,7 @@ where
Self {
element,
data,
shared_context,
quirks_mode,
stack_limit_checker,
nth_index_cache,
processor,
@ -259,7 +259,7 @@ where
self.element,
self.data.as_mut().map(|d| &mut **d),
self.nth_index_cache.as_mut().map(|c| &mut **c),
self.shared_context,
self.quirks_mode,
&mut descendant_invalidations,
&mut sibling_invalidations,
);
@ -296,7 +296,7 @@ where
let mut sibling_invalidator = TreeStyleInvalidator::new(
sibling,
sibling_data.as_mut().map(|d| &mut **d),
self.shared_context,
self.quirks_mode,
self.stack_limit_checker,
self.nth_index_cache.as_mut().map(|c| &mut **c),
self.processor,
@ -364,7 +364,7 @@ where
let mut child_invalidator = TreeStyleInvalidator::new(
child,
child_data.as_mut().map(|d| &mut **d),
self.shared_context,
self.quirks_mode,
self.stack_limit_checker,
self.nth_index_cache.as_mut().map(|c| &mut **c),
self.processor,
@ -609,7 +609,7 @@ where
None,
self.nth_index_cache.as_mut().map(|c| &mut **c),
VisitedHandlingMode::AllLinksVisitedAndUnvisited,
self.shared_context.quirks_mode(),
self.quirks_mode,
);
matches_compound_selector(