Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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):

Canonical link: https://commits.webkit.org/49653@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@58383 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Yuzo Fujishima committed Apr 28, 2010
1 parent 849ad87 commit 8684f1c
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 57 deletions.
16 changes: 16 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,19 @@
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.
Expand Down
34 changes: 18 additions & 16 deletions LayoutTests/fast/dom/prototype-inheritance-2-expected.txt
Expand Up @@ -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__
Expand All @@ -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__
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions LayoutTests/printing/page-rule-css-text-expected.txt
@@ -0,0 +1,8 @@
@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; } }

76 changes: 76 additions & 0 deletions LayoutTests/printing/page-rule-css-text.html
@@ -0,0 +1,76 @@
<!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>

31 changes: 31 additions & 0 deletions WebCore/ChangeLog
@@ -1,3 +1,34 @@
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.
Expand Down
29 changes: 14 additions & 15 deletions WebCore/css/CSSPageRule.cpp
Expand Up @@ -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()
Expand All @@ -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
23 changes: 10 additions & 13 deletions WebCore/css/CSSPageRule.h
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions WebCore/css/CSSParser.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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 */)
Expand Down
5 changes: 3 additions & 2 deletions WebCore/css/CSSStyleRule.h
Expand Up @@ -40,7 +40,7 @@ class CSSStyleRule : public CSSRule {
}
virtual ~CSSStyleRule();

String selectorText() const;
virtual String selectorText() const;
void setSelectorText(const String&, ExceptionCode&);

CSSMutableStyleDeclaration* style() const { return m_style.get(); }
Expand All @@ -60,9 +60,10 @@ class CSSStyleRule : public CSSRule {

int sourceLine() { return m_sourceLine; }

private:
protected:
CSSStyleRule(CSSStyleSheet* parent, int sourceLine);

private:
virtual bool isStyleRule() { return true; }

// Inherited from CSSRule
Expand Down

0 comments on commit 8684f1c

Please sign in to comment.