diff options
author | yuzo@google.com <yuzo@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2010-04-27 09:35:16 +0000 |
---|---|---|
committer | yuzo@google.com <yuzo@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2010-04-27 09:35:16 +0000 |
commit | 36142fcbbed73e202b0fde1a9dc25d02ff6f32f0 (patch) | |
tree | b32380be92d4a508e7b1f5ef224fd74e5b629783 | |
parent | 7d68b04659a4d8fc7162e2f3f907a76f932f9c8c (diff) | |
download | chromium_src-36142fcbbed73e202b0fde1a9dc25d02ff6f32f0.zip chromium_src-36142fcbbed73e202b0fde1a9dc25d02ff6f32f0.tar.gz chromium_src-36142fcbbed73e202b0fde1a9dc25d02ff6f32f0.tar.bz2 |
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:
git-svn-id: svn://svn.chromium.org/blink/trunk@58299 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r-- | third_party/WebKit/LayoutTests/ChangeLog | 14 | ||||
-rw-r--r-- | third_party/WebKit/LayoutTests/fast/css/parsing-page-rule-expected.txt | 1 | ||||
-rw-r--r-- | third_party/WebKit/LayoutTests/fast/css/parsing-page-rule.html | 65 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/ChangeLog | 30 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/CSSGrammar.y | 128 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/CSSParser.cpp | 38 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/CSSParser.h | 5 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/CSSSelector.cpp | 13 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/CSSSelector.h | 22 | ||||
-rw-r--r-- | third_party/WebKit/WebCore/css/tokenizer.flex | 16 |
10 files changed, 318 insertions, 14 deletions
diff --git a/third_party/WebKit/LayoutTests/ChangeLog b/third_party/WebKit/LayoutTests/ChangeLog index df5b35d..3eaf1ea 100644 --- a/third_party/WebKit/LayoutTests/ChangeLog +++ b/third_party/WebKit/LayoutTests/ChangeLog @@ -1,3 +1,17 @@ +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-26 Yuzo Fujishima <yuzo@google.com> Unreviewed, Chromium test expectation change. diff --git a/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule-expected.txt b/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule-expected.txt new file mode 100644 index 0000000..7ef22e9 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule-expected.txt @@ -0,0 +1 @@ +PASS diff --git a/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule.html b/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule.html new file mode 100644 index 0000000..6484f6d --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/css/parsing-page-rule.html @@ -0,0 +1,65 @@ +<!doctype html> +<html> +<head> + <script type="text/javascript"> + if (window.layoutTestController) + layoutTestController.dumpAsText(); + </script> + <style> + .to_be_shown { + display:none; + color:green; + } + .to_be_hidden { + display:block; + color:red; + } + </style> + <style> + /* page rule must not interfere with non-page rules */ + #test1 { + display:none; + } + @page { + #test1 { + display:block; + } + @top-center { + content:"Test"; + display:block; + } + #test2 { + display:block; + } + } + #test2 { + display:none; + } + </style> + <style> + /* Malformed page rule must not interfere with non-page rules as far as braces are paired properly */ + @page { + p:before { + content:"malformed + } + @top-left + } + #test3 { + display:none; + } + </style> + <style> + /* Successfully parsed */ + #last { + display:block; + } + </style> +</head> +<body> + <div class="to_be_hidden" id="test1">FAIL: Test 1</div> + <div class="to_be_hidden" id="test2">FAIL: Test 2</div> + <div class="to_be_hidden" id="test3">FAIL: Test 3</div> + <div class="to_be_shown" id="last">PASS</div> +</body> +</html> + diff --git a/third_party/WebKit/WebCore/ChangeLog b/third_party/WebKit/WebCore/ChangeLog index ce845cb..826a77e 100644 --- a/third_party/WebKit/WebCore/ChangeLog +++ b/third_party/WebKit/WebCore/ChangeLog @@ -1,3 +1,33 @@ +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: + 2010-04-27 Adam Barth <abarth@webkit.org> Reviewed by Eric Seidel. diff --git a/third_party/WebKit/WebCore/css/CSSGrammar.y b/third_party/WebKit/WebCore/css/CSSGrammar.y index ec0c141..78b431a 100644 --- a/third_party/WebKit/WebCore/css/CSSGrammar.y +++ b/third_party/WebKit/WebCore/css/CSSGrammar.y @@ -70,6 +70,7 @@ using namespace HTMLNames; CSSRuleList* ruleList; CSSSelector* selector; Vector<CSSSelector*>* selectorList; + CSSSelector::MarginBoxType marginBox; CSSSelector::Relation relation; MediaList* mediaList; MediaQuery* mediaQuery; @@ -97,7 +98,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser) %} -%expect 54 +%expect 55 %nonassoc LOWEST_PREC @@ -142,6 +143,23 @@ static int cssyylex(YYSTYPE* yylval, void* parser) %token WEBKIT_DEFINE_SYM %token VARIABLES_FOR %token WEBKIT_VARIABLES_DECLS_SYM +%token <marginBox> TOPLEFTCORNER_SYM +%token <marginBox> TOPLEFT_SYM +%token <marginBox> TOPCENTER_SYM +%token <marginBox> TOPRIGHT_SYM +%token <marginBox> TOPRIGHTCORNER_SYM +%token <marginBox> BOTTOMLEFTCORNER_SYM +%token <marginBox> BOTTOMLEFT_SYM +%token <marginBox> BOTTOMCENTER_SYM +%token <marginBox> BOTTOMRIGHT_SYM +%token <marginBox> BOTTOMRIGHTCORNER_SYM +%token <marginBox> LEFTTOP_SYM +%token <marginBox> LEFTMIDDLE_SYM +%token <marginBox> LEFTBOTTOM_SYM +%token <marginBox> RIGHTTOP_SYM +%token <marginBox> RIGHTMIDDLE_SYM +%token <marginBox> RIGHTBOTTOM_SYM + %token ATKEYWORD %token IMPORTANT_SYM @@ -188,6 +206,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser) %type <rule> import %type <rule> namespace %type <rule> page +%type <rule> margin_box %type <rule> font_face %type <rule> keyframes %type <rule> invalid_rule @@ -209,6 +228,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser) %type <string> ident_or_string %type <string> medium %type <string> hexcolor +%type <marginBox> margin_sym %type <string> media_feature %type <mediaList> media_list @@ -237,6 +257,7 @@ static int cssyylex(YYSTYPE* yylval, void* parser) %type <selector> class %type <selector> attrib %type <selector> pseudo +%type <selector> page_selector %type <boolean> declaration_list %type <boolean> decl_list @@ -729,26 +750,105 @@ key: } ; -/* page: - PAGE_SYM maybe_space IDENT? pseudo_page? maybe_space - '{' maybe_space declaration [ ';' maybe_space declaration ]* '}' maybe_space - ; - -pseudo_page - : ':' IDENT - ; -*/ - -page: - PAGE_SYM error invalid_block { + PAGE_SYM maybe_space page_selector maybe_space + '{' maybe_space declarations_and_margins closing_brace { + CSSParser* p = static_cast<CSSParser*>(parser); + $$ = p->createPageRule(p->sinkFloatingSelector($3)); + } + | PAGE_SYM error invalid_block { $$ = 0; } - | PAGE_SYM error ';' { + | PAGE_SYM error ';' { $$ = 0; } ; +page_selector: + IDENT { + CSSParser* p = static_cast<CSSParser*>(parser); + $$ = p->createFloatingSelector(); + $$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace); + } + | IDENT pseudo { + CSSParser* p = static_cast<CSSParser*>(parser); + $$ = $2; + if ($$) + $$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace); + } + | pseudo { + $$ = $1; + } + | /* empty */ { + CSSParser* p = static_cast<CSSParser*>(parser); + $$ = p->createFloatingSelector(); + } + ; + +declarations_and_margins: + declaration_list + | declarations_and_margins margin_box maybe_space declaration_list + ; + +margin_box: + margin_sym { + static_cast<CSSParser*>(parser)->startDeclarationsForMarginBox(); + } maybe_space '{' maybe_space declaration_list closing_brace { + $$ = static_cast<CSSParser*>(parser)->createMarginAtRule($1); + } + ; + +margin_sym : + TOPLEFTCORNER_SYM { + $$ = CSSSelector::TopLeftCornerMarginBox; + } + | TOPLEFT_SYM { + $$ = CSSSelector::TopLeftMarginBox; + } + | TOPCENTER_SYM { + $$ = CSSSelector::TopCenterMarginBox; + } + | TOPRIGHT_SYM { + $$ = CSSSelector::TopRightMarginBox; + } + | TOPRIGHTCORNER_SYM { + $$ = CSSSelector::TopRightCornerMarginBox; + } + | BOTTOMLEFTCORNER_SYM { + $$ = CSSSelector::BottomLeftCornerMarginBox; + } + | BOTTOMLEFT_SYM { + $$ = CSSSelector::BottomLeftMarginBox; + } + | BOTTOMCENTER_SYM { + $$ = CSSSelector::BottomCenterMarginBox; + } + | BOTTOMRIGHT_SYM { + $$ = CSSSelector::BottomRightMarginBox; + } + | BOTTOMRIGHTCORNER_SYM { + $$ = CSSSelector::BottomRightCornerMarginBox; + } + | LEFTTOP_SYM { + $$ = CSSSelector::LeftTopMarginBox; + } + | LEFTMIDDLE_SYM { + $$ = CSSSelector::LeftMiddleMarginBox; + } + | LEFTBOTTOM_SYM { + $$ = CSSSelector::LeftBottomMarginBox; + } + | RIGHTTOP_SYM { + $$ = CSSSelector::RightTopMarginBox; + } + | RIGHTMIDDLE_SYM { + $$ = CSSSelector::RightMiddleMarginBox; + } + | RIGHTBOTTOM_SYM { + $$ = CSSSelector::RightBottomMarginBox; + } + ; + font_face: FONT_FACE_SYM maybe_space '{' maybe_space declaration_list '}' maybe_space { diff --git a/third_party/WebKit/WebCore/css/CSSParser.cpp b/third_party/WebKit/WebCore/css/CSSParser.cpp index 04a8855..97b0144 100644 --- a/third_party/WebKit/WebCore/css/CSSParser.cpp +++ b/third_party/WebKit/WebCore/css/CSSParser.cpp @@ -69,6 +69,7 @@ #include "WebKitCSSKeyframeRule.h" #include "WebKitCSSKeyframesRule.h" #include "WebKitCSSTransformValue.h" +#include <limits.h> #include <wtf/dtoa.h> #if ENABLE(DASHBOARD_SUPPORT) @@ -91,6 +92,8 @@ using namespace WTF; namespace WebCore { +static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX; + static bool equal(const CSSParserString& a, const char* b) { for (int i = 0; i < a.length; ++i) { @@ -135,6 +138,7 @@ CSSParser::CSSParser(bool strictParsing) , m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*)))) , m_numParsedProperties(0) , m_maxParsedProperties(32) + , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES) , m_inParseShorthand(0) , m_currentShorthand(0) , m_implicitShorthand(false) @@ -396,6 +400,7 @@ void CSSParser::clearProperties() for (unsigned i = 0; i < m_numParsedProperties; i++) delete m_parsedProperties[i]; m_numParsedProperties = 0; + m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES; m_hasFontFaceOnlyValues = false; } @@ -5193,6 +5198,39 @@ bool CSSParser::addVariableDeclarationBlock(const CSSParserString&) #endif +CSSRule* CSSParser::createPageRule(CSSSelector* /* pageSelector */) +{ + // FIXME: Create page rule here, using: + // - pageSelector->pseudoType(): the page pseudo-class, i.e., :left, :right, or :first + // - pageSelector->m_tag: the page name + // - m_parsedProperties: the page properties + + clearProperties(); + return 0; // until this method is implemented. +} + +CSSRule* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */) +{ + // FIXME: Implement margin at-rule here, using: + // - marginBox: margin box + // - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMarginBox, m_numParsedProperties) are for this at-rule. + + endDeclarationsForMarginBox(); + return 0; // until this method is implemented. +} + +void CSSParser::startDeclarationsForMarginBox() +{ + m_numParsedPropertiesBeforeMarginBox = m_numParsedProperties; +} + +void CSSParser::endDeclarationsForMarginBox() +{ + ASSERT(m_numParsedPropertiesBeforeMarginBox != INVALID_NUM_PARSED_PROPERTIES); + rollbackLastProperties(m_numParsedProperties - m_numParsedPropertiesBeforeMarginBox); + m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES; +} + void CSSParser::clearVariables() { m_variableNames.clear(); diff --git a/third_party/WebKit/WebCore/css/CSSParser.h b/third_party/WebKit/WebCore/css/CSSParser.h index ca8c66a..a88adc4 100644 --- a/third_party/WebKit/WebCore/css/CSSParser.h +++ b/third_party/WebKit/WebCore/css/CSSParser.h @@ -179,6 +179,10 @@ namespace WebCore { CSSRule* createStyleRule(Vector<CSSSelector*>* selectors); CSSRule* createFontFaceRule(); CSSRule* createVariablesRule(MediaList*, bool variablesKeyword); + CSSRule* createPageRule(CSSSelector* pageSelector); + CSSRule* createMarginAtRule(CSSSelector::MarginBoxType marginBox); + void startDeclarationsForMarginBox(); + void endDeclarationsForMarginBox(); MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*); MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*); @@ -212,6 +216,7 @@ namespace WebCore { CSSSelectorList* m_selectorListForParseSelector; unsigned m_numParsedProperties; unsigned m_maxParsedProperties; + unsigned m_numParsedPropertiesBeforeMarginBox; int m_inParseShorthand; int m_currentShorthand; diff --git a/third_party/WebKit/WebCore/css/CSSSelector.cpp b/third_party/WebKit/WebCore/css/CSSSelector.cpp index 64a7627..decb1bb 100644 --- a/third_party/WebKit/WebCore/css/CSSSelector.cpp +++ b/third_party/WebKit/WebCore/css/CSSSelector.cpp @@ -203,6 +203,9 @@ PseudoId CSSSelector::pseudoId(PseudoType type) case PseudoDoubleButton: case PseudoSingleButton: case PseudoNoButton: + case PseudoFirstPage: + case PseudoLeftPage: + case PseudoRightPage: return NOPSEUDO; case PseudoNotParsed: ASSERT_NOT_REACHED(); @@ -305,6 +308,10 @@ static HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoTypeMap( DEFINE_STATIC_LOCAL(AtomicString, singleButton, ("single-button")); DEFINE_STATIC_LOCAL(AtomicString, noButton, ("no-button")); DEFINE_STATIC_LOCAL(AtomicString, cornerPresent, ("corner-present")); + // Paged Media pseudo-classes + DEFINE_STATIC_LOCAL(AtomicString, firstPage, ("first")); + DEFINE_STATIC_LOCAL(AtomicString, leftPage, ("left")); + DEFINE_STATIC_LOCAL(AtomicString, rightPage, ("right")); static HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = 0; if (!nameToPseudoType) { @@ -399,6 +406,9 @@ static HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoTypeMap( nameToPseudoType->set(sliderThumb.impl(), CSSSelector::PseudoSliderThumb); nameToPseudoType->set(target.impl(), CSSSelector::PseudoTarget); nameToPseudoType->set(visited.impl(), CSSSelector::PseudoVisited); + nameToPseudoType->set(firstPage.impl(), CSSSelector::PseudoFirstPage); + nameToPseudoType->set(leftPage.impl(), CSSSelector::PseudoLeftPage); + nameToPseudoType->set(rightPage.impl(), CSSSelector::PseudoRightPage); } return nameToPseudoType; } @@ -515,6 +525,9 @@ void CSSSelector::extractPseudoType() const case PseudoSingleButton: case PseudoNoButton: case PseudoNotParsed: + case PseudoFirstPage: + case PseudoLeftPage: + case PseudoRightPage: break; } diff --git a/third_party/WebKit/WebCore/css/CSSSelector.h b/third_party/WebKit/WebCore/css/CSSSelector.h index 633101a..8f84b05 100644 --- a/third_party/WebKit/WebCore/css/CSSSelector.h +++ b/third_party/WebKit/WebCore/css/CSSSelector.h @@ -188,6 +188,28 @@ namespace WebCore { PseudoInnerSpinButton, PseudoOuterSpinButton, PseudoProgressBarValue, + PseudoLeftPage, + PseudoRightPage, + PseudoFirstPage, + }; + + enum MarginBoxType { + TopLeftCornerMarginBox, + TopLeftMarginBox, + TopCenterMarginBox, + TopRightMarginBox, + TopRightCornerMarginBox, + BottomLeftCornerMarginBox, + BottomLeftMarginBox, + BottomCenterMarginBox, + BottomRightMarginBox, + BottomRightCornerMarginBox, + LeftTopMarginBox, + LeftMiddleMarginBox, + LeftBottomMarginBox, + RightTopMarginBox, + RightMiddleMarginBox, + RightBottomMarginBox, }; PseudoType pseudoType() const diff --git a/third_party/WebKit/WebCore/css/tokenizer.flex b/third_party/WebKit/WebCore/css/tokenizer.flex index 3af725c..290c590 100644 --- a/third_party/WebKit/WebCore/css/tokenizer.flex +++ b/third_party/WebKit/WebCore/css/tokenizer.flex @@ -53,6 +53,22 @@ nth [\+-]?{intnum}*n([\+-]{intnum})? "@import" {BEGIN(mediaquery); yyTok = IMPORT_SYM; return yyTok;} "@page" {yyTok = PAGE_SYM; return yyTok;} +"@top-left-corner" {yyTok = TOPLEFTCORNER_SYM; return yyTok;} +"@top-left" {yyTok = TOPLEFT_SYM; return yyTok;} +"@top-center" {yyTok = TOPCENTER_SYM; return yyTok;} +"@top-right" {yyTok = TOPRIGHT_SYM; return yyTok;} +"@top-right-corner" {yyTok = TOPRIGHTCORNER_SYM; return yyTok;} +"@bottom-left-corner" {yyTok = BOTTOMLEFTCORNER_SYM; return yyTok;} +"@bottom-left" {yyTok = BOTTOMLEFT_SYM; return yyTok;} +"@bottom-center" {yyTok = BOTTOMCENTER_SYM; return yyTok;} +"@bottom-right" {yyTok = BOTTOMRIGHT_SYM; return yyTok;} +"@bottom-right-corner" {yyTok = BOTTOMRIGHTCORNER_SYM; return yyTok;} +"@left-top" {yyTok = LEFTTOP_SYM; return yyTok;} +"@left-middle" {yyTok = LEFTMIDDLE_SYM; return yyTok;} +"@left-bottom" {yyTok = LEFTBOTTOM_SYM; return yyTok;} +"@right-top" {yyTok = RIGHTTOP_SYM; return yyTok;} +"@right-middle" {yyTok = RIGHTMIDDLE_SYM; return yyTok;} +"@right-bottom" {yyTok = RIGHTBOTTOM_SYM; return yyTok;} "@media" {BEGIN(mediaquery); yyTok = MEDIA_SYM; return yyTok;} "@font-face" {yyTok = FONT_FACE_SYM; return yyTok;} "@charset" {yyTok = CHARSET_SYM; return yyTok;} |