Make the Selector's specificity part of Selector matching
https://bugs.webkit.org/show_bug.cgi?id=138486

Reviewed by Andreas Kling.

In CSS Selectors Level 4, the specificity of selectors is computed dynamically
based on which element is being matched.

For example, a selector:
    :matches(#foo, .bar, baz)
has a specificity of
    (1, 0, 0) on <baz id=foo class=bar>
    (0, 1, 0) on <baz class=bar>
    (0, 0, 1) on <baz>

Previously, the specificity of each selector was computed statically when populating
RuleSet. With more recent CSS, this gives us the wrong specificity because we do not know
how the selectors applies to the target.

This patch moves one tiny step in the direction of dynamic specificity. The specificity
is removed from RuleSet and is moved inside Selector Matching.

There is one bit worth keeping static: matching based on rule hash. This path is important
to avoid spending time compiling trivial selectors.
In order to keep rule hash matching working, the RuleData store which specificity class
the rule has in addition to the information about matching/not-matching. When going through
the fast path in ElementCollector, we compute the right specificity based on the type
of rule-hash matching.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::specificityForOneSelector):
* css/CSSSelector.h:
* css/ElementRuleCollector.cpp:
(WebCore::ElementRuleCollector::addMatchedRule):
(WebCore::ElementRuleCollector::sortAndTransferMatchedRules):
(WebCore::ElementRuleCollector::ruleMatches):
(WebCore::ElementRuleCollector::collectMatchingRulesForList):
(WebCore::compareRules):
* css/ElementRuleCollector.h:
* css/RuleSet.cpp:
(WebCore::computeMatchBasedOnRuleHash):
(WebCore::RuleData::RuleData):
(WebCore::isSelectorMatchingHTMLBasedOnRuleHash): Deleted.
* css/RuleSet.h:
(WebCore::RuleData::matchBasedOnRuleHash):
(WebCore::RuleData::hasRightmostSelectorMatchingHTMLBasedOnRuleHash): Deleted.
(WebCore::RuleData::specificity): Deleted.
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::match):
* css/SelectorChecker.h:
* css/StyleResolver.h:
(WebCore::checkRegionSelector):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::SelectorCodeGenerator::SelectorCodeGenerator):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateSelectorChecker):
* cssjit/SelectorCompiler.h:
(WebCore::SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction):
(WebCore::SelectorCompiler::querySelectorSimpleSelectorCheckerFunction):
(WebCore::SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext):
(WebCore::SelectorCompiler::querySelectorSelectorCheckerFunctionWithCheckingContext):
(WebCore::SelectorCompiler::simpleSelectorCheckerFunction): Deleted.
(WebCore::SelectorCompiler::selectorCheckerFunctionWithCheckingContext): Deleted.
* dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::selectorMatches):
(WebCore::SelectorDataList::selectorClosest):
(WebCore::SelectorDataList::executeCompiledSimpleSelectorChecker):
(WebCore::SelectorDataList::executeCompiledSelectorCheckerWithCheckingContext):
(WebCore::SelectorDataList::executeCompiledSingleMultiSelectorData):
(WebCore::SelectorDataList::execute):
* dom/SelectorQuery.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@175772 268f45cc-cd09-0410-ab3c-d52691b4dbfc