diff options
author | Zach Hoffman <zach@zrhoffman.net> | 2023-03-15 06:56:21 +0000 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-11-21 15:36:35 +0100 |
commit | 356e886d26b75611224bacb5c13cea23dd7f271e (patch) | |
tree | ab7a11f98b70dd77ec1b44f474a10cdb3a0f1496 /components/style/gecko/snapshot_helpers.rs | |
parent | c7f884566514055ad79c4475955cff4f72306865 (diff) | |
download | servo-356e886d26b75611224bacb5c13cea23dd7f271e.tar.gz servo-356e886d26b75611224bacb5c13cea23dd7f271e.zip |
style: Record attribute dependencies within the selector list of :nth-child(... of <selector list>)
There are separate filters for IDs, classes, attribute local names, and
element state.
Also, we invalidate siblings of elements matched against the selector
list of :nth-child(... of <selector list>) by marking matched elements
with NODE_HAS_SLOW_SELECTOR_NTH_OF.
The only remaining invalidation case invalidation case is
`:nth-child(An+B of :has())` (bug 1818155), which should not block
shipping `layout.css.nth-child-of.enabled`, because :has(...) is still
being implemented (bug 418039).
Depends on D172352
Differential Revision: https://phabricator.services.mozilla.com/D171936
Diffstat (limited to 'components/style/gecko/snapshot_helpers.rs')
-rw-r--r-- | components/style/gecko/snapshot_helpers.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/components/style/gecko/snapshot_helpers.rs b/components/style/gecko/snapshot_helpers.rs index 992a3652820..73d740012b2 100644 --- a/components/style/gecko/snapshot_helpers.rs +++ b/components/style/gecko/snapshot_helpers.rs @@ -4,13 +4,17 @@ //! Element an snapshot common logic. +use crate::dom::TElement; use crate::gecko_bindings::bindings; use crate::gecko_bindings::structs::{self, nsAtom}; +use crate::invalidation::element::element_wrapper::ElementSnapshot; +use crate::selector_parser::SnapshotMap; use crate::string_cache::WeakAtom; use crate::values::AtomIdent; use crate::Atom; use crate::CaseSensitivityExt; use selectors::attr::CaseSensitivity; +use smallvec::SmallVec; /// A function that, given an element of type `T`, allows you to get a single /// class or a class list. @@ -166,3 +170,27 @@ where } } } + +/// Returns a list of classes that were either added to or removed from the +/// element since the snapshot. +pub fn classes_changed<E: TElement>(element: &E, snapshots: &SnapshotMap) -> SmallVec<[Atom; 8]> { + debug_assert!(element.has_snapshot(), "Why bothering?"); + let snapshot = snapshots.get(element).expect("has_snapshot lied"); + if !snapshot.class_changed() { + return SmallVec::new(); + } + + let mut classes_changed = SmallVec::<[Atom; 8]>::new(); + snapshot.each_class(|c| { + if !element.has_class(c, CaseSensitivity::CaseSensitive) { + classes_changed.push(c.0.clone()); + } + }); + element.each_class(|c| { + if !snapshot.has_class(c, CaseSensitivity::CaseSensitive) { + classes_changed.push(c.0.clone()); + } + }); + + classes_changed +} |