Changeset 260319 in webkit


Ignore:
Timestamp:
Apr 18, 2020 1:24:31 PM (4 years ago)
Author:
Antti Koivisto
Message:

[CSS selectors] Support :where() pseudo class
https://bugs.webkit.org/show_bug.cgi?id=210690

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/css/selectors/invalidation/where-expected.txt:

Source/WebCore:

"The Specificity-adjustment pseudo-class, :where(), is a functional pseudo-class with the same
syntax and functionality as :is(). Unlike :is(), neither the :where pseudo-class, nor any of
its arguments contribute to the specificity of the selector—its specificity is always zero.

This is useful for introducing filters in a selector while keeping the associated style
declarations easy to override."

https://drafts.csswg.org/selectors-4/#zero-matches

In terms of implementation this is just another alias for :is() with different (always 0) specificity.

Test: fast/selectors/where-specificity.html

  • css/CSSSelector.cpp:

(WebCore::simpleSelectorSpecificityInternal):

Here is where it differs from PseudoClassIs.

(WebCore::CSSSelector::selectorText const):

  • css/CSSSelector.h:
  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::checkOne const):

  • css/SelectorPseudoClassAndCompatibilityElementMap.in:
  • css/parser/CSSSelectorParser.cpp:

(WebCore::isOnlyPseudoClassFunction):
(WebCore::CSSSelectorParser::consumePseudo):

  • cssjit/SelectorCompiler.cpp:

(WebCore::SelectorCompiler::addPseudoClassType):

LayoutTests:

  • fast/selectors/where-specificity-expected.html: Added.
  • fast/selectors/where-specificity.html: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r260305 r260319  
     12020-04-18  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS selectors] Support :where() pseudo class
     4        https://bugs.webkit.org/show_bug.cgi?id=210690
     5
     6        Reviewed by Sam Weinig.
     7
     8        * fast/selectors/where-specificity-expected.html: Added.
     9        * fast/selectors/where-specificity.html: Added.
     10
    1112020-04-17  Simon Fraser  <simon.fraser@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r260256 r260319  
     12020-04-18  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS selectors] Support :where() pseudo class
     4        https://bugs.webkit.org/show_bug.cgi?id=210690
     5
     6        Reviewed by Sam Weinig.
     7
     8        * web-platform-tests/css/selectors/invalidation/where-expected.txt:
     9
    1102020-04-17  Jason Lawrence  <lawrence.j@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/where-expected.txt

    r259194 r260319  
    66Yellow
    77
    8 FAIL Preconditions. assert_equals: expected "rgb(255, 0, 0)" but got "rgb(0, 0, 0)"
    9 FAIL Invalidate :where() for simple selector arguments. assert_equals: expected "rgb(255, 0, 0)" but got "rgb(0, 0, 0)"
    10 FAIL Invalidate :where() for compound selector arguments. assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
    11 FAIL Invalidate :where() for complex selector arguments. assert_equals: expected "rgb(255, 255, 0)" but got "rgb(0, 0, 0)"
    12 FAIL Invalidate nested :where(). assert_equals: expected "rgb(0, 0, 255)" but got "rgb(0, 0, 0)"
     8PASS Preconditions.
     9PASS Invalidate :where() for simple selector arguments.
     10PASS Invalidate :where() for compound selector arguments.
     11PASS Invalidate :where() for complex selector arguments.
     12PASS Invalidate nested :where().
    1313
  • trunk/Source/WebCore/ChangeLog

    r260317 r260319  
     12020-04-18  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS selectors] Support :where() pseudo class
     4        https://bugs.webkit.org/show_bug.cgi?id=210690
     5
     6        Reviewed by Sam Weinig.
     7
     8        "The Specificity-adjustment pseudo-class, :where(), is a functional pseudo-class with the same
     9        syntax and functionality as :is(). Unlike :is(), neither the :where pseudo-class, nor any of
     10        its arguments contribute to the specificity of the selector—its specificity is always zero.
     11
     12        This is useful for introducing filters in a selector while keeping the associated style
     13        declarations easy to override."
     14
     15        https://drafts.csswg.org/selectors-4/#zero-matches
     16
     17        In terms of implementation this is just another alias for :is() with different (always 0) specificity.
     18
     19        Test: fast/selectors/where-specificity.html
     20
     21        * css/CSSSelector.cpp:
     22        (WebCore::simpleSelectorSpecificityInternal):
     23
     24        Here is where it differs from PseudoClassIs.
     25
     26        (WebCore::CSSSelector::selectorText const):
     27        * css/CSSSelector.h:
     28        * css/SelectorChecker.cpp:
     29        (WebCore::SelectorChecker::checkOne const):
     30        * css/SelectorPseudoClassAndCompatibilityElementMap.in:
     31        * css/parser/CSSSelectorParser.cpp:
     32        (WebCore::isOnlyPseudoClassFunction):
     33        (WebCore::CSSSelectorParser::consumePseudo):
     34        * cssjit/SelectorCompiler.cpp:
     35        (WebCore::SelectorCompiler::addPseudoClassType):
     36
    1372020-04-18  Rob Buis  <rbuis@igalia.com>
    238
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r260069 r260319  
    125125        case CSSSelector::PseudoClassNot:
    126126            return maxSpecificity(*simpleSelector.selectorList());
     127        case CSSSelector::PseudoClassWhere:
     128            return 0;
    127129        case CSSSelector::PseudoClassNthChild:
    128130        case CSSSelector::PseudoClassNthLastChild:
     
    606608                break;
    607609            }
     610            case CSSSelector::PseudoClassWhere: {
     611                builder.appendLiteral(":where(");
     612                cs->selectorList()->buildSelectorsText(builder);
     613                builder.append(')');
     614                break;
     615            }
    608616            case CSSSelector::PseudoClassPlaceholderShown:
    609617                builder.appendLiteral(":placeholder-shown");
  • trunk/Source/WebCore/css/CSSSelector.h

    r260069 r260319  
    124124            PseudoClassIs,
    125125            PseudoClassMatches, // obsolete synonym for PseudoClassIs
     126            PseudoClassWhere,
    126127            PseudoClassOptional,
    127128            PseudoClassPlaceholderShown,
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r260069 r260319  
    799799        case CSSSelector::PseudoClassIs:
    800800        case CSSSelector::PseudoClassMatches:
     801        case CSSSelector::PseudoClassWhere:
    801802            {
    802803                bool hasMatchedAnything = false;
  • trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in

    r259261 r260319  
    7272vertical
    7373visited
     74where
    7475window-inactive
    7576
  • trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp

    r259261 r260319  
    498498    case CSSSelector::PseudoClassIs:
    499499    case CSSSelector::PseudoClassMatches:
     500    case CSSSelector::PseudoClassWhere:
    500501    case CSSSelector::PseudoClassNthChild:
    501502    case CSSSelector::PseudoClassNthLastChild:
     
    635636        }
    636637        case CSSSelector::PseudoClassIs:
    637         case CSSSelector::PseudoClassMatches: {
     638        case CSSSelector::PseudoClassMatches:
     639        case CSSSelector::PseudoClassWhere: {
    638640            auto selectorList = makeUnique<CSSSelectorList>();
    639641            *selectorList = consumeComplexSelectorList(block);
  • trunk/Source/WebCore/cssjit/SelectorCompiler.cpp

    r260069 r260319  
    801801    case CSSSelector::PseudoClassIs:
    802802    case CSSSelector::PseudoClassMatches:
     803    case CSSSelector::PseudoClassWhere:
    803804        {
    804805            SelectorList matchesList;
Note: See TracChangeset for help on using the changeset viewer.