haikuwebkit/LayoutTests/fast/css/matches-specificity-2-expec...

14 lines
163 B
HTML
Raw Permalink Normal View History

Add the initial implementation of dynamic specificity for :matches() https://bugs.webkit.org/show_bug.cgi?id=138822 Reviewed by Andreas Kling. Source/WebCore: Previously we completely ignored the selector list of :matches() when computing the specificity of the selector. The spec (http://dev.w3.org/csswg/selectors4/#specificity) says: "The specificity of a :matches() pseudo-class, however, is the specificity of the most specific complex selector that matched the given element." This patch does just that. In the CSS JIT, we only consider specificities that can be computed statically for now, this should be extended later. When the specificity is dynamic, we fall back to SelectorChecker. In that case, we execute every selector of the selector list and we keep the maximum value as the specificity for the whole :matches(). Tests: fast/css/matches-specificity-1.html fast/css/matches-specificity-2.html fast/css/matches-specificity-3.html fast/css/matches-specificity-4.html fast/css/matches-specificity-5.html fast/css/matches-specificity-6.html fast/css/matches-specificity-7.html fast/css/matches-specificity-8.html fast/css/matches-specificity-9.html fast/css/matches-specificity-10.html * css/CSSSelector.cpp: (WebCore::selectorSpecificity): (WebCore::maxSpecificity): (WebCore::CSSSelector::specificity): (WebCore::simpleSelectorSpecificityInternal): (WebCore::CSSSelector::simpleSelectorSpecificity): :matches() itself should not have any specificity. The specificity of its components is computed in SelectorChecker. Since :matches() is no longer accounted as a class B specificity, I had to finish the specificity of :not() or some test breaks. * css/CSSSelector.h: * css/PageRuleCollector.cpp: (WebCore::comparePageRules): * css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne): We can no longer shortcut the execution when context.pseudoElementEffective is false. There is no guarantee that a following selector wouldn't match with a higher specificity. * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator): (WebCore::SelectorCompiler::constructFragments): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker): LayoutTests: * fast/css/matches-specificity-1-expected.html: Added. * fast/css/matches-specificity-1.html: Added. * fast/css/matches-specificity-2-expected.html: Added. * fast/css/matches-specificity-2.html: Added. * fast/css/matches-specificity-3-expected.html: Added. * fast/css/matches-specificity-3.html: Added. * fast/css/matches-specificity-4-expected.html: Added. * fast/css/matches-specificity-4.html: Added. * fast/css/matches-specificity-5-expected.html: Added. * fast/css/matches-specificity-5.html: Added. * fast/css/matches-specificity-6-expected.html: Added. * fast/css/matches-specificity-6.html: Added. * fast/css/matches-specificity-7-expected.html: Added. * fast/css/matches-specificity-7.html: Added. * fast/css/matches-specificity-8-expected.html: Added. * fast/css/matches-specificity-8.html: Added. * fast/css/matches-specificity-9-expected.html: Added. * fast/css/matches-specificity-9.html: Added. * fast/css/matches-specificity-10-expected.html: Added. * fast/css/matches-specificity-10.html: Added. Canonical link: https://commits.webkit.org/156716@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176307 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-11-19 05:12:53 +00:00
<!doctype html>
<html>
<head>
<style>
* {
border: none;
}
</style>
</head>
<body>
[CSS Selectors] Selectors Level 4 specificity calculation for pseudo classes https://bugs.webkit.org/show_bug.cgi?id=210419 Reviewed by Simon Fraser. LayoutTests/imported/w3c: * web-platform-tests/css/selectors/invalidation/is-expected.txt: Source/WebCore: CSS selector specification drafts at some point had a concept of "dynamic specificity" where the specificity of a selector depended on the element it matched. It was only ever used with :matches and :nth-child pseudo classes and has subsequently been removed. Selector specificity can now always be computed statically. There is a ton of code to support this obsolete feature. Remove it. https://drafts.csswg.org/selectors-4/#specificity-rules "The specificity of an :is(), :not(), or :has() pseudo-class is replaced by the specificity of the most specific complex selector in its selector list argument. Analogously, the specificity of an :nth-child() or :nth-last-child() selector is the specificity of the pseudo class itself (counting as one pseudo-class selector) plus the specificity of the most specific complex selector in its selector list argument (if any)." * css/html.css: Reorganize a :matches rule into a selector list to keep the exact specificites. It matters here to select between listbox and menulist correctly based on the 'size' and 'multiple' attributes. * css/CSSSelector.cpp: (WebCore::selectorSpecificity): (WebCore::maxSpecificity): (WebCore::simpleSelectorSpecificityInternal): (WebCore::CSSSelector::simpleSelectorSpecificity const): Also handle nth here. (WebCore::CSSSelector::specificity const): (WebCore::simpleSelectorFunctionalPseudoClassStaticSpecificity): Deleted. (WebCore::functionalPseudoClassStaticSpecificity): Deleted. (WebCore::staticSpecificityInternal): Deleted. (WebCore::CSSSelector::staticSpecificity const): Deleted. Rename to just computeSpecificity(), there is no other kind than static. * css/CSSSelector.h: * css/SelectorChecker.cpp: (WebCore::SelectorChecker::match const): (WebCore::SelectorChecker::matchHostPseudoClass const): (WebCore::SelectorChecker::matchRecursively const): (WebCore::SelectorChecker::checkOne const): (WebCore::SelectorChecker::matchSelectorList const): SelectorChecker doesn't need to deal with specificity anymore. * css/SelectorChecker.h: * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addNthChildType): (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::constructFragmentsInternal): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementAttributeFunctionCallValueMatching): Neither does SelectorCompiler. * cssjit/SelectorCompiler.h: * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::selectorMatches const): (WebCore::SelectorDataList::selectorClosest const): * inspector/InspectorStyleSheet.cpp: (WebCore::buildObjectForSelectorHelper): (WebCore::selectorsFromSource): (WebCore::InspectorStyleSheet::buildObjectForSelector): (WebCore::InspectorStyleSheet::buildObjectForSelectorList): (WebCore::InspectorStyleSheet::buildObjectForRule): (WebCore::InspectorStyleSheet::buildArrayForRuleList): (WebCore::hasDynamicSpecificity): Deleted. * inspector/InspectorStyleSheet.h: * inspector/agents/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::setRuleSelector): (WebCore::InspectorCSSAgent::addRule): (WebCore::InspectorCSSAgent::buildObjectForRule): (WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList): * inspector/agents/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::highlightSelector): * style/ElementRuleCollector.cpp: (WebCore::Style::ElementRuleCollector::ruleMatches): Switch to get the specificity from the selector instead of computing it during selector checking. * style/ElementRuleCollector.h: LayoutTests: Update specificity tests for static behavior, trying to also keep them useful. * fast/css/is-specificity-10-expected.html: * fast/css/is-specificity-10.html: * fast/css/is-specificity-2-expected.html: * fast/css/is-specificity-2.html: * fast/css/is-specificity-3-expected.html: * fast/css/is-specificity-3.html: * fast/css/is-specificity-4-expected.html: * fast/css/is-specificity-4.html: * fast/css/is-specificity-5.html: * fast/css/matches-specificity-10-expected.html: * fast/css/matches-specificity-10.html: * fast/css/matches-specificity-2-expected.html: * fast/css/matches-specificity-2.html: * fast/css/matches-specificity-3-expected.html: * fast/css/matches-specificity-3.html: * fast/css/matches-specificity-4-expected.html: * fast/css/matches-specificity-4.html: * fast/css/matches-specificity-5.html: * fast/css/nth-child-specificity-2-expected.html: * fast/css/nth-child-specificity-2.html: * fast/css/nth-child-specificity-3-expected.html: * fast/css/nth-child-specificity-3.html: * fast/css/nth-child-specificity-4-expected.html: * fast/css/nth-child-specificity-4.html: * fast/css/nth-last-child-specificity-2-expected.html: * fast/css/nth-last-child-specificity-2.html: * fast/css/nth-last-child-specificity-3-expected.html: * fast/css/nth-last-child-specificity-3.html: * fast/css/nth-last-child-specificity-4-expected.html: * fast/css/nth-last-child-specificity-4.html: Canonical link: https://commits.webkit.org/223365@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@260069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-04-14 11:37:40 +00:00
<target style="color: blue;">Target</target>
Add the initial implementation of dynamic specificity for :matches() https://bugs.webkit.org/show_bug.cgi?id=138822 Reviewed by Andreas Kling. Source/WebCore: Previously we completely ignored the selector list of :matches() when computing the specificity of the selector. The spec (http://dev.w3.org/csswg/selectors4/#specificity) says: "The specificity of a :matches() pseudo-class, however, is the specificity of the most specific complex selector that matched the given element." This patch does just that. In the CSS JIT, we only consider specificities that can be computed statically for now, this should be extended later. When the specificity is dynamic, we fall back to SelectorChecker. In that case, we execute every selector of the selector list and we keep the maximum value as the specificity for the whole :matches(). Tests: fast/css/matches-specificity-1.html fast/css/matches-specificity-2.html fast/css/matches-specificity-3.html fast/css/matches-specificity-4.html fast/css/matches-specificity-5.html fast/css/matches-specificity-6.html fast/css/matches-specificity-7.html fast/css/matches-specificity-8.html fast/css/matches-specificity-9.html fast/css/matches-specificity-10.html * css/CSSSelector.cpp: (WebCore::selectorSpecificity): (WebCore::maxSpecificity): (WebCore::CSSSelector::specificity): (WebCore::simpleSelectorSpecificityInternal): (WebCore::CSSSelector::simpleSelectorSpecificity): :matches() itself should not have any specificity. The specificity of its components is computed in SelectorChecker. Since :matches() is no longer accounted as a class B specificity, I had to finish the specificity of :not() or some test breaks. * css/CSSSelector.h: * css/PageRuleCollector.cpp: (WebCore::comparePageRules): * css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne): We can no longer shortcut the execution when context.pseudoElementEffective is false. There is no guarantee that a following selector wouldn't match with a higher specificity. * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator): (WebCore::SelectorCompiler::constructFragments): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker): LayoutTests: * fast/css/matches-specificity-1-expected.html: Added. * fast/css/matches-specificity-1.html: Added. * fast/css/matches-specificity-2-expected.html: Added. * fast/css/matches-specificity-2.html: Added. * fast/css/matches-specificity-3-expected.html: Added. * fast/css/matches-specificity-3.html: Added. * fast/css/matches-specificity-4-expected.html: Added. * fast/css/matches-specificity-4.html: Added. * fast/css/matches-specificity-5-expected.html: Added. * fast/css/matches-specificity-5.html: Added. * fast/css/matches-specificity-6-expected.html: Added. * fast/css/matches-specificity-6.html: Added. * fast/css/matches-specificity-7-expected.html: Added. * fast/css/matches-specificity-7.html: Added. * fast/css/matches-specificity-8-expected.html: Added. * fast/css/matches-specificity-8.html: Added. * fast/css/matches-specificity-9-expected.html: Added. * fast/css/matches-specificity-9.html: Added. * fast/css/matches-specificity-10-expected.html: Added. * fast/css/matches-specificity-10.html: Added. Canonical link: https://commits.webkit.org/156716@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176307 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-11-19 05:12:53 +00:00
</body>
</html>