Changeset 58299 in webkit


Ignore:
Timestamp:
Apr 27, 2010 2:35:16 AM (14 years ago)
Author:
yuzo@google.com
Message:

2010-04-27 Yuzo Fujishima <yuzo@google.com>

Reviewed by David Hyatt.

Enhance CSS parser for Paged Media (Iteration 1)

In this change, the grammar is extended and skeletal methods for creating page rules and margin at-rules are defined.
The contents of the methods should be implemented by other changes.

https://bugs.webkit.org/show_bug.cgi?id=35329

  • fast/css/parsing-page-rule-expected.txt: Copied from LayoutTests/editing/selection/doubleclick-whitespace-img-crash-expected.txt.
  • fast/css/parsing-page-rule.html: Added.

2010-04-27 Yuzo Fujishima <yuzo@google.com>

Reviewed by David Hyatt.

Enhance CSS parser for Paged Media (Iteration 1)

In this change, the grammar is extended and skeletal methods for creating page rules and margin at-rules are defined.
The contents of the methods should be implemented by other changes.

https://bugs.webkit.org/show_bug.cgi?id=35329

Test: fast/css/parsing-page-rule.html

  • css/CSSGrammar.y:
  • css/CSSParser.cpp: (WebCore::CSSParser::CSSParser): (WebCore::CSSParser::clearProperties): (WebCore::CSSParser::lex): (WebCore::CSSParser::text): (WebCore::CSSParser::createPageRule): (WebCore::CSSParser::createMarginAtRule): (WebCore::CSSParser::startDeclarationsForMarginBox): (WebCore::CSSParser::endDeclarationsForMarginBox):
  • css/CSSParser.h:
  • css/CSSSelector.cpp: (WebCore::CSSSelector::extractPseudoType):
  • css/CSSSelector.h: (WebCore::CSSSelector::):
  • css/tokenizer.flex:
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r58277 r58299  
     12010-04-27  Yuzo Fujishima  <yuzo@google.com>
     2
     3        Reviewed by David Hyatt.
     4
     5        Enhance CSS parser for Paged Media (Iteration 1)
     6
     7        In this change, the grammar is extended and skeletal methods for creating page rules and margin at-rules are defined.
     8        The contents of the methods should be implemented by other changes.
     9
     10        https://bugs.webkit.org/show_bug.cgi?id=35329
     11
     12        * fast/css/parsing-page-rule-expected.txt: Copied from LayoutTests/editing/selection/doubleclick-whitespace-img-crash-expected.txt.
     13        * fast/css/parsing-page-rule.html: Added.
     14
    1152010-04-26  Yuzo Fujishima  <yuzo@google.com>
    216
  • trunk/WebCore/ChangeLog

    r58298 r58299  
     12010-04-27  Yuzo Fujishima  <yuzo@google.com>
     2
     3        Reviewed by David Hyatt.
     4
     5        Enhance CSS parser for Paged Media (Iteration 1)
     6
     7        In this change, the grammar is extended and skeletal methods for creating page rules and margin at-rules are defined.
     8        The contents of the methods should be implemented by other changes.
     9
     10        https://bugs.webkit.org/show_bug.cgi?id=35329
     11
     12        Test: fast/css/parsing-page-rule.html
     13
     14        * css/CSSGrammar.y:
     15        * css/CSSParser.cpp:
     16        (WebCore::CSSParser::CSSParser):
     17        (WebCore::CSSParser::clearProperties):
     18        (WebCore::CSSParser::lex):
     19        (WebCore::CSSParser::text):
     20        (WebCore::CSSParser::createPageRule):
     21        (WebCore::CSSParser::createMarginAtRule):
     22        (WebCore::CSSParser::startDeclarationsForMarginBox):
     23        (WebCore::CSSParser::endDeclarationsForMarginBox):
     24        * css/CSSParser.h:
     25        * css/CSSSelector.cpp:
     26        (WebCore::CSSSelector::extractPseudoType):
     27        * css/CSSSelector.h:
     28        (WebCore::CSSSelector::):
     29        * css/tokenizer.flex:
     30
    1312010-04-27  Adam Barth  <abarth@webkit.org>
    232
  • trunk/WebCore/css/CSSGrammar.y

    r57299 r58299  
    7171    CSSSelector* selector;
    7272    Vector<CSSSelector*>* selectorList;
     73    CSSSelector::MarginBoxType marginBox;
    7374    CSSSelector::Relation relation;
    7475    MediaList* mediaList;
     
    9899%}
    99100
    100 %expect 54
     101%expect 55
    101102
    102103%nonassoc LOWEST_PREC
     
    143144%token VARIABLES_FOR
    144145%token WEBKIT_VARIABLES_DECLS_SYM
     146%token <marginBox> TOPLEFTCORNER_SYM
     147%token <marginBox> TOPLEFT_SYM
     148%token <marginBox> TOPCENTER_SYM
     149%token <marginBox> TOPRIGHT_SYM
     150%token <marginBox> TOPRIGHTCORNER_SYM
     151%token <marginBox> BOTTOMLEFTCORNER_SYM
     152%token <marginBox> BOTTOMLEFT_SYM
     153%token <marginBox> BOTTOMCENTER_SYM
     154%token <marginBox> BOTTOMRIGHT_SYM
     155%token <marginBox> BOTTOMRIGHTCORNER_SYM
     156%token <marginBox> LEFTTOP_SYM
     157%token <marginBox> LEFTMIDDLE_SYM
     158%token <marginBox> LEFTBOTTOM_SYM
     159%token <marginBox> RIGHTTOP_SYM
     160%token <marginBox> RIGHTMIDDLE_SYM
     161%token <marginBox> RIGHTBOTTOM_SYM
     162
    145163%token ATKEYWORD
    146164
     
    189207%type <rule> namespace
    190208%type <rule> page
     209%type <rule> margin_box
    191210%type <rule> font_face
    192211%type <rule> keyframes
     
    210229%type <string> medium
    211230%type <string> hexcolor
     231%type <marginBox> margin_sym
    212232
    213233%type <string> media_feature
     
    238258%type <selector> attrib
    239259%type <selector> pseudo
     260%type <selector> page_selector
    240261
    241262%type <boolean> declaration_list
     
    730751    ;
    731752
    732 /*
    733753page:
    734     PAGE_SYM maybe_space IDENT? pseudo_page? maybe_space
    735     '{' maybe_space declaration [ ';' maybe_space declaration ]* '}' maybe_space
    736   ;
    737 
    738 pseudo_page
    739   : ':' IDENT
    740   ;
    741 */
    742 
    743 page:
    744     PAGE_SYM error invalid_block {
     754    PAGE_SYM maybe_space page_selector maybe_space
     755    '{' maybe_space declarations_and_margins closing_brace {
     756        CSSParser* p = static_cast<CSSParser*>(parser);
     757        $$ = p->createPageRule(p->sinkFloatingSelector($3));
     758    }
     759    | PAGE_SYM error invalid_block {
    745760      $$ = 0;
    746761    }
    747   | PAGE_SYM error ';' {
     762    | PAGE_SYM error ';' {
    748763      $$ = 0;
     764    }
     765    ;
     766
     767page_selector:
     768    IDENT {
     769        CSSParser* p = static_cast<CSSParser*>(parser);
     770        $$ = p->createFloatingSelector();
     771        $$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace);
     772    }
     773    | IDENT pseudo {
     774        CSSParser* p = static_cast<CSSParser*>(parser);
     775        $$ = $2;
     776        if ($$)
     777            $$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace);
     778    }
     779    | pseudo {
     780        $$ = $1;
     781    }
     782    | /* empty */ {
     783        CSSParser* p = static_cast<CSSParser*>(parser);
     784        $$ = p->createFloatingSelector();
     785    }
     786    ;
     787
     788declarations_and_margins:
     789    declaration_list
     790    | declarations_and_margins margin_box maybe_space declaration_list
     791    ;
     792
     793margin_box:
     794    margin_sym {
     795        static_cast<CSSParser*>(parser)->startDeclarationsForMarginBox();
     796    } maybe_space '{' maybe_space declaration_list closing_brace {
     797        $$ = static_cast<CSSParser*>(parser)->createMarginAtRule($1);
     798    }
     799    ;
     800
     801margin_sym :
     802    TOPLEFTCORNER_SYM {
     803        $$ = CSSSelector::TopLeftCornerMarginBox;
     804    }
     805    | TOPLEFT_SYM {
     806        $$ = CSSSelector::TopLeftMarginBox;
     807    }
     808    | TOPCENTER_SYM {
     809        $$ = CSSSelector::TopCenterMarginBox;
     810    }
     811    | TOPRIGHT_SYM {
     812        $$ = CSSSelector::TopRightMarginBox;
     813    }
     814    | TOPRIGHTCORNER_SYM {
     815        $$ = CSSSelector::TopRightCornerMarginBox;
     816    }
     817    | BOTTOMLEFTCORNER_SYM {
     818        $$ = CSSSelector::BottomLeftCornerMarginBox;
     819    }
     820    | BOTTOMLEFT_SYM {
     821        $$ = CSSSelector::BottomLeftMarginBox;
     822    }
     823    | BOTTOMCENTER_SYM {
     824        $$ = CSSSelector::BottomCenterMarginBox;
     825    }
     826    | BOTTOMRIGHT_SYM {
     827        $$ = CSSSelector::BottomRightMarginBox;
     828    }
     829    | BOTTOMRIGHTCORNER_SYM {
     830        $$ = CSSSelector::BottomRightCornerMarginBox;
     831    }
     832    | LEFTTOP_SYM {
     833        $$ = CSSSelector::LeftTopMarginBox;
     834    }
     835    | LEFTMIDDLE_SYM {
     836        $$ = CSSSelector::LeftMiddleMarginBox;
     837    }
     838    | LEFTBOTTOM_SYM {
     839        $$ = CSSSelector::LeftBottomMarginBox;
     840    }
     841    | RIGHTTOP_SYM {
     842        $$ = CSSSelector::RightTopMarginBox;
     843    }
     844    | RIGHTMIDDLE_SYM {
     845        $$ = CSSSelector::RightMiddleMarginBox;
     846    }
     847    | RIGHTBOTTOM_SYM {
     848        $$ = CSSSelector::RightBottomMarginBox;
    749849    }
    750850    ;
  • trunk/WebCore/css/CSSParser.cpp

    r57105 r58299  
    7070#include "WebKitCSSKeyframesRule.h"
    7171#include "WebKitCSSTransformValue.h"
     72#include <limits.h>
    7273#include <wtf/dtoa.h>
    7374
     
    9192
    9293namespace WebCore {
     94
     95static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
    9396
    9497static bool equal(const CSSParserString& a, const char* b)
     
    136139    , m_numParsedProperties(0)
    137140    , m_maxParsedProperties(32)
     141    , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
    138142    , m_inParseShorthand(0)
    139143    , m_currentShorthand(0)
     
    397401        delete m_parsedProperties[i];
    398402    m_numParsedProperties = 0;
     403    m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
    399404    m_hasFontFaceOnlyValues = false;
    400405}
     
    51945199#endif
    51955200
     5201CSSRule* CSSParser::createPageRule(CSSSelector* /* pageSelector */)
     5202{
     5203    // FIXME: Create page rule here, using:
     5204    //        - pageSelector->pseudoType(): the page pseudo-class, i.e., :left, :right, or :first
     5205    //        - pageSelector->m_tag:  the page name
     5206    //        - m_parsedProperties: the page properties
     5207
     5208    clearProperties();
     5209    return 0; // until this method is implemented.
     5210}
     5211
     5212CSSRule* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
     5213{
     5214    // FIXME: Implement margin at-rule here, using:
     5215    //        - marginBox: margin box
     5216    //        - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMarginBox, m_numParsedProperties) are for this at-rule.
     5217
     5218    endDeclarationsForMarginBox();
     5219    return 0; // until this method is implemented.
     5220}
     5221
     5222void CSSParser::startDeclarationsForMarginBox()
     5223{
     5224    m_numParsedPropertiesBeforeMarginBox = m_numParsedProperties;
     5225}
     5226
     5227void CSSParser::endDeclarationsForMarginBox()
     5228{
     5229    ASSERT(m_numParsedPropertiesBeforeMarginBox != INVALID_NUM_PARSED_PROPERTIES);
     5230    rollbackLastProperties(m_numParsedProperties - m_numParsedPropertiesBeforeMarginBox);
     5231    m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES;
     5232}
     5233
    51965234void CSSParser::clearVariables()
    51975235{
  • trunk/WebCore/css/CSSParser.h

    r57105 r58299  
    180180        CSSRule* createFontFaceRule();
    181181        CSSRule* createVariablesRule(MediaList*, bool variablesKeyword);
     182        CSSRule* createPageRule(CSSSelector* pageSelector);
     183        CSSRule* createMarginAtRule(CSSSelector::MarginBoxType marginBox);
     184        void startDeclarationsForMarginBox();
     185        void endDeclarationsForMarginBox();
    182186
    183187        MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
     
    213217        unsigned m_numParsedProperties;
    214218        unsigned m_maxParsedProperties;
     219        unsigned m_numParsedPropertiesBeforeMarginBox;
    215220
    216221        int m_inParseShorthand;
  • trunk/WebCore/css/CSSSelector.cpp

    r58228 r58299  
    204204    case PseudoSingleButton:
    205205    case PseudoNoButton:
     206    case PseudoFirstPage:
     207    case PseudoLeftPage:
     208    case PseudoRightPage:
    206209        return NOPSEUDO;
    207210    case PseudoNotParsed:
     
    306309    DEFINE_STATIC_LOCAL(AtomicString, noButton, ("no-button"));
    307310    DEFINE_STATIC_LOCAL(AtomicString, cornerPresent, ("corner-present"));
     311    // Paged Media pseudo-classes
     312    DEFINE_STATIC_LOCAL(AtomicString, firstPage, ("first"));
     313    DEFINE_STATIC_LOCAL(AtomicString, leftPage, ("left"));
     314    DEFINE_STATIC_LOCAL(AtomicString, rightPage, ("right"));
    308315
    309316    static HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = 0;
     
    400407        nameToPseudoType->set(target.impl(), CSSSelector::PseudoTarget);
    401408        nameToPseudoType->set(visited.impl(), CSSSelector::PseudoVisited);
     409        nameToPseudoType->set(firstPage.impl(), CSSSelector::PseudoFirstPage);
     410        nameToPseudoType->set(leftPage.impl(), CSSSelector::PseudoLeftPage);
     411        nameToPseudoType->set(rightPage.impl(), CSSSelector::PseudoRightPage);
    402412    }
    403413    return nameToPseudoType;
     
    516526    case PseudoNoButton:
    517527    case PseudoNotParsed:
     528    case PseudoFirstPage:
     529    case PseudoLeftPage:
     530    case PseudoRightPage:
    518531        break;
    519532    }
  • trunk/WebCore/css/CSSSelector.h

    r58228 r58299  
    189189            PseudoOuterSpinButton,
    190190            PseudoProgressBarValue,
     191            PseudoLeftPage,
     192            PseudoRightPage,
     193            PseudoFirstPage,
     194        };
     195
     196        enum MarginBoxType {
     197            TopLeftCornerMarginBox,
     198            TopLeftMarginBox,
     199            TopCenterMarginBox,
     200            TopRightMarginBox,
     201            TopRightCornerMarginBox,
     202            BottomLeftCornerMarginBox,
     203            BottomLeftMarginBox,
     204            BottomCenterMarginBox,
     205            BottomRightMarginBox,
     206            BottomRightCornerMarginBox,
     207            LeftTopMarginBox,
     208            LeftMiddleMarginBox,
     209            LeftBottomMarginBox,
     210            RightTopMarginBox,
     211            RightMiddleMarginBox,
     212            RightBottomMarginBox,
    191213        };
    192214
  • trunk/WebCore/css/tokenizer.flex

    r56414 r58299  
    5454"@import"               {BEGIN(mediaquery); yyTok = IMPORT_SYM; return yyTok;}
    5555"@page"                 {yyTok = PAGE_SYM; return yyTok;}
     56"@top-left-corner"      {yyTok = TOPLEFTCORNER_SYM; return yyTok;}
     57"@top-left"             {yyTok = TOPLEFT_SYM; return yyTok;}
     58"@top-center"           {yyTok = TOPCENTER_SYM; return yyTok;}
     59"@top-right"            {yyTok = TOPRIGHT_SYM; return yyTok;}
     60"@top-right-corner"     {yyTok = TOPRIGHTCORNER_SYM; return yyTok;}
     61"@bottom-left-corner"   {yyTok = BOTTOMLEFTCORNER_SYM; return yyTok;}
     62"@bottom-left"          {yyTok = BOTTOMLEFT_SYM; return yyTok;}
     63"@bottom-center"        {yyTok = BOTTOMCENTER_SYM; return yyTok;}
     64"@bottom-right"         {yyTok = BOTTOMRIGHT_SYM; return yyTok;}
     65"@bottom-right-corner"  {yyTok = BOTTOMRIGHTCORNER_SYM; return yyTok;}
     66"@left-top"             {yyTok = LEFTTOP_SYM; return yyTok;}
     67"@left-middle"          {yyTok = LEFTMIDDLE_SYM; return yyTok;}
     68"@left-bottom"          {yyTok = LEFTBOTTOM_SYM; return yyTok;}
     69"@right-top"            {yyTok = RIGHTTOP_SYM; return yyTok;}
     70"@right-middle"         {yyTok = RIGHTMIDDLE_SYM; return yyTok;}
     71"@right-bottom"         {yyTok = RIGHTBOTTOM_SYM; return yyTok;}
    5672"@media"                {BEGIN(mediaquery); yyTok = MEDIA_SYM; return yyTok;}
    5773"@font-face"            {yyTok = FONT_FACE_SYM; return yyTok;}
Note: See TracChangeset for help on using the changeset viewer.