Ignore:
Timestamp:
Oct 20, 2020, 10:07:25 AM (5 years ago)
Author:
Antti Koivisto
Message:

Implement <forgiving-selector-list> for :is/:where
https://bugs.webkit.org/show_bug.cgi?id=217814
<rdar://problem/70384483>

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/css/selectors/is-where-error-recovery-expected.txt:
  • web-platform-tests/css/selectors/is-where-not-expected.txt:

Source/WebCore:

The spec now says :is/:where should parse as a forgiving selector list: https://drafts.csswg.org/selectors/#matches

  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::isValidCSSSelector):

  • css/CSSPageRule.cpp:

(WebCore::CSSPageRule::setSelectorText):

  • css/CSSSelectorList.h:

(WebCore::CSSSelectorList::isEmpty const):
(WebCore::CSSSelectorList::isValid const): Deleted.

An empty CSSSelectorList is now valid.
Represent invalid CSSSelectorList with Optional where needed.

  • css/CSSStyleRule.cpp:

(WebCore::CSSStyleRule::setSelectorText):

  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseSelector):

  • css/parser/CSSParser.h:
  • css/parser/CSSParserImpl.cpp:

(WebCore::CSSParserImpl::consumePageRule):
(WebCore::CSSParserImpl::consumeStyleRule):

  • css/parser/CSSSelectorParser.cpp:

(WebCore::parseCSSSelector):
(WebCore::CSSSelectorParser::consumeComplexSelectorList):
(WebCore::CSSSelectorParser::consumeComplexForgivingSelectorList):

Add function for consuming <forgiving-selector-list>.

(WebCore::CSSSelectorParser::consumePseudo):

Use it for :is/:where.

  • css/parser/CSSSelectorParser.h:
  • dom/SelectorQuery.cpp:
  • inspector/InspectorStyleSheet.cpp:

(WebCore::isValidSelectorListString):

  • inspector/agents/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::highlightSelector):

  • style/RuleSet.cpp:

(WebCore::Style::RuleSet::addStyleRule):

LayoutTests:

Update some selector parsing tests to log the results instead of PASS/FAIL as forgiving
parsing allows many combinations involving :is/:where.

Remove a few repetetive tests that don't add anything.

  • fast/css/parsing-css-attribute-case-insensitive-value-4-expected.txt: Removed.
  • fast/css/parsing-css-attribute-case-insensitive-value-4.html: Removed.
  • fast/css/parsing-css-is-5-expected.txt:
  • fast/css/parsing-css-is-5.html:
  • fast/css/parsing-css-is-6-expected.txt:
  • fast/css/parsing-css-is-6.html:
  • fast/css/parsing-css-is-7-expected.txt:
  • fast/css/parsing-css-is-7.html:
  • fast/css/parsing-css-is-8-expected.txt:
  • fast/css/parsing-css-is-8.html:
  • fast/css/parsing-css-matches-5-expected.txt: Removed.
  • fast/css/parsing-css-matches-5.html: Removed.
  • fast/css/parsing-css-matches-6-expected.txt: Removed.
  • fast/css/parsing-css-matches-6.html: Removed.
  • fast/css/parsing-css-matches-7-expected.txt: Removed.
  • fast/css/parsing-css-matches-7.html: Removed.
  • fast/css/parsing-css-matches-8-expected.txt: Removed.
  • fast/css/parsing-css-matches-8.html: Removed.
  • fast/css/parsing-css-not-5-expected.txt:
  • fast/css/parsing-css-not-5.html:
  • fast/css/parsing-css-not-6-expected.txt:
  • fast/css/parsing-css-not-6.html:
  • fast/css/parsing-css-not-7-expected.txt:
  • fast/css/parsing-css-not-7.html:
  • fast/css/parsing-css-not-8-expected.txt:
  • fast/css/parsing-css-not-8.html:
  • fast/css/parsing-css-not-9-expected.txt:
  • fast/css/parsing-css-not-9.html:
  • fast/css/parsing-css-nth-child-of-4-expected.txt:
  • fast/css/parsing-css-nth-child-of-4.html:
  • fast/css/parsing-css-nth-last-child-of-4-expected.txt:
  • fast/css/parsing-css-nth-last-child-of-4.html:
  • fast/selectors/invalid-functional-pseudo-class-expected.txt:
  • fast/selectors/invalid-functional-pseudo-class.html:
  • fast/selectors/pseudo-element-in-is-where-expected.html:
  • fast/selectors/pseudo-element-in-is-where.html:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSStyleRule.cpp

    r252599 r268741  
    9292
    9393    CSSParser p(parserContext());
    94     CSSSelectorList selectorList;
    95     p.parseSelector(selectorText, selectorList);
    96     if (!selectorList.isValid())
     94    auto selectorList = p.parseSelector(selectorText);
     95    if (!selectorList)
    9796        return;
    9897
    9998    // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369>
    100     if (selectorList.componentCount() > Style::RuleData::maximumSelectorComponentCount)
     99    if (selectorList->componentCount() > Style::RuleData::maximumSelectorComponentCount)
    101100        return;
    102101
    103102    CSSStyleSheet::RuleMutationScope mutationScope(this);
    104103
    105     m_styleRule->wrapperAdoptSelectorList(WTFMove(selectorList));
     104    m_styleRule->wrapperAdoptSelectorList(WTFMove(*selectorList));
    106105
    107106    if (hasCachedSelectorText()) {
Note: See TracChangeset for help on using the changeset viewer.