Commit 4e988936 authored by yuzo@google.com's avatar yuzo@google.com
Browse files

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

        Reviewed by Eric Seidel.

        Enhance CSS parser for Paged Media (Iteration 2)
        Parse and hold paged media rules in CSSStyleSelector.

        fast/dom/script-tests/prototype-inheritance-2.js is rebaselined because it assumes @page is ignored.

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

        * fast/dom/prototype-inheritance-2-expected.txt:
        * fast/dom/script-tests/prototype-inheritance-2.js:
        * printing/page-rule-css-text-expected.txt: Added.
        * printing/page-rule-css-text.html: Added.
2010-04-27  Yuzo Fujishima  <yuzo@google.com>

        Reviewed by Eric Seidel.

        Enhance CSS parser for Paged Media (Iteration 2)
        Parse and hold paged media rules in CSSStyleSelector.

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

        Test: printing/page-rule-css-text.html

        * css/CSSGrammar.y:
        * css/CSSPageRule.cpp:
        (WebCore::CSSPageRule::CSSPageRule):
        (WebCore::CSSPageRule::selectorText):
        * css/CSSPageRule.h:
        (WebCore::CSSPageRule::create):
        (WebCore::CSSPageRule::isPageRule):
        * css/CSSParser.cpp:
        (WebCore::CSSParser::createPageRule):
        * css/CSSStyleRule.h:
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSRuleSet::getPageRules):
        (WebCore::CSSRuleSet::CSSRuleSet):
        (WebCore::CSSRuleSet::~CSSRuleSet):
        (WebCore::CSSRuleSet::addPageRule):
        (WebCore::CSSRuleSet::addRulesFromSheet):
        * css/CSSStyleSelector.h:
        * css/StyleBase.h:
        (WebCore::StyleBase::isPageRule):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@58383 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9f8cb6db
2010-04-27 Yuzo Fujishima <yuzo@google.com>
Reviewed by Eric Seidel.
Enhance CSS parser for Paged Media (Iteration 2)
Parse and hold paged media rules in CSSStyleSelector.
fast/dom/script-tests/prototype-inheritance-2.js is rebaselined because it assumes @page is ignored.
https://bugs.webkit.org/show_bug.cgi?id=35782
* fast/dom/prototype-inheritance-2-expected.txt:
* fast/dom/script-tests/prototype-inheritance-2.js:
* printing/page-rule-css-text-expected.txt: Added.
* printing/page-rule-css-text.html: Added.
2010-04-27 Daniel Bates <dbates@rim.com>
 
