12020-04-14 Antti Koivisto <antti@apple.com>
2
3 [CSS Selectors] Selectors Level 4 specificity calculation for pseudo classes
4 https://bugs.webkit.org/show_bug.cgi?id=210419
5
6 Reviewed by Simon Fraser.
7
8 CSS selector specification drafts at some point had a concept of "dynamic specificity" where
9 the specificity of a selector depended on the element it matched. It was only ever used with
10 :matches and :nth-child pseudo classes and has subsequently been removed. Selector specificity
11 can now always be computed statically.
12
13 There is a ton of code to support this obsolete feature. Remove it.
14
15 https://drafts.csswg.org/selectors-4/#specificity-rules
16
17 "The specificity of an :is(), :not(), or :has() pseudo-class is replaced by the specificity
18 of the most specific complex selector in its selector list argument.
19
20 Analogously, the specificity of an :nth-child() or :nth-last-child() selector is the specificity
21 of the pseudo class itself (counting as one pseudo-class selector) plus the specificity of the
22 most specific complex selector in its selector list argument (if any)."
23
24 * css/html.css:
25
26 Reorganize a :matches rule into a selector list to keep the exact specificites.
27 It matters here to select between listbox and menulist correctly based on the 'size' and 'multiple' attributes.
28
29 * css/CSSSelector.cpp:
30 (WebCore::selectorSpecificity):
31 (WebCore::maxSpecificity):
32 (WebCore::simpleSelectorSpecificityInternal):
33 (WebCore::CSSSelector::simpleSelectorSpecificity const):
34
35 Also handle nth here.
36
37 (WebCore::CSSSelector::specificity const):
38 (WebCore::simpleSelectorFunctionalPseudoClassStaticSpecificity): Deleted.
39 (WebCore::functionalPseudoClassStaticSpecificity): Deleted.
40 (WebCore::staticSpecificityInternal): Deleted.
41 (WebCore::CSSSelector::staticSpecificity const): Deleted.
42
43 Rename to just computeSpecificity(), there is no other kind than static.
44
45 * css/CSSSelector.h:
46 * css/SelectorChecker.cpp:
47 (WebCore::SelectorChecker::match const):
48 (WebCore::SelectorChecker::matchHostPseudoClass const):
49 (WebCore::SelectorChecker::matchRecursively const):
50 (WebCore::SelectorChecker::checkOne const):
51 (WebCore::SelectorChecker::matchSelectorList const):
52
53 SelectorChecker doesn't need to deal with specificity anymore.
54
55 * css/SelectorChecker.h:
56 * cssjit/SelectorCompiler.cpp:
57 (WebCore::SelectorCompiler::addNthChildType):
58 (WebCore::SelectorCompiler::addPseudoClassType):
59 (WebCore::SelectorCompiler::constructFragmentsInternal):
60 (WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker):
61 (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementAttributeFunctionCallValueMatching):
62
63 Neither does SelectorCompiler.
64
65 * cssjit/SelectorCompiler.h:
66 * dom/SelectorQuery.cpp:
67 (WebCore::SelectorDataList::selectorMatches const):
68 (WebCore::SelectorDataList::selectorClosest const):
69 * inspector/InspectorStyleSheet.cpp:
70 (WebCore::buildObjectForSelectorHelper):
71 (WebCore::selectorsFromSource):
72 (WebCore::InspectorStyleSheet::buildObjectForSelector):
73 (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
74 (WebCore::InspectorStyleSheet::buildObjectForRule):
75 (WebCore::InspectorStyleSheet::buildArrayForRuleList):
76 (WebCore::hasDynamicSpecificity): Deleted.
77 * inspector/InspectorStyleSheet.h:
78 * inspector/agents/InspectorCSSAgent.cpp:
79 (WebCore::InspectorCSSAgent::setRuleSelector):
80 (WebCore::InspectorCSSAgent::addRule):
81 (WebCore::InspectorCSSAgent::buildObjectForRule):
82 (WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList):
83 * inspector/agents/InspectorDOMAgent.cpp:
84 (WebCore::InspectorDOMAgent::highlightSelector):
85 * style/ElementRuleCollector.cpp:
86 (WebCore::Style::ElementRuleCollector::ruleMatches):
87
88 Switch to get the specificity from the selector instead of computing it during selector checking.
89
90 * style/ElementRuleCollector.h:
91