Changeset 51608 in webkit


Ignore:
Timestamp:
Dec 2, 2009 11:27:17 AM (14 years ago)
Author:
hyatt@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=32072, clean up invalid @-rule error handling so that we
pass more CSS test suite stuff. Make the grammar stop enforcing the ordering of @namespace vs.
@variables vs. @import. Just let the parser handle that instead. This simplifies the grammar and
makes error handling deal with more cases correctly.

Reviewed by Darin Adler.

Added fast/css/namespaces/namespaces-invalid-at-rules.xml

  • css/CSSGrammar.y:
  • css/CSSParser.cpp:

(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::parseRule):
(WebCore::CSSParser::createCharsetRule):
(WebCore::CSSParser::createImportRule):
(WebCore::CSSParser::createMediaRule):
(WebCore::CSSParser::createKeyframesRule):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::createFontFaceRule):
(WebCore::CSSParser::addNamespace):
(WebCore::CSSParser::createVariablesRule):

  • css/CSSParser.h:
Location:
trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/platform/mac/fast/css/variables/misplaced-import-test-expected.checksum

    r38008 r51608  
    1 298a5c439d36bd284adea72df4b2cbd5
     13b521f0661cb5be8ef5513b2de77f62e
  • trunk/LayoutTests/platform/mac/fast/css/variables/misplaced-import-test-expected.txt

    r36855 r51608  
    33layer at (0,0) size 800x34
    44  RenderBlock {HTML} at (0,0) size 800x34
    5     RenderBody {BODY} at (8,8) size 784x18
     5    RenderBody {BODY} at (8,8) size 784x18 [bgcolor=#FF0000]
    66      RenderText {#text} at (0,0) size 511x18
    77        text run at (0,0) width 316: "This text should be green on a white background. "
  • trunk/WebCore/ChangeLog

    r51605 r51608  
     12009-12-02  Dave Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=32072, clean up invalid @-rule error handling so that we
     6        pass more CSS test suite stuff.  Make the grammar stop enforcing the ordering of @namespace vs.
     7        @variables vs. @import.  Just let the parser handle that instead.  This simplifies the grammar and
     8        makes error handling deal with more cases correctly.
     9
     10        Added fast/css/namespaces/namespaces-invalid-at-rules.xml
     11
     12        * css/CSSGrammar.y:
     13        * css/CSSParser.cpp:
     14        (WebCore::CSSParser::CSSParser):
     15        (WebCore::CSSParser::parseRule):
     16        (WebCore::CSSParser::createCharsetRule):
     17        (WebCore::CSSParser::createImportRule):
     18        (WebCore::CSSParser::createMediaRule):
     19        (WebCore::CSSParser::createKeyframesRule):
     20        (WebCore::CSSParser::createStyleRule):
     21        (WebCore::CSSParser::createFontFaceRule):
     22        (WebCore::CSSParser::addNamespace):
     23        (WebCore::CSSParser::createVariablesRule):
     24        * css/CSSParser.h:
     25
    1262009-12-02  Yusuke Sato  <yusukes@chromium.org>
    227
  • trunk/WebCore/css/CSSGrammar.y

    r51549 r51608  
    9898%}
    9999
    100 %expect 51
     100%expect 48
    101101
    102102%nonassoc LOWEST_PREC
     
    185185%type <rule> charset
    186186%type <rule> ruleset
    187 %type <rule> valid_rule_or_import
    188187%type <rule> media
    189188%type <rule> import
     189%type <rule> namespace
    190190%type <rule> page
    191191%type <rule> font_face
     
    194194%type <rule> save_block
    195195%type <rule> invalid_at
    196 %type <rule> invalid_at_list
    197 %type <rule> invalid_import
    198 %type <rule> invalid_media
    199196%type <rule> rule
    200197%type <rule> valid_rule
     
    269266
    270267stylesheet:
    271     maybe_space maybe_charset maybe_sgml import_list variables_list namespace_list rule_list
     268    maybe_space maybe_charset maybe_sgml rule_list
    272269  | webkit_rule maybe_space
    273270  | webkit_decls maybe_space
     
    279276  ;
    280277
    281 valid_rule_or_import:
    282     valid_rule
    283   | import
    284   ;
    285 
    286278webkit_rule:
    287     WEBKIT_RULE_SYM '{' maybe_space valid_rule_or_import maybe_space '}' {
     279    WEBKIT_RULE_SYM '{' maybe_space valid_rule maybe_space '}' {
    288280        static_cast<CSSParser*>(parser)->m_rule = $4;
    289281    }
     
    374366;
    375367
    376 import_list:
    377  /* empty */
    378  | import_list import maybe_sgml {
    379      CSSParser* p = static_cast<CSSParser*>(parser);
    380      if ($2 && p->m_styleSheet)
    381          p->m_styleSheet->append($2);
    382  }
    383  | invalid_at_list {
    384  }
    385  ;
    386 
    387 variables_list:
    388 /* empty */
    389 | variables_list variables_rule maybe_sgml {
    390     CSSParser* p = static_cast<CSSParser*>(parser);
    391      if ($2 && p->m_styleSheet)
    392          p->m_styleSheet->append($2);
    393 }
    394 ;
    395 
    396 namespace_list:
    397 /* empty */
    398 | namespace_list namespace maybe_sgml
    399 ;
    400 
    401368rule_list:
    402369   /* empty */
     
    414381  | font_face
    415382  | keyframes
     383  | namespace
     384  | import
     385  | variables_rule
    416386  ;
    417387
     
    420390  | invalid_rule
    421391  | invalid_at
    422   | invalid_import
    423392  ;
    424393
     
    446415  | invalid_rule
    447416  | invalid_at
    448   | invalid_import
    449   | invalid_media
     417  | namespace
     418  | import
     419  | variables_rule
     420  | media
    450421  ;
    451422
     
    571542namespace:
    572543NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' {
    573     CSSParser* p = static_cast<CSSParser*>(parser);
    574     if (p->m_styleSheet)
    575         p->m_styleSheet->addNamespace(p, $3, $4);
     544    static_cast<CSSParser*>(parser)->addNamespace($3, $4);
     545    $$ = 0;
    576546}
    577 | NAMESPACE_SYM error invalid_block
    578 | NAMESPACE_SYM error ';'
     547| NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space invalid_block {
     548    $$ = 0;
     549}
     550| NAMESPACE_SYM error invalid_block {
     551    $$ = 0;
     552}
     553| NAMESPACE_SYM error ';' {
     554    $$ = 0;
     555}
    579556;
    580557
     
    14821459    ;
    14831460
    1484 invalid_at_list:
    1485     invalid_at maybe_sgml
    1486   | invalid_at_list invalid_at maybe_sgml
    1487   ;
    1488 
    1489 invalid_import:
    1490     import {
    1491         $$ = 0;
    1492     }
    1493     ;
    1494 
    1495 invalid_media:
    1496     media {
    1497         $$ = 0;
    1498     }
    1499     ;
    1500 
    15011461invalid_rule:
    15021462    error invalid_block {
  • trunk/WebCore/css/CSSParser.cpp

    r51600 r51608  
    143143    , m_data(0)
    144144    , yy_start(1)
     145    , m_allowImportRules(true)
     146    , m_allowVariablesRules(true)
     147    , m_allowNamespaceDeclarations(true)
    145148    , m_floatingMediaQuery(0)
    146149    , m_floatingMediaQueryExp(0)
     
    230233{
    231234    m_styleSheet = sheet;
     235    m_allowNamespaceDeclarations = false;
    232236    setupParser("@-webkit-rule{", string, "} ");
    233237    cssyyparse(this);
     
    49774981CSSRule* CSSParser::createImportRule(const CSSParserString& url, MediaList* media)
    49784982{
    4979     if (!media || !m_styleSheet)
     4983    if (!media || !m_styleSheet || !m_allowImportRules)
    49804984        return 0;
    49814985    RefPtr<CSSImportRule> rule = CSSImportRule::create(m_styleSheet, url, media);
     
    49894993    if (!media || !rules || !m_styleSheet)
    49904994        return 0;
     4995    m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false;
    49914996    RefPtr<CSSMediaRule> rule = CSSMediaRule::create(m_styleSheet, media, rules);
    49924997    CSSMediaRule* result = rule.get();
     
    50065011WebKitCSSKeyframesRule* CSSParser::createKeyframesRule()
    50075012{
     5013    m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false;
    50085014    RefPtr<WebKitCSSKeyframesRule> rule = WebKitCSSKeyframesRule::create(m_styleSheet);
    50095015    WebKitCSSKeyframesRule* rulePtr = rule.get();
     
    50145020CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors)
    50155021{
     5022    m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false;
    50165023    CSSStyleRule* result = 0;
    50175024    if (selectors) {
     
    50305037CSSRule* CSSParser::createFontFaceRule()
    50315038{
     5039    m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false;
    50325040    RefPtr<CSSFontFaceRule> rule = CSSFontFaceRule::create(m_styleSheet);
    50335041    for (unsigned i = 0; i < m_numParsedProperties; ++i) {
     
    50475055}
    50485056
     5057void CSSParser::addNamespace(const AtomicString& prefix, const AtomicString& uri)
     5058{
     5059    if (!m_styleSheet || !m_allowNamespaceDeclarations)
     5060        return;
     5061    m_allowImportRules = false;
     5062    m_allowVariablesRules = false;
     5063    m_styleSheet->addNamespace(this, prefix, uri);
     5064}
     5065
    50495066#if !ENABLE(CSS_VARIABLES)
    50505067
     
    50685085CSSRule* CSSParser::createVariablesRule(MediaList* mediaList, bool variablesKeyword)
    50695086{
     5087    if (!m_allowVariablesRules)
     5088        return 0;
     5089    m_allowImportRules = false;
    50705090    RefPtr<CSSVariablesRule> rule = CSSVariablesRule::create(m_styleSheet, mediaList, variablesKeyword);
    50715091    rule->setDeclaration(CSSVariablesDeclaration::create(rule.get(), m_variableNames, m_variableValues));
  • trunk/WebCore/css/CSSParser.h

    r51600 r51608  
    188188        MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
    189189
     190        void addNamespace(const AtomicString& prefix, const AtomicString& uri);
     191
    190192        bool addVariable(const CSSParserString&, CSSParserValueList*);
    191193        bool addVariableDeclarationBlock(const CSSParserString&);
     
    194196       
    195197        Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; }
    196        
     198
    197199        bool m_strict;
    198200        bool m_important;
     
    249251        int yyTok;
    250252        int yy_start;
     253
     254        bool m_allowImportRules;
     255        bool m_allowVariablesRules;
     256        bool m_allowNamespaceDeclarations;
    251257
    252258        Vector<RefPtr<StyleBase> > m_parsedStyleObjects;
Note: See TracChangeset for help on using the changeset viewer.