summaryrefslogtreecommitdiffstats
path: root/servo/components/style/invalidation/element/state_and_attributes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'servo/components/style/invalidation/element/state_and_attributes.rs')
-rw-r--r--servo/components/style/invalidation/element/state_and_attributes.rs66
1 files changed, 48 insertions, 18 deletions
diff --git a/servo/components/style/invalidation/element/state_and_attributes.rs b/servo/components/style/invalidation/element/state_and_attributes.rs
index 1c58cddf1e..d5f0723d66 100644
--- a/servo/components/style/invalidation/element/state_and_attributes.rs
+++ b/servo/components/style/invalidation/element/state_and_attributes.rs
@@ -19,11 +19,12 @@ use crate::selector_map::SelectorMap;
use crate::selector_parser::Snapshot;
use crate::stylesheets::origin::OriginSet;
use crate::{Atom, WeakAtom};
+use crate::values::AtomIdent;
use dom::ElementState;
use selectors::attr::CaseSensitivity;
+use selectors::kleene_value::KleeneValue;
use selectors::matching::{
- matches_selector, MatchingContext, MatchingForInvalidation, MatchingMode, NeedsSelectorFlags,
- SelectorCaches, VisitedHandlingMode,
+ matches_selector_kleene, MatchingContext, MatchingForInvalidation, MatchingMode, NeedsSelectorFlags, SelectorCaches, VisitedHandlingMode
};
use smallvec::SmallVec;
@@ -41,6 +42,8 @@ where
added_id: Option<&'a WeakAtom>,
classes_removed: &'a SmallVec<[Atom; 8]>,
classes_added: &'a SmallVec<[Atom; 8]>,
+ custom_states_removed: &'a SmallVec<[AtomIdent; 8]>,
+ custom_states_added: &'a SmallVec<[AtomIdent; 8]>,
state_changes: ElementState,
descendant_invalidations: &'a mut DescendantInvalidationLists<'selectors>,
sibling_invalidations: &'a mut InvalidationVector<'selectors>,
@@ -97,23 +100,25 @@ where
E: TElement,
W: selectors::Element<Impl = E::Impl>,
{
- let matches_now = matches_selector(
- &dependency.selector,
- dependency.selector_offset,
- None,
- element,
- context,
- );
+ context.for_invalidation_comparison(|context| {
+ let matches_now = matches_selector_kleene(
+ &dependency.selector,
+ dependency.selector_offset,
+ None,
+ element,
+ context,
+ );
- let matched_then = matches_selector(
- &dependency.selector,
- dependency.selector_offset,
- None,
- wrapper,
- context,
- );
+ let matched_then = matches_selector_kleene(
+ &dependency.selector,
+ dependency.selector_offset,
+ None,
+ wrapper,
+ context,
+ );
- matched_then != matches_now
+ matched_then != matches_now || matches_now == KleeneValue::Unknown
+ })
}
/// Whether we should process the descendants of a given element for style
@@ -243,7 +248,7 @@ where
return false;
};
- if !snapshot.has_attrs() && state_changes.is_empty() {
+ if !snapshot.has_attrs() && !snapshot.has_custom_states() && state_changes.is_empty() {
return false;
}
@@ -264,6 +269,21 @@ where
})
}
+ let mut custom_states_removed = SmallVec::<[AtomIdent; 8]>::new();
+ let mut custom_states_added = SmallVec::<[AtomIdent; 8]>::new();
+ if snapshot.has_custom_states() {
+ snapshot.each_custom_state(|s| {
+ if !element.has_custom_state(s) {
+ custom_states_removed.push(s.clone())
+ }
+ });
+ element.each_custom_state(|s| {
+ if !snapshot.has_custom_state(s) {
+ custom_states_added.push(s.clone())
+ }
+ })
+ }
+
let mut id_removed = None;
let mut id_added = None;
if snapshot.id_changed() {
@@ -326,6 +346,8 @@ where
added_id: id_added,
classes_removed: &classes_removed,
classes_added: &classes_added,
+ custom_states_removed: &custom_states_removed,
+ custom_states_added: &custom_states_added,
descendant_invalidations,
sibling_invalidations,
invalidates_self: false,
@@ -443,6 +465,14 @@ where
}
}
+ for state in self.custom_states_added.iter().chain(self.custom_states_removed.iter()) {
+ if let Some(deps) = map.custom_state_affecting_selectors.get(state) {
+ for dep in deps {
+ self.scan_dependency(dep);
+ }
+ }
+ }
+
self.snapshot.each_attr_changed(|attribute| {
if let Some(deps) = map.other_attribute_affecting_selectors.get(attribute) {
for dep in deps {