8000 Fix invalidation for class names within :nth-child() selector lists · WebKit/WebKit@f2bf588 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2bf588

Browse files
committed
Fix invalidation for class names within :nth-child() selector lists
https://bugs.webkit.org/show_bug.cgi?id=250551 rdar://104241960 Reviewed by Darin Adler. There is an optimization in ClassChangeInvalidation that assumes only adding a class makes new elements match. However, it is not true in the case of :nth-child(n of .class), removing the class name can make new elements match too. Special case MatchElement::AnySibling (used by :nth-child() invalidation) to reflect this. Tests: - imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-class.html - imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-sibling.html * LayoutTests/TestExpectations: * Source/WebCore/style/ClassChangeInvalidation.cpp: (WebCore::Style::ClassChangeInvalidation::computeInvalidation): Canonical link: https://commits.webkit.org/258917@main
1 parent 78892eb commit f2bf588

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

LayoutTests/TestExpectations

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,10 +1636,8 @@ webkit.org/b/238822 imported/w3c/web-platform-tests/css/selectors/child-indexed-
16361636
webkit.org/b/238822 imported/w3c/web-platform-tests/css/selectors/selector-structural-pseudo-root.html [ ImageOnlyFailure ]
16371637

16381638
# :nth-child(n of S) invalidation
1639-
imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-class.html [ ImageOnlyFailure ]
16401639
imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-has.html [ ImageOnlyFailure ]
16411640
imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-in-ancestor.html [ ImageOnlyFailure ]
1642-
imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-of-sibling.html [ ImageOnlyFailure ]
16431641
imported/w3c/web-platform-tests/css/selectors/invalidation/nth-child-in-shadow-root.html [ ImageOnlyFailure ]
16441642

16451643
# This test is bit heavy for debug

Source/WebCore/style/ClassChangeInvalidation.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,24 @@ void ClassChangeInvalidation::computeInvalidation(const SpaceSplitString& oldCla
116116

117117
auto& ruleSets = m_element.styleResolver().ruleSets();
118118

119-
auto invalidateBeforeChange = [](ClassChangeType type, IsNegation isNegation) {
120-
if (type == ClassChangeType::Remove)
121-
return isNegation == IsNegation::No;
122-
return isNegation == IsNegation::Yes;
119+
auto invalidateBeforeChange = [](ClassChangeType type, IsNegation isNegation, MatchElement matchElement) {
120+
if (matchElement == MatchElement::AnySibling)
121+
return true;
122+
return type == ClassChangeType::Remove ? isNegation == IsNegation::No : isNegation == IsNegation::Yes;
123+
};
124+
125+
auto invalidateAfterChange = [](ClassChangeType type, IsNegation isNegation, MatchElement matchElement) {
126+
if (matchElement == MatchElement::AnySibling)
127+
return true;
128+
return type == ClassChangeType::Add ? isNegation == IsNegation::No : isNegation == IsNegation::Yes;
123129
};
124130

125131
for (auto& classChange : classChanges) {
126132
if (auto* invalidationRuleSets = ruleSets.classInvalidationRuleSets(classChange.className)) {
127133
for (auto& invalidationRuleSet : *invalidationRuleSets) {
128-
if (invalidateBeforeChange(classChange.type, invalidationRuleSet.isNegation))
134+
if (invalidateBeforeChange(classChange.type, invalidationRuleSet.isNegation, invalidationRuleSet.matchElement))
129135
Invalidator::addToMatchElementRuleSets(m_beforeChangeRuleSets, invalidationRuleSet);
130-
else
136+
if (invalidateAfterChange(classChange.type, invalidationRuleSet.isNegation, invalidationRuleSet.matchElement))
131137
Invalidator::addToMatchElementRuleSets(m_afterChangeRuleSets, invalidationRuleSet);
132138
}
133139
}

0 commit comments

Comments
 (0)
0