Reviewed by Oliver Hunt.
......
......@@ -13,15 +13,18 @@ FAIL Boolean from inner.document.forms.testForm.0.noValidate
PASS CSSCharsetRule from inner.document.getElementById("dummyStyle").sheet.cssRules.0
PASS CSSCharsetRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.0.constructor
PASS CSSCharsetRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.0.__proto__
PASS CSSFontFaceRule from inner.document.getElementById("dummyStyle").sheet.cssRules.3
PASS CSSFontFaceRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.3.constructor
PASS CSSFontFaceRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.3.__proto__
PASS CSSFontFaceRule from inner.document.getElementById("dummyStyle").sheet.cssRules.4
PASS CSSFontFaceRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.4.constructor
PASS CSSFontFaceRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.4.__proto__
PASS CSSImportRule from inner.document.getElementById("dummyStyle").sheet.cssRules.1
PASS CSSImportRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.1.constructor
PASS CSSImportRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.1.__proto__
PASS CSSMediaRule from inner.document.getElementById("dummyStyle").sheet.cssRules.2
PASS CSSMediaRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.2.constructor
PASS CSSMediaRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.2.__proto__
PASS CSSMediaRule from inner.document.getElementById("dummyStyle").sheet.cssRules.3
PASS CSSMediaRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.3.constructor
PASS CSSMediaRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.3.__proto__
PASS CSSPageRule from inner.document.getElementById("dummyStyle").sheet.cssRules.2
PASS CSSPageRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.2.constructor
PASS CSSPageRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.2.__proto__
PASS CSSPrimitiveValue from inner.getComputedStyle(inner.document.body).getPropertyCSSValue(background-clip)
PASS CSSPrimitiveValueConstructor from inner.getComputedStyle(inner.document.body).getPropertyCSSValue(background-clip).constructor
PASS CSSPrimitiveValuePrototype from inner.getComputedStyle(inner.document.body).getPropertyCSSValue(background-clip).__proto__
......@@ -32,9 +35,9 @@ PASS CSSRulePrototype from inner.document.getElementById("dummyStyle").sheet.css
PASS CSSStyleDeclaration from inner.document.getElementById("styledSpan").style
PASS CSSStyleDeclarationConstructor from inner.document.forms.testForm.0.style.constructor
PASS CSSStyleDeclarationPrototype from inner.document.forms.testForm.0.0.style.__proto__
PASS CSSStyleRule from inner.document.getElementById("dummyStyle").sheet.cssRules.4
PASS CSSStyleRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.4.constructor
PASS CSSStyleRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.4.__proto__
PASS CSSStyleRule from inner.document.getElementById("dummyStyle").sheet.cssRules.5
PASS CSSStyleRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.5.constructor
PASS CSSStyleRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.5.__proto__
PASS CSSStyleSheet from inner.document.forms.testForm.0.ownerDocument.styleSheets.0
PASS CSSStyleSheetConstructor from inner.document.forms.testForm.0.ownerDocument.styleSheets.0.constructor
PASS CSSStyleSheetPrototype from inner.document.forms.testForm.0.ownerDocument.styleSheets.0.__proto__
......@@ -196,17 +199,16 @@ PASS TimeRanges from inner.document.forms.testForm.0.previousElementSibling.play
PASS TimeRangesPrototype from inner.document.forms.testForm.0.previousElementSibling.played.__proto__
PASS ValidityState from inner.document.forms.testForm.0.0.validity
PASS ValidityStatePrototype from inner.document.forms.testForm.0.0.validity.__proto__
PASS WebKitCSSKeyframeRule from inner.document.getElementById("dummyStyle").sheet.cssRules.5.0
PASS WebKitCSSKeyframeRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.5.0.constructor
PASS WebKitCSSKeyframeRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.5.0.__proto__
PASS WebKitCSSKeyframesRule from inner.document.getElementById("dummyStyle").sheet.cssRules.5
PASS WebKitCSSKeyframesRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.5.constructor
PASS WebKitCSSKeyframesRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.5.__proto__
PASS WebKitCSSKeyframeRule from inner.document.getElementById("dummyStyle").sheet.cssRules.6.0
PASS WebKitCSSKeyframeRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.6.0.constructor
PASS WebKitCSSKeyframeRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.6.0.__proto__
PASS WebKitCSSKeyframesRule from inner.document.getElementById("dummyStyle").sheet.cssRules.6
PASS WebKitCSSKeyframesRuleConstructor from inner.document.getElementById("dummyStyle").sheet.cssRules.6.constructor
PASS WebKitCSSKeyframesRulePrototype from inner.document.getElementById("dummyStyle").sheet.cssRules.6.__proto__
PASS XSLTProcessorConsructor from inner.document.forms.testForm.0.ownerDocument.defaultView.XSLTProcessor
Never found Audio
Never found Blob
Never found CDATASection
Never found CSSPageRule
Never found CSSRule
Never found CSSVariablesDeclaration
Never found CSSVariablesRule
......
......@@ -196,7 +196,7 @@ htmlToAdd += "<!-- test -->";
styleContents = "@charset 'UTF-8';";
styleContents += "@import url('dummy.css') print;\n"; // Our parser seems to want this rule first?
styleContents += "@variables { Ignored: 2em; }\n"; // For when variables are turned back on
styleContents += "@page { margin: 3cm; }\n"; // Current WebKit ignores @page
styleContents += "@page { margin: 3cm; }\n";
styleContents += "@media print { body { margin: 3cm; } }\n"
styleContents += "@font-face {font-family:'Times';}\n";
styleContents += "ignored {font-family: var(Ignored);}\n"; // a CSSStyleRule
......
@page { margin-top: 5cm; margin-bottom: 10cm; }
@page :left { margin-right: 3cm; }
@page :right { margin-left: 3cm; }
@page :first { border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; }
@page hello { color: green; }
@page world:right { color: red; }
@media print { @page somepage:first { margin-top: 3cm; margin-right: 3cm; margin-bottom: 3cm; margin-left: 3cm; } }
<!doctype html>
<html>
<head>
<style type="text/css">
@page {
margin-top:5cm;
margin-bottom:10cm;
}
@page :left {
margin-right:3cm;
}
@page :right {
margin-left:3cm;
}
@page :first {
border-width:1px;
}
@page hello {
color:green;
}
@page world:right {
color:red;
}
@media print {
@page somepage:first {
margin:3cm;
}
}
/* FIXME: Add the following once size property is implemented.
@page :left {
size: 4in 6in;
}
@page :right {
size: letter;
}
*/
/* FIXME: Add the following once margin at-rule is implemented.
@page :first {
@top-left-corner {
content:"TLC";
}
@bottom-center {
content:"BC";
}
}
*/
</style>
<script type="text/javascript">
if (window.layoutTestController)
layoutTestController.dumpAsText();
function print(str)
{
document.getElementById("output").innerHTML += str;
}
function printCssTextOfPageRules()
{
var ss = document.styleSheets;
for (var i = 0; i < ss.length; i++) {
for (var j = 0; j < ss[i].cssRules.length; j++) {
print(ss[i].cssRules[j].cssText + "<br/>");
}
}
}
</script>
</head>
<body onload="printCssTextOfPageRules();">
<div id="output"></div>
</body>
</html>
2010-04-27 Yuzo Fujishima <yuzo@google.com>
Reviewed by Eric Seidel.
Enhance CSS parser for Paged Media (Iteration 2)
Parse and hold paged media rules in CSSStyleSelector.
https://bugs.webkit.org/show_bug.cgi?id=35782
Test: printing/page-rule-css-text.html
* css/CSSGrammar.y:
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::CSSPageRule):
(WebCore::CSSPageRule::selectorText):
* css/CSSPageRule.h:
(WebCore::CSSPageRule::create):
(WebCore::CSSPageRule::isPageRule):
* css/CSSParser.cpp:
(WebCore::CSSParser::createPageRule):
* css/CSSStyleRule.h:
* css/CSSStyleSelector.cpp:
(WebCore::CSSRuleSet::getPageRules):
(WebCore::CSSRuleSet::CSSRuleSet):
(WebCore::CSSRuleSet::~CSSRuleSet):
(WebCore::CSSRuleSet::addPageRule):
(WebCore::CSSRuleSet::addRulesFromSheet):
* css/CSSStyleSelector.h:
* css/StyleBase.h:
(WebCore::StyleBase::isPageRule):
2010-04-27 Daniel Bates <dbates@rim.com>
 
Reviewed by Oliver Hunt.
......@@ -23,12 +23,16 @@
#include "CSSPageRule.h"
#include "CSSMutableStyleDeclaration.h"
#include <wtf/Vector.h>
namespace WebCore {
CSSPageRule::CSSPageRule(CSSStyleSheet* parent)
: CSSRule(parent)
CSSPageRule::CSSPageRule(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine)
: CSSStyleRule(parent, sourceLine)
{
Vector<CSSSelector*> selectors;
selectors.append(selector);
adoptSelectorVector(selectors);
}
CSSPageRule::~CSSPageRule()
......@@ -37,19 +41,14 @@ CSSPageRule::~CSSPageRule()
String CSSPageRule::selectorText() const
{
// FIXME: Implement!
return String();
}
void CSSPageRule::setSelectorText(const String& /*selectorText*/, ExceptionCode& /*ec*/)
{
// FIXME: Implement!
}
String CSSPageRule::cssText() const
{
// FIXME: Implement!
return String();
String text = "@page";
CSSSelector* selector = selectorList().first();
if (selector) {
String pageSpecification = selector->selectorText();
if (!pageSpecification.isEmpty() && pageSpecification != starAtom)
text += " " + pageSpecification;
}
return text;
}
} // namespace WebCore
......@@ -22,37 +22,34 @@
#ifndef CSSPageRule_h
#define CSSPageRule_h
#include "CSSRule.h"
#include "CSSStyleRule.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class CSSMutableStyleDeclaration;
class CSSSelector;
class CSSSelectorList;
class CSSPageRule : public CSSRule {
class CSSPageRule : public CSSStyleRule {
public:
static PassRefPtr<CSSPageRule> create(CSSStyleSheet* parent)
static PassRefPtr<CSSPageRule> create(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine)
{
return adoptRef(new CSSPageRule(parent));
return adoptRef(new CSSPageRule(parent, selector, sourceLine));
}
virtual ~CSSPageRule();
String selectorText() const;
void setSelectorText(const String&, ExceptionCode&);
CSSMutableStyleDeclaration* style() const { return m_style.get(); }
virtual String cssText() const;
virtual String selectorText() const;
private:
CSSPageRule(CSSStyleSheet* parent);
CSSPageRule(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine);
virtual bool isPageRule() { return true; }
// Inherited from CSSRule
virtual unsigned short type() const { return PAGE_RULE; }
RefPtr<CSSMutableStyleDeclaration> m_style;
};
} // namespace WebCore
......
......@@ -40,6 +40,7 @@
#include "CSSInitialValue.h"
#include "CSSMediaRule.h"
#include "CSSMutableStyleDeclaration.h"
#include "CSSPageRule.h"
#include "CSSPrimitiveValue.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
......@@ -5198,15 +5199,19 @@ bool CSSParser::addVariableDeclarationBlock(const CSSParserString&)
#endif
CSSRule* CSSParser::createPageRule(CSSSelector* /* pageSelector */)
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
// FIXME: Margin at-rules are ignored.
m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false;
CSSPageRule* pageRule = 0;
if (pageSelector) {
RefPtr<CSSPageRule> rule = CSSPageRule::create(m_styleSheet, pageSelector, m_lastSelectorLine);
rule->setDeclaration(CSSMutableStyleDeclaration::create(rule.get(), m_parsedProperties, m_numParsedProperties));
pageRule = rule.get();
m_parsedStyleObjects.append(rule.release());
}
clearProperties();
return 0; // until this method is implemented.
return pageRule;
}
CSSRule* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
......
......@@ -40,7 +40,7 @@ public:
}
virtual ~CSSStyleRule();
String selectorText() const;
virtual String selectorText() const;
void setSelectorText(const String&, ExceptionCode&);
CSSMutableStyleDeclaration* style() const { return m_style.get(); }
......@@ -60,9 +60,10 @@ public:
int sourceLine() { return m_sourceLine; }
private:
protected:
CSSStyleRule(CSSStyleSheet* parent, int sourceLine);
private:
virtual bool isStyleRule() { return true; }
// Inherited from CSSRule
......
......@@ -31,6 +31,7 @@
#include "CSSFontFaceRule.h"
#include "CSSImportRule.h"
#include "CSSMediaRule.h"
#include "CSSPageRule.h"
#include "CSSParser.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSPropertyNames.h"
......@@ -358,6 +359,7 @@ public:
void addRulesFromSheet(CSSStyleSheet*, const MediaQueryEvaluator&, CSSStyleSelector* = 0);
void addRule(CSSStyleRule* rule, CSSSelector* sel);
void addPageRule(CSSStyleRule* rule, CSSSelector* sel);
void addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map,
CSSStyleRule* rule, CSSSelector* sel);
......@@ -365,13 +367,16 @@ public:
CSSRuleDataList* getClassRules(AtomicStringImpl* key) { return m_classRules.get(key); }
CSSRuleDataList* getTagRules(AtomicStringImpl* key) { return m_tagRules.get(key); }
CSSRuleDataList* getUniversalRules() { return m_universalRules; }
CSSRuleDataList* getPageRules() { return m_pageRules; }
public:
AtomRuleMap m_idRules;
AtomRuleMap m_classRules;
AtomRuleMap m_tagRules;
CSSRuleDataList* m_universalRules;
CSSRuleDataList* m_pageRules;
unsigned m_ruleCount;
unsigned m_pageRuleCount;
};
static CSSRuleSet* defaultStyle;
......@@ -2677,7 +2682,9 @@ CSSValue* CSSStyleSelector::resolveVariableDependentValue(CSSVariableDependentVa
CSSRuleSet::CSSRuleSet()
{
m_universalRules = 0;
m_pageRules = 0;
m_ruleCount = 0;
m_pageRuleCount = 0;
}
CSSRuleSet::~CSSRuleSet()
......@@ -2687,6 +2694,7 @@ CSSRuleSet::~CSSRuleSet()
deleteAllValues(m_tagRules);
delete m_universalRules;
delete m_pageRules;
}
......@@ -2726,6 +2734,14 @@ void CSSRuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel)
m_universalRules->append(m_ruleCount++, rule, sel);
}
void CSSRuleSet::addPageRule(CSSStyleRule* rule, CSSSelector* sel)
{
if (!m_pageRules)
m_pageRules = new CSSRuleDataList(m_pageRuleCount++, rule, sel);
else
m_pageRules->append(m_pageRuleCount++, rule, sel);
}
void CSSRuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator& medium, CSSStyleSelector* styleSelector)
{
if (!sheet)
......@@ -2741,9 +2757,14 @@ void CSSRuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluat
for (int i = 0; i < len; i++) {
StyleBase* item = sheet->item(i);
if (item->isStyleRule()) {
CSSStyleRule* rule = static_cast<CSSStyleRule*>(item);
for (CSSSelector* s = rule->selectorList().first(); s; s = CSSSelectorList::next(s))
addRule(rule, s);
if (item->isPageRule()) {
CSSPageRule* pageRule = static_cast<CSSPageRule*>(item);
addPageRule(pageRule, pageRule->selectorList().first());
} else {
CSSStyleRule* rule = static_cast<CSSStyleRule*>(item);
for (CSSSelector* s = rule->selectorList().first(); s; s = CSSSelectorList::next(s))
addRule(rule, s);
}
}
else if (item->isImportRule()) {
CSSImportRule* import = static_cast<CSSImportRule*>(item);
......
......@@ -35,6 +35,7 @@
namespace WebCore {
class CSSMutableStyleDeclaration;
class CSSPageRule;
class CSSPrimitiveValue;
class CSSProperty;
class CSSFontFace;
......@@ -155,6 +156,7 @@ public:
void resolveVariablesForDeclaration(CSSMutableStyleDeclaration* decl, CSSMutableStyleDeclaration* newDecl, HashSet<String>& usedBlockVariables);
void addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule> rule);
void addPageStyle(PassRefPtr<CSSPageRule>);
static bool createTransformOperations(CSSValue* inValue, RenderStyle* inStyle, RenderStyle* rootStyle, TransformOperations& outOperations);
......
......@@ -54,6 +54,7 @@ namespace WebCore {
virtual bool isKeyframesRule() { return false; }
virtual bool isMediaRule() { return false; }
virtual bool isVariablesRule() { return false; }
virtual bool isPageRule() { return false; }
virtual bool isRule() { return false; }
virtual bool isStyleRule() { return false; }
......
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