Commit 1fcfaa52 authored by yuzo@google.com's avatar yuzo@google.com
Browse files

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

        Reviewed by David Hyatt.

        Retry of: 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/5136696-expected.txt.
        * fast/css/parsing-page-rule.html: Added.
2010-04-27  Yuzo Fujishima  <yuzo@google.com>

        Reviewed by David Hyatt.

        Retry of: 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::createPageRule):
        (WebCore::CSSParser::createMarginAtRule):
        (WebCore::CSSParser::startDeclarationsForMarginBox):
        (WebCore::CSSParser::endDeclarationsForMarginBox):
        * css/CSSParser.h:
        * css/CSSSelector.cpp:
        (WebCore::CSSSelector::pseudoId):
        (WebCore::nameToPseudoTypeMap):
        (WebCore::CSSSelector::extractPseudoType):
        * css/CSSSelector.h:
        (WebCore::CSSSelector::):
        * css/tokenizer.flex:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@58374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5cc9ccfc
2010-04-27 Yuzo Fujishima <yuzo@google.com>
Reviewed by David Hyatt.
Retry of: 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/5136696-expected.txt.
* fast/css/parsing-page-rule.html: Added.
2010-04-27 Julien Chaffraix <jchaffraix@webkit.org>
 
Unreviewed, rolling out my changes as it rendered the Qt bot unreliable.
......
<!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>
2010-04-27 Yuzo Fujishima <yuzo@google.com>
Reviewed by David Hyatt.
Retry of: 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::createPageRule):
(WebCore::CSSParser::createMarginAtRule):
(WebCore::CSSParser::startDeclarationsForMarginBox):
(WebCore::CSSParser::endDeclarationsForMarginBox):
* css/CSSParser.h:
* css/CSSSelector.cpp:
(WebCore::CSSSelector::pseudoId):
(WebCore::nameToPseudoTypeMap):
(WebCore::CSSSelector::extractPseudoType):
* css/CSSSelector.h:
(WebCore::CSSSelector::):
* css/tokenizer.flex:
2010-04-27 Julien Chaffraix <jchaffraix@webkit.org>
 
Unreviewed, rolling out my changes as it rendered the Qt bot unreliable.
......@@ -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,10 +257,12 @@ 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
%type <boolean> declaration
%type <boolean> declarations_and_margins
%type <boolean> prio
......@@ -729,26 +751,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 {
......
......@@ -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();
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment