Changeset 179819 in webkit


Ignore:
Timestamp:
Feb 8, 2015 7:44:57 PM (9 years ago)
Author:
benjamin@webkit.org
Message:

Add parsing support for CSS Selector L4's case-insensitive attribute
https://bugs.webkit.org/show_bug.cgi?id=141373

Reviewed by Darin Adler.

Source/WebCore:

This patch adds parsing for the case-insensitive attribute value
matching of CSS Selectors Level 4: http://dev.w3.org/csswg/selectors-4/#attribute-case
Excuse of a grammar: http://dev.w3.org/csswg/selectors-4/#grammar

This patch also covers serialization for CSSOM. The serialization
is defined here: http://dev.w3.org/csswg/cssom/#serializing-selectors

Matching is completely ignored in this patch. All the simple selectors
are treated as regular attribute selectors.

Tests: fast/css/parsing-css-attribute-case-insensitive-value-1.html

fast/css/parsing-css-attribute-case-insensitive-value-2.html
fast/css/parsing-css-attribute-case-insensitive-value-3.html
fast/css/parsing-css-attribute-case-insensitive-value-4.html

  • css/CSSGrammar.y.in:
  • css/CSSParserValues.h:

(WebCore::CSSParserSelector::setAttributeValueMatchingIsCaseInsensitive):

  • css/CSSSelector.cpp:

(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::selectorText):

  • css/CSSSelector.h:

(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::setAttributeValueMatchingIsCaseInsensitive):
(WebCore::CSSSelector::attributeValueMatchingIsCaseInsensitive):

LayoutTests:

  • fast/css/css-selector-text-expected.txt:
  • fast/css/css-selector-text.html:
  • fast/css/css-set-selector-text-expected.txt:
  • fast/css/css-set-selector-text.html:

Basic round-trip serialization through CSSOM.

  • fast/css/parsing-css-attribute-case-insensitive-value-1-expected.txt: Added.
  • fast/css/parsing-css-attribute-case-insensitive-value-1.html: Added.

Simple cases by themself and used in complex selectors.

  • fast/css/parsing-css-attribute-case-insensitive-value-2-expected.txt: Added.
  • fast/css/parsing-css-attribute-case-insensitive-value-2.html: Added.

Less simple cases, all kinds of valid syntax for case-insensitive attributes.

  • fast/css/parsing-css-attribute-case-insensitive-value-3-expected.txt: Added.
  • fast/css/parsing-css-attribute-case-insensitive-value-3.html: Added.

Cases that must be treated as invalid selectors.

  • fast/css/parsing-css-attribute-case-insensitive-value-4-expected.txt: Added.
  • fast/css/parsing-css-attribute-case-insensitive-value-4.html: Added.

Verify that invalid rules do not affect surrounding valid rules.

Location:
trunk
Files:
8 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r179818 r179819  
     12015-02-08  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Add parsing support for CSS Selector L4's case-insensitive attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=141373
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/css/css-selector-text-expected.txt:
     9        * fast/css/css-selector-text.html:
     10        * fast/css/css-set-selector-text-expected.txt:
     11        * fast/css/css-set-selector-text.html:
     12        Basic round-trip serialization through CSSOM.
     13
     14        * fast/css/parsing-css-attribute-case-insensitive-value-1-expected.txt: Added.
     15        * fast/css/parsing-css-attribute-case-insensitive-value-1.html: Added.
     16        Simple cases by themself and used in complex selectors.
     17
     18        * fast/css/parsing-css-attribute-case-insensitive-value-2-expected.txt: Added.
     19        * fast/css/parsing-css-attribute-case-insensitive-value-2.html: Added.
     20        Less simple cases, all kinds of valid syntax for case-insensitive attributes.
     21
     22        * fast/css/parsing-css-attribute-case-insensitive-value-3-expected.txt: Added.
     23        * fast/css/parsing-css-attribute-case-insensitive-value-3.html: Added.
     24        Cases that must be treated as invalid selectors.
     25
     26        * fast/css/parsing-css-attribute-case-insensitive-value-4-expected.txt: Added.
     27        * fast/css/parsing-css-attribute-case-insensitive-value-4.html: Added.
     28        Verify that invalid rules do not affect surrounding valid rules.
     29
    1302015-02-08  David Kilzer  <ddkilzer@apple.com>
    231
  • trunk/LayoutTests/fast/css/css-selector-text-expected.txt

    r178592 r179819  
    1616PASS parseThenSerializeRule('[a$="b"] { }') is '[a$="b"] { }'
    1717PASS parseThenSerializeRule('[a*="b"] { }') is '[a*="b"] { }'
     18PASS parseThenSerializeRule('[a="b" i] { }') is '[a="b" i] { }'
     19PASS parseThenSerializeRule('[a~="b" i] { }') is '[a~="b" i] { }'
     20PASS parseThenSerializeRule('[a|="b" i] { }') is '[a|="b" i] { }'
     21PASS parseThenSerializeRule('[a^="b" i] { }') is '[a^="b" i] { }'
     22PASS parseThenSerializeRule('[a$="b" i] { }') is '[a$="b" i] { }'
     23PASS parseThenSerializeRule('[a*="b" i] { }') is '[a*="b" i] { }'
    1824
    1925PASS parseThenSerializeRule('*|a { }') is '*|a { }'
  • trunk/LayoutTests/fast/css/css-selector-text.html

    r178592 r179819  
    4141testSelectorRoundTrip('[a$="b"]');
    4242testSelectorRoundTrip('[a*="b"]');
     43testSelectorRoundTrip('[a="b" i]');
     44testSelectorRoundTrip('[a~="b" i]');
     45testSelectorRoundTrip('[a|="b" i]');
     46testSelectorRoundTrip('[a^="b" i]');
     47testSelectorRoundTrip('[a$="b" i]');
     48testSelectorRoundTrip('[a*="b" i]');
    4349
    4450debug('');
  • trunk/LayoutTests/fast/css/css-set-selector-text-expected.txt

    r178592 r179819  
    2626PASS setThenReadSelectorText('[a$="b"]') is '[a$="b"]'
    2727PASS setThenReadSelectorText('[a*="b"]') is '[a*="b"]'
     28PASS setThenReadSelectorText('[a="b" i]') is '[a="b" i]'
     29PASS setThenReadSelectorText('[a~="b" i]') is '[a~="b" i]'
     30PASS setThenReadSelectorText('[a|="b" i]') is '[a|="b" i]'
     31PASS setThenReadSelectorText('[a^="b" i]') is '[a^="b" i]'
     32PASS setThenReadSelectorText('[a$="b" i]') is '[a$="b" i]'
     33PASS setThenReadSelectorText('[a*="b" i]') is '[a*="b" i]'
    2834
    2935PASS setThenReadSelectorText('*|a') is '*|a'
  • trunk/LayoutTests/fast/css/css-set-selector-text.html

    r178592 r179819  
    5858testSelectorRoundTrip('[a$="b"]');
    5959testSelectorRoundTrip('[a*="b"]');
     60testSelectorRoundTrip('[a="b" i]');
     61testSelectorRoundTrip('[a~="b" i]');
     62testSelectorRoundTrip('[a|="b" i]');
     63testSelectorRoundTrip('[a^="b" i]');
     64testSelectorRoundTrip('[a$="b" i]');
     65testSelectorRoundTrip('[a*="b" i]');
    6066
    6167debug('');
  • trunk/Source/WebCore/ChangeLog

    r179813 r179819  
     12015-02-08  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        Add parsing support for CSS Selector L4's case-insensitive attribute
     4        https://bugs.webkit.org/show_bug.cgi?id=141373
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch adds parsing for the case-insensitive attribute value
     9        matching of CSS Selectors Level 4: http://dev.w3.org/csswg/selectors-4/#attribute-case
     10        Excuse of a grammar: http://dev.w3.org/csswg/selectors-4/#grammar
     11
     12        This patch also covers serialization for CSSOM. The serialization
     13        is defined here: http://dev.w3.org/csswg/cssom/#serializing-selectors
     14
     15        Matching is completely ignored in this patch. All the simple selectors
     16        are treated as regular attribute selectors.
     17
     18        Tests: fast/css/parsing-css-attribute-case-insensitive-value-1.html
     19               fast/css/parsing-css-attribute-case-insensitive-value-2.html
     20               fast/css/parsing-css-attribute-case-insensitive-value-3.html
     21               fast/css/parsing-css-attribute-case-insensitive-value-4.html
     22
     23        * css/CSSGrammar.y.in:
     24        * css/CSSParserValues.h:
     25        (WebCore::CSSParserSelector::setAttributeValueMatchingIsCaseInsensitive):
     26        * css/CSSSelector.cpp:
     27        (WebCore::CSSSelector::CSSSelector):
     28        (WebCore::CSSSelector::selectorText):
     29        * css/CSSSelector.h:
     30        (WebCore::CSSSelector::CSSSelector):
     31        (WebCore::CSSSelector::setAttributeValueMatchingIsCaseInsensitive):
     32        (WebCore::CSSSelector::attributeValueMatchingIsCaseInsensitive):
     33
    1342015-02-08  Darin Adler  <darin@apple.com>
    235
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r179485 r179819  
    307307
    308308%union { bool boolean; }
    309 %type <boolean> declaration declaration_list decl_list priority
     309%type <boolean> attrib_flags declaration declaration_list decl_list priority
    310310
    311311%union { CSSSelector::Match match; }
     
    12641264        $$->setMatch(CSSSelector::Set);
    12651265    }
    1266     | '[' maybe_space IDENT maybe_space match maybe_space ident_or_string maybe_space ']' {
     1266    | '[' maybe_space IDENT maybe_space match maybe_space ident_or_string maybe_space attrib_flags ']' {
    12671267        $$ = new CSSParserSelector;
    12681268        $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom), parser->m_context.isHTMLDocument);
    12691269        $$->setMatch($5);
    12701270        $$->setValue($7);
     1271        $$->setAttributeValueMatchingIsCaseInsensitive($9);
    12711272    }
    12721273    | '[' maybe_space namespace_selector IDENT maybe_space ']' {
     
    12751276        $$->setMatch(CSSSelector::Set);
    12761277    }
    1277     | '[' maybe_space namespace_selector IDENT maybe_space match maybe_space ident_or_string maybe_space ']' {
     1278    | '[' maybe_space namespace_selector IDENT maybe_space match maybe_space ident_or_string maybe_space attrib_flags ']' {
    12781279        $$ = new CSSParserSelector;
    12791280        $$->setAttribute(parser->determineNameInNamespace($3, $4), parser->m_context.isHTMLDocument);
    12801281        $$->setMatch($6);
    12811282        $$->setValue($8);
    1282     }
    1283   ;
     1283        $$->setAttributeValueMatchingIsCaseInsensitive($10);
     1284    }
     1285  ;
     1286
     1287attrib_flags:
     1288#if ENABLE_CSS_SELECTORS_LEVEL4
     1289    IDENT maybe_space {
     1290        if (UNLIKELY($1.length() != 1 || !isASCIIAlphaCaselessEqual($1[0], 'i')))
     1291            YYERROR;
     1292        $$ = true;
     1293    }
     1294    |
     1295#endif
     1296    /* empty */ {
     1297        $$ = false;
     1298    }
    12841299
    12851300match:
  • trunk/Source/WebCore/css/CSSParserValues.h

    r178675 r179819  
    224224    void setAttribute(const QualifiedName& value, bool isCaseInsensitive) { m_selector->setAttribute(value, isCaseInsensitive); }
    225225    void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
     226    void setAttributeValueMatchingIsCaseInsensitive(bool isCaseInsensitive) { m_selector->setAttributeValueMatchingIsCaseInsensitive(isCaseInsensitive); }
    226227    void setMatch(CSSSelector::Match value) { m_selector->setMatch(value); }
    227228    void setRelation(CSSSelector::Relation value) { m_selector->setRelation(value); }
    228229    void setForPage() { m_selector->setForPage(); }
    229 
    230230
    231231    void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r179323 r179819  
    6262    , m_tagIsForNamespaceRule(tagIsForNamespaceRule)
    6363    , m_descendantDoubleChildSyntax(false)
     64    , m_caseInsensitiveAttributeValueMatching(false)
    6465{
    6566    const AtomicString& tagLocalName = tagQName.localName();
     
    684685            if (cs->match() != CSSSelector::Set) {
    685686                serializeString(cs->value(), str);
    686                 str.append(']');
     687                if (cs->attributeValueMatchingIsCaseInsensitive())
     688                    str.appendLiteral(" i]");
     689                else
     690                    str.append(']');
    687691            }
    688692        } else if (cs->match() == CSSSelector::PagePseudoClass) {
  • trunk/Source/WebCore/css/CSSSelector.h

    r179132 r179819  
    235235        const AtomicString& attributeCanonicalLocalName() const;
    236236        const AtomicString& argument() const { return m_hasRareData ? m_data.m_rareData->m_argument : nullAtom; }
     237        bool attributeValueMatchingIsCaseInsensitive() const;
    237238#if ENABLE(CSS_SELECTORS_LEVEL4)
    238239        const Vector<LanguageArgument>* langArgumentList() const { return m_hasRareData ? m_data.m_rareData->m_langArgumentList.get() : nullptr; }
     
    243244        void setAttribute(const QualifiedName&, bool isCaseInsensitive);
    244245        void setArgument(const AtomicString&);
     246        void setAttributeValueMatchingIsCaseInsensitive(bool);
    245247#if ENABLE(CSS_SELECTORS_LEVEL4)
    246248        void setLangArgumentList(std::unique_ptr<Vector<LanguageArgument>>);
     
    332334        unsigned m_tagIsForNamespaceRule : 1;
    333335        unsigned m_descendantDoubleChildSyntax : 1;
     336        unsigned m_caseInsensitiveAttributeValueMatching : 1;
    334337
    335338        unsigned simpleSelectorSpecificityForPage() const;
     
    473476    , m_tagIsForNamespaceRule(false)
    474477    , m_descendantDoubleChildSyntax(false)
     478    , m_caseInsensitiveAttributeValueMatching(false)
    475479{
    476480}
     
    488492    , m_tagIsForNamespaceRule(o.m_tagIsForNamespaceRule)
    489493    , m_descendantDoubleChildSyntax(o.m_descendantDoubleChildSyntax)
     494    , m_caseInsensitiveAttributeValueMatching(o.m_caseInsensitiveAttributeValueMatching)
    490495{
    491496    if (o.m_hasRareData) {
     
    539544}
    540545
     546inline void CSSSelector::setAttributeValueMatchingIsCaseInsensitive(bool isCaseInsensitive)
     547{
     548    ASSERT(isAttributeSelector() && match() != CSSSelector::Set);
     549    m_caseInsensitiveAttributeValueMatching = isCaseInsensitive;
     550}
     551
     552inline bool CSSSelector::attributeValueMatchingIsCaseInsensitive() const
     553{
     554    return m_caseInsensitiveAttributeValueMatching;
     555}
    541556
    542557} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.