style: Make InvalidationProcessor methods be &mut self.

This would allow querySelector / querySelectorAll to mutate the list of matched
nodes as it sees fit.
This commit is contained in:
Emilio Cobos Álvarez 2017-10-12 18:08:44 +02:00
parent 9034e6a732
commit e447f819a2
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 38 additions and 41 deletions

View file

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

View file

@ -63,7 +63,7 @@ where
fn invalidates_on_eager_pseudo_element(&self) -> bool { true }
fn collect_invalidations(
&self,
&mut self,
element: E,
mut data: Option<&mut ElementData>,
nth_index_cache: Option<&mut NthIndexCache>,
@ -182,7 +182,7 @@ where
}
fn should_process_descendants(
&self,
&mut self,
_element: E,
data: Option<&mut ElementData>,
) -> bool {
@ -196,7 +196,7 @@ where
}
fn recursion_limit_exceeded(
&self,
&mut self,
_element: E,
data: Option<&mut ElementData>,
) {
@ -206,7 +206,7 @@ where
}
fn invalidated_descendants(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
child: E,
@ -236,7 +236,7 @@ where
}
fn invalidated_self(
&self,
&mut self,
_element: E,
data: Option<&mut ElementData>,
) {

View file

@ -34,7 +34,7 @@ where
///
/// Returns whether the element itself was invalidated.
fn collect_invalidations(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
nth_index_cache: Option<&mut NthIndexCache>,
@ -46,7 +46,7 @@ where
/// Returns whether the invalidation process should process the descendants
/// of the given element.
fn should_process_descendants(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
) -> bool;
@ -54,21 +54,21 @@ where
/// Executes an arbitrary action when the recursion limit is exceded (if
/// any).
fn recursion_limit_exceeded(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
);
/// Executes an action when `Self` is invalidated.
fn invalidated_self(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
);
/// Executes an action when any descendant of `Self` is invalidated.
fn invalidated_descendants(
&self,
&mut self,
element: E,
data: Option<&mut ElementData>,
child: E,
@ -96,10 +96,7 @@ where
shared_context: &'a SharedStyleContext<'b>,
stack_limit_checker: Option<&'a StackLimitChecker>,
nth_index_cache: Option<&'a mut NthIndexCache>,
// TODO(emilio): Make a mutable reference, we're going to need that for
// QS/QSA.
processor: &'a P,
processor: &'a mut P,
}
/// A vector of invalidations, optimized for small invalidation sets.
@ -240,7 +237,7 @@ where
shared_context: &'a SharedStyleContext<'b>,
stack_limit_checker: Option<&'a StackLimitChecker>,
nth_index_cache: Option<&'a mut NthIndexCache>,
processor: &'a P,
processor: &'a mut P,
) -> Self {
Self {
element,
@ -359,6 +356,10 @@ where
invalidations: &InvalidationVector,
sibling_invalidations: &mut InvalidationVector,
) -> bool {
let mut invalidations_for_descendants = InvalidationVector::new();
let mut invalidated_child = false;
let invalidated_descendants = {
let mut child_data = child.mutate_data();
let mut child_invalidator = TreeStyleInvalidator::new(
@ -370,9 +371,6 @@ where
self.processor,
);
let mut invalidations_for_descendants = InvalidationVector::new();
let mut invalidated_child = false;
invalidated_child |=
child_invalidator.process_sibling_invalidations(
&mut invalidations_for_descendants,
@ -386,9 +384,8 @@ where
sibling_invalidations,
);
let invalidated_descendants = child_invalidator.invalidate_descendants(
&invalidations_for_descendants
);
child_invalidator.invalidate_descendants(&invalidations_for_descendants)
};
// The child may not be a flattened tree child of the current element,
// but may be arbitrarily deep.