mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
style: Move MatchingContext to the InvalidationProcessor.
This avoids threading the quirks mode and nth-index cache around, and prevents having to thread even more arguments down for the querySelector stuff (at least VisitedHandlingMode and the style scope). Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
5ac0f5121e
commit
258efb70df
3 changed files with 39 additions and 48 deletions
|
@ -263,13 +263,12 @@ impl ElementData {
|
||||||
shared_context,
|
shared_context,
|
||||||
element,
|
element,
|
||||||
self,
|
self,
|
||||||
|
nth_index_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
let invalidator = TreeStyleInvalidator::new(
|
let invalidator = TreeStyleInvalidator::new(
|
||||||
element,
|
element,
|
||||||
shared_context.quirks_mode(),
|
|
||||||
stack_limit_checker,
|
stack_limit_checker,
|
||||||
nth_index_cache,
|
|
||||||
&mut processor,
|
&mut processor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -51,24 +51,34 @@ where
|
||||||
|
|
||||||
/// An invalidation processor for style changes due to state and attribute
|
/// An invalidation processor for style changes due to state and attribute
|
||||||
/// changes.
|
/// changes.
|
||||||
pub struct StateAndAttrInvalidationProcessor<'a, 'b: 'a, E> {
|
pub struct StateAndAttrInvalidationProcessor<'a, 'b: 'a, E: TElement> {
|
||||||
shared_context: &'a SharedStyleContext<'b>,
|
shared_context: &'a SharedStyleContext<'b>,
|
||||||
element: E,
|
element: E,
|
||||||
data: &'a mut ElementData,
|
data: &'a mut ElementData,
|
||||||
|
matching_context: MatchingContext<'a, E::Impl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b: 'a, E> StateAndAttrInvalidationProcessor<'a, 'b, E> {
|
impl<'a, 'b: 'a, E: TElement> StateAndAttrInvalidationProcessor<'a, 'b, E> {
|
||||||
/// Creates a new StateAndAttrInvalidationProcessor.
|
/// Creates a new StateAndAttrInvalidationProcessor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
shared_context: &'a SharedStyleContext<'b>,
|
shared_context: &'a SharedStyleContext<'b>,
|
||||||
element: E,
|
element: E,
|
||||||
data: &'a mut ElementData,
|
data: &'a mut ElementData,
|
||||||
|
nth_index_cache: Option<&'a mut NthIndexCache>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { shared_context, element, data }
|
let matching_context = MatchingContext::new_for_visited(
|
||||||
|
MatchingMode::Normal,
|
||||||
|
None,
|
||||||
|
nth_index_cache,
|
||||||
|
VisitedHandlingMode::AllLinksVisitedAndUnvisited,
|
||||||
|
shared_context.quirks_mode(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Self { shared_context, element, data, matching_context }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b: 'a, E> InvalidationProcessor<E> for StateAndAttrInvalidationProcessor<'a, 'b, E>
|
impl<'a, 'b: 'a, E> InvalidationProcessor<'a, E> for StateAndAttrInvalidationProcessor<'a, 'b, E>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
{
|
{
|
||||||
|
@ -77,17 +87,18 @@ where
|
||||||
/// content being generated.
|
/// content being generated.
|
||||||
fn invalidates_on_eager_pseudo_element(&self) -> bool { true }
|
fn invalidates_on_eager_pseudo_element(&self) -> bool { true }
|
||||||
|
|
||||||
|
fn matching_context(&mut self) -> &mut MatchingContext<'a, E::Impl> {
|
||||||
|
&mut self.matching_context
|
||||||
|
}
|
||||||
|
|
||||||
fn collect_invalidations(
|
fn collect_invalidations(
|
||||||
&mut self,
|
&mut self,
|
||||||
element: E,
|
element: E,
|
||||||
nth_index_cache: Option<&mut NthIndexCache>,
|
|
||||||
quirks_mode: QuirksMode,
|
|
||||||
_self_invalidations: &mut InvalidationVector,
|
_self_invalidations: &mut InvalidationVector,
|
||||||
descendant_invalidations: &mut InvalidationVector,
|
descendant_invalidations: &mut InvalidationVector,
|
||||||
sibling_invalidations: &mut InvalidationVector,
|
sibling_invalidations: &mut InvalidationVector,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
debug_assert!(element.has_snapshot(), "Why bothering?");
|
debug_assert!(element.has_snapshot(), "Why bothering?");
|
||||||
debug_assert_eq!(quirks_mode, self.shared_context.quirks_mode(), "How exactly?");
|
|
||||||
|
|
||||||
let wrapper =
|
let wrapper =
|
||||||
ElementWrapper::new(element, &*self.shared_context.snapshot_map);
|
ElementWrapper::new(element, &*self.shared_context.snapshot_map);
|
||||||
|
@ -150,11 +161,11 @@ where
|
||||||
let mut collector = Collector {
|
let mut collector = Collector {
|
||||||
wrapper,
|
wrapper,
|
||||||
lookup_element,
|
lookup_element,
|
||||||
nth_index_cache,
|
|
||||||
state_changes,
|
state_changes,
|
||||||
element,
|
element,
|
||||||
snapshot: &snapshot,
|
snapshot: &snapshot,
|
||||||
quirks_mode: self.shared_context.quirks_mode(),
|
quirks_mode: self.shared_context.quirks_mode(),
|
||||||
|
nth_index_cache: self.matching_context.nth_index_cache.as_mut().map(|c| &mut **c),
|
||||||
removed_id: id_removed.as_ref(),
|
removed_id: id_removed.as_ref(),
|
||||||
added_id: id_added.as_ref(),
|
added_id: id_added.as_ref(),
|
||||||
classes_removed: &classes_removed,
|
classes_removed: &classes_removed,
|
||||||
|
|
|
@ -8,16 +8,14 @@
|
||||||
use context::StackLimitChecker;
|
use context::StackLimitChecker;
|
||||||
use dom::{TElement, TNode};
|
use dom::{TElement, TNode};
|
||||||
use selector_parser::SelectorImpl;
|
use selector_parser::SelectorImpl;
|
||||||
use selectors::NthIndexCache;
|
use selectors::matching::{CompoundSelectorMatchingResult, MatchingContext};
|
||||||
use selectors::matching::{MatchingContext, MatchingMode, QuirksMode, VisitedHandlingMode};
|
|
||||||
use selectors::matching::CompoundSelectorMatchingResult;
|
|
||||||
use selectors::matching::matches_compound_selector;
|
use selectors::matching::matches_compound_selector;
|
||||||
use selectors::parser::{Combinator, Component, Selector};
|
use selectors::parser::{Combinator, Component, Selector};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// A trait to abstract the collection of invalidations for a given pass.
|
/// A trait to abstract the collection of invalidations for a given pass.
|
||||||
pub trait InvalidationProcessor<E>
|
pub trait InvalidationProcessor<'a, E>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
{
|
{
|
||||||
|
@ -26,14 +24,15 @@ where
|
||||||
/// that would originate it.
|
/// that would originate it.
|
||||||
fn invalidates_on_eager_pseudo_element(&self) -> bool { false }
|
fn invalidates_on_eager_pseudo_element(&self) -> bool { false }
|
||||||
|
|
||||||
|
/// The matching context that should be used to process invalidations.
|
||||||
|
fn matching_context(&mut self) -> &mut MatchingContext<'a, E::Impl>;
|
||||||
|
|
||||||
/// Collect invalidations for a given element's descendants and siblings.
|
/// Collect invalidations for a given element's descendants and siblings.
|
||||||
///
|
///
|
||||||
/// Returns whether the element itself was invalidated.
|
/// Returns whether the element itself was invalidated.
|
||||||
fn collect_invalidations(
|
fn collect_invalidations(
|
||||||
&mut self,
|
&mut self,
|
||||||
element: E,
|
element: E,
|
||||||
nth_index_cache: Option<&mut NthIndexCache>,
|
|
||||||
quirks_mode: QuirksMode,
|
|
||||||
self_invalidations: &mut InvalidationVector,
|
self_invalidations: &mut InvalidationVector,
|
||||||
descendant_invalidations: &mut InvalidationVector,
|
descendant_invalidations: &mut InvalidationVector,
|
||||||
sibling_invalidations: &mut InvalidationVector,
|
sibling_invalidations: &mut InvalidationVector,
|
||||||
|
@ -56,16 +55,16 @@ where
|
||||||
|
|
||||||
/// The struct that takes care of encapsulating all the logic on where and how
|
/// The struct that takes care of encapsulating all the logic on where and how
|
||||||
/// element styles need to be invalidated.
|
/// element styles need to be invalidated.
|
||||||
pub struct TreeStyleInvalidator<'a, E, P: 'a>
|
pub struct TreeStyleInvalidator<'a, 'b, E, P: 'a>
|
||||||
where
|
where
|
||||||
|
'b: 'a,
|
||||||
E: TElement,
|
E: TElement,
|
||||||
P: InvalidationProcessor<E>
|
P: InvalidationProcessor<'b, E>,
|
||||||
{
|
{
|
||||||
element: E,
|
element: E,
|
||||||
quirks_mode: QuirksMode,
|
|
||||||
stack_limit_checker: Option<&'a StackLimitChecker>,
|
stack_limit_checker: Option<&'a StackLimitChecker>,
|
||||||
nth_index_cache: Option<&'a mut NthIndexCache>,
|
|
||||||
processor: &'a mut P,
|
processor: &'a mut P,
|
||||||
|
_marker: ::std::marker::PhantomData<&'b ()>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A vector of invalidations, optimized for small invalidation sets.
|
/// A vector of invalidations, optimized for small invalidation sets.
|
||||||
|
@ -201,25 +200,23 @@ impl InvalidationResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, E, P: 'a> TreeStyleInvalidator<'a, E, P>
|
impl<'a, 'b, E, P: 'a> TreeStyleInvalidator<'a, 'b, E, P>
|
||||||
where
|
where
|
||||||
|
'b: 'a,
|
||||||
E: TElement,
|
E: TElement,
|
||||||
P: InvalidationProcessor<E>,
|
P: InvalidationProcessor<'b, E>,
|
||||||
{
|
{
|
||||||
/// Trivially constructs a new `TreeStyleInvalidator`.
|
/// Trivially constructs a new `TreeStyleInvalidator`.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
element: E,
|
element: E,
|
||||||
quirks_mode: QuirksMode,
|
|
||||||
stack_limit_checker: Option<&'a StackLimitChecker>,
|
stack_limit_checker: Option<&'a StackLimitChecker>,
|
||||||
nth_index_cache: Option<&'a mut NthIndexCache>,
|
|
||||||
processor: &'a mut P,
|
processor: &'a mut P,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
element,
|
element,
|
||||||
quirks_mode,
|
|
||||||
stack_limit_checker,
|
stack_limit_checker,
|
||||||
nth_index_cache,
|
|
||||||
processor,
|
processor,
|
||||||
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,8 +230,6 @@ where
|
||||||
|
|
||||||
let mut invalidated_self = self.processor.collect_invalidations(
|
let mut invalidated_self = self.processor.collect_invalidations(
|
||||||
self.element,
|
self.element,
|
||||||
self.nth_index_cache.as_mut().map(|c| &mut **c),
|
|
||||||
self.quirks_mode,
|
|
||||||
&mut self_invalidations,
|
&mut self_invalidations,
|
||||||
&mut descendant_invalidations,
|
&mut descendant_invalidations,
|
||||||
&mut sibling_invalidations,
|
&mut sibling_invalidations,
|
||||||
|
@ -276,9 +271,7 @@ where
|
||||||
while let Some(sibling) = current {
|
while let Some(sibling) = current {
|
||||||
let mut sibling_invalidator = TreeStyleInvalidator::new(
|
let mut sibling_invalidator = TreeStyleInvalidator::new(
|
||||||
sibling,
|
sibling,
|
||||||
self.quirks_mode,
|
|
||||||
self.stack_limit_checker,
|
self.stack_limit_checker,
|
||||||
self.nth_index_cache.as_mut().map(|c| &mut **c),
|
|
||||||
self.processor,
|
self.processor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -341,9 +334,7 @@ where
|
||||||
let invalidated_descendants = {
|
let invalidated_descendants = {
|
||||||
let mut child_invalidator = TreeStyleInvalidator::new(
|
let mut child_invalidator = TreeStyleInvalidator::new(
|
||||||
child,
|
child,
|
||||||
self.quirks_mode,
|
|
||||||
self.stack_limit_checker,
|
self.stack_limit_checker,
|
||||||
self.nth_index_cache.as_mut().map(|c| &mut **c),
|
|
||||||
self.processor,
|
self.processor,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -570,22 +561,12 @@ where
|
||||||
debug!("TreeStyleInvalidator::process_invalidation({:?}, {:?}, {:?})",
|
debug!("TreeStyleInvalidator::process_invalidation({:?}, {:?}, {:?})",
|
||||||
self.element, invalidation, invalidation_kind);
|
self.element, invalidation, invalidation_kind);
|
||||||
|
|
||||||
let matching_result = {
|
let matching_result = matches_compound_selector(
|
||||||
let mut context = MatchingContext::new_for_visited(
|
&invalidation.selector,
|
||||||
MatchingMode::Normal,
|
invalidation.offset,
|
||||||
None,
|
self.processor.matching_context(),
|
||||||
self.nth_index_cache.as_mut().map(|c| &mut **c),
|
&self.element
|
||||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited,
|
);
|
||||||
self.quirks_mode,
|
|
||||||
);
|
|
||||||
|
|
||||||
matches_compound_selector(
|
|
||||||
&invalidation.selector,
|
|
||||||
invalidation.offset,
|
|
||||||
&mut context,
|
|
||||||
&self.element
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut invalidated_self = false;
|
let mut invalidated_self = false;
|
||||||
let mut matched = false;
|
let mut matched = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue