Commit e86c7fe5 authored by eric@webkit.org's avatar eric@webkit.org

Reviewed by ap.

        Still more CSSParser cleanup
        - use c++ style member initializers in CSSParser()
        - change m_styleElement to m_styleSheet and make it a CSSStyleSheet
        - finally add my copyright to the files I've been cleaning

        * css/CSSGrammar.y:
        * css/CSSParser.cpp:
        (WebCore::CSSParser::CSSParser):
        (WebCore::CSSParser::setupParser):
        (WebCore::CSSParser::parseValue):
        (WebCore::CSSParser::parseColor):
        (WebCore::CSSParser::parseDeclaration):
        (WebCore::CSSParser::parseContent):
        (WebCore::CSSParser::parseFillImage):
        (WebCore::CSSParser::parseFontFaceSrc):
        (WebCore::CSSParser::parseBorderImage):
        (WebCore::CSSParser::createCharsetRule):
        (WebCore::CSSParser::createImportRule):
        (WebCore::CSSParser::createMediaRule):
        (WebCore::CSSParser::createStyleRule):
        * css/CSSParser.h:
        * css/SVGCSSParser.cpp:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34423 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b657e623
2008-06-07 Eric Seidel <eric@webkit.org>
Reviewed by ap.
Still more CSSParser cleanup
- use c++ style member initializers in CSSParser()
- change m_styleElement to m_styleSheet and make it a CSSStyleSheet
- finally add my copyright to the files I've been cleaning
* css/CSSGrammar.y:
* css/CSSParser.cpp:
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::setupParser):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseColor):
(WebCore::CSSParser::parseDeclaration):
(WebCore::CSSParser::parseContent):
(WebCore::CSSParser::parseFillImage):
(WebCore::CSSParser::parseFontFaceSrc):
(WebCore::CSSParser::parseBorderImage):
(WebCore::CSSParser::createCharsetRule):
(WebCore::CSSParser::createImportRule):
(WebCore::CSSParser::createMediaRule):
(WebCore::CSSParser::createStyleRule):
* css/CSSParser.h:
* css/SVGCSSParser.cpp:
2008-06-07 Eric Seidel <eric@webkit.org>
Reviewed by ap.
......@@ -4,6 +4,7 @@
* Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -287,8 +288,8 @@ charset:
CHARSET_SYM maybe_space STRING maybe_space ';' {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = static_cast<CSSParser*>(parser)->createCharsetRule($3);
if ($$ && p->m_styleElement && p->m_styleElement->isCSSStyleSheet())
p->m_styleElement->append($$);
if ($$ && p->m_styleSheet)
p->m_styleSheet->append($$);
}
| CHARSET_SYM error invalid_block {
}
......@@ -300,8 +301,8 @@ import_list:
/* empty */
| import_list import maybe_sgml {
CSSParser* p = static_cast<CSSParser*>(parser);
if ($2 && p->m_styleElement && p->m_styleElement->isCSSStyleSheet())
p->m_styleElement->append($2);
if ($2 && p->m_styleSheet)
p->m_styleSheet->append($2);
}
;
......@@ -314,8 +315,8 @@ rule_list:
/* empty */
| rule_list rule maybe_sgml {
CSSParser* p = static_cast<CSSParser*>(parser);
if ($2 && p->m_styleElement && p->m_styleElement->isCSSStyleSheet())
p->m_styleElement->append($2);
if ($2 && p->m_styleSheet)
p->m_styleSheet->append($2);
}
;
......@@ -348,8 +349,8 @@ import:
namespace:
NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' {
CSSParser* p = static_cast<CSSParser*>(parser);
if (p->m_styleElement && p->m_styleElement->isCSSStyleSheet())
static_cast<CSSStyleSheet*>(p->m_styleElement)->addNamespace(p, $3, $4);
if (p->m_styleSheet)
p->m_styleSheet->addNamespace(p, $3, $4);
}
| NAMESPACE_SYM error invalid_block
| NAMESPACE_SYM error ';'
......@@ -634,10 +635,10 @@ simple_selector:
AtomicString namespacePrefix = $1;
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
if (p->m_styleElement && p->m_styleElement->isCSSStyleSheet()) {
if (p->m_styleSheet)
$$->m_tag = QualifiedName(namespacePrefix, $2,
static_cast<CSSStyleSheet*>(p->m_styleElement)->determineNamespace(namespacePrefix));
} else // FIXME: Shouldn't this case be an error?
p->m_styleSheet->determineNamespace(namespacePrefix));
else // FIXME: Shouldn't this case be an error?
$$->m_tag = QualifiedName(nullAtom, $2, p->m_defaultNamespace);
}
| namespace_selector element_name specifier_list {
......@@ -645,10 +646,10 @@ simple_selector:
if ($$) {
AtomicString namespacePrefix = $1;
CSSParser* p = static_cast<CSSParser*>(parser);
if (p->m_styleElement && p->m_styleElement->isCSSStyleSheet()) {
if (p->m_styleSheet)
$$->m_tag = QualifiedName(namespacePrefix, $2,
static_cast<CSSStyleSheet*>(p->m_styleElement)->determineNamespace(namespacePrefix));
} else // FIXME: Shouldn't this case be an error?
p->m_styleSheet->determineNamespace(namespacePrefix));
else // FIXME: Shouldn't this case be an error?
$$->m_tag = QualifiedName(nullAtom, $2, p->m_defaultNamespace);
}
}
......@@ -657,10 +658,9 @@ simple_selector:
if ($$) {
AtomicString namespacePrefix = $1;
CSSParser* p = static_cast<CSSParser*>(parser);
if (p->m_styleElement && p->m_styleElement->isCSSStyleSheet())
$$->m_tag = QualifiedName(namespacePrefix,
starAtom,
static_cast<CSSStyleSheet*>(p->m_styleElement)->determineNamespace(namespacePrefix));
if (p->m_styleSheet)
$$->m_tag = QualifiedName(namespacePrefix, starAtom,
p->m_styleSheet->determineNamespace(namespacePrefix));
}
}
;
......@@ -771,7 +771,7 @@ attrib:
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_attr = QualifiedName(namespacePrefix, $4,
static_cast<CSSStyleSheet*>(p->m_styleElement)->determineNamespace(namespacePrefix));
p->m_styleSheet->determineNamespace(namespacePrefix));
$$->m_match = CSSSelector::Set;
}
| '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' {
......@@ -779,7 +779,7 @@ attrib:
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_attr = QualifiedName(namespacePrefix, $4,
static_cast<CSSStyleSheet*>(p->m_styleElement)->determineNamespace(namespacePrefix));
p->m_styleSheet->determineNamespace(namespacePrefix));
$$->m_match = (CSSSelector::Match)$5;
$$->m_value = $7;
}
......
......@@ -3,6 +3,7 @@
* Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -127,28 +128,25 @@ ValueList::~ValueList()
}
CSSParser::CSSParser(bool strictParsing)
: m_floatingMediaQuery(0)
: m_strict(strictParsing)
, m_important(false)
, m_id(0)
, m_styleSheet(0)
, m_mediaQuery(0)
, m_valueList(0)
, m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*))))
, m_numParsedProperties(0)
, m_maxParsedProperties(32)
, m_inParseShorthand(0)
, m_currentShorthand(0)
, m_implicitShorthand(false)
, m_defaultNamespace(starAtom)
, m_data(0)
, yy_start(1)
, m_floatingMediaQuery(0)
, m_floatingMediaQueryExp(0)
, m_floatingMediaQueryExpList(0)
{
m_strict = strictParsing;
m_parsedProperties = (CSSProperty **)fastMalloc(32 * sizeof(CSSProperty *));
m_numParsedProperties = 0;
m_maxParsedProperties = 32;
m_data = 0;
m_valueList = 0;
m_id = 0;
m_important = false;
m_inParseShorthand = 0;
m_currentShorthand = 0;
m_implicitShorthand = false;
m_defaultNamespace = starAtom;
yy_start = 1;
#if YYDEBUG > 0
cssyydebug = 1;
#endif
......@@ -195,9 +193,7 @@ void CSSParser::setupParser(const char* prefix, const String& string, const char
{
int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
if (m_data)
fastFree(m_data);
fastFree(m_data);
m_data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
for (unsigned i = 0; i < strlen(prefix); i++)
m_data[i] = prefix[i];
......@@ -220,7 +216,7 @@ void CSSParser::setupParser(const char* prefix, const String& string, const char
void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string)
{
m_styleElement = sheet;
m_styleSheet = sheet;
m_defaultNamespace = starAtom; // Reset the default namespace.
setupParser("", string, "");
......@@ -230,7 +226,7 @@ void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string)
PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
{
m_styleElement = sheet;
m_styleSheet = sheet;
setupParser("@-webkit-rule{", string, "} ");
cssyyparse(this);
return m_rule.release();
......@@ -238,7 +234,8 @@ PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& str
bool CSSParser::parseValue(CSSMutableStyleDeclaration* declaration, int id, const String& string, bool important)
{
m_styleElement = declaration->stylesheet();
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-value{", string, "} ");
......@@ -286,7 +283,8 @@ bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String& string)
{
m_styleElement = declaration->stylesheet();
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-decls{color:", string, "} ");
cssyyparse(this);
......@@ -297,7 +295,8 @@ bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String
bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string)
{
m_styleElement = declaration->stylesheet();
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet());
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet());
setupParser("@-webkit-decls{", string, "} ");
cssyyparse(this);
......@@ -364,7 +363,7 @@ void CSSParser::clearProperties()
Document* CSSParser::document() const
{
StyleBase* root = m_styleElement;
StyleBase* root = m_styleSheet;
Document* doc = 0;
while (root->parent())
root = root->parent();
......@@ -806,7 +805,7 @@ bool CSSParser::parseValue(int propId, bool important)
hotspot = IntPoint(coords[0], coords[1]);
if (m_strict || coords.size() == 0) {
if (!uri.isEmpty())
list->append(CSSCursorImageValue::create(KURL(m_styleElement->baseURL(), uri).string(), hotspot));
list->append(CSSCursorImageValue::create(KURL(m_styleSheet->baseURL(), uri).string(), hotspot));
}
if ((m_strict && !value) || (value && !(value->unit == Value::Operator && value->iValue == ',')))
return false;
......@@ -872,7 +871,7 @@ bool CSSParser::parseValue(int propId, bool important)
// ### allow string in non strict mode?
String uri = parseURL(value->string);
if (!uri.isEmpty()) {
parsedValue = CSSImageValue::create(KURL(m_styleElement->baseURL(), uri).string());
parsedValue = CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string());
m_valueList->next();
}
} else if (value->unit == Value::Function && equalIgnoringCase(value->function->name, "-webkit-gradient(")) {
......@@ -1089,7 +1088,7 @@ bool CSSParser::parseValue(int propId, bool important)
while ((val = m_valueList->current())) {
if (val->unit == CSSPrimitiveValue::CSS_URI) {
String value = parseURL(val->string);
parsedValue = new CSSPrimitiveValue(KURL(m_styleElement->baseURL(), value).string(),
parsedValue = new CSSPrimitiveValue(KURL(m_styleSheet->baseURL(), value).string(),
CSSPrimitiveValue::CSS_URI);
}
if (!parsedValue)
......@@ -1866,7 +1865,7 @@ bool CSSParser::parseContent(int propId, bool important)
if (val->unit == CSSPrimitiveValue::CSS_URI) {
// url
String value = parseURL(val->string);
parsedValue = CSSImageValue::create(KURL(m_styleElement->baseURL(), value).string());
parsedValue = CSSImageValue::create(KURL(m_styleSheet->baseURL(), value).string());
} else if (val->unit == Value::Function) {
// attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
ValueList* args = val->function->args;
......@@ -1937,7 +1936,7 @@ bool CSSParser::parseFillImage(RefPtr<CSSValue>& value)
if (m_valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
String uri = parseURL(m_valueList->current()->string);
if (!uri.isEmpty())
value = CSSImageValue::create(KURL(m_styleElement->baseURL(), uri).string());
value = CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string());
return true;
}
if (m_valueList->current()->unit == Value::Function) {
......@@ -2777,7 +2776,7 @@ bool CSSParser::parseFontFaceSrc()
RefPtr<CSSFontFaceSrcValue> parsedValue;
if (val->unit == CSSPrimitiveValue::CSS_URI && !expectComma) {
String value = parseURL(val->string);
parsedValue = new CSSFontFaceSrcValue(KURL(m_styleElement->baseURL(), value).string(), false);
parsedValue = new CSSFontFaceSrcValue(KURL(m_styleSheet->baseURL(), value).string(), false);
uriValue = parsedValue;
allowFormat = true;
expectComma = true;
......@@ -3381,7 +3380,7 @@ bool CSSParser::parseBorderImage(int propId, bool important, RefPtr<CSSValue>& r
String uri = parseURL(val->string);
if (uri.isEmpty())
return false;
context.commitImage(CSSImageValue::create(KURL(m_styleElement->baseURL(), uri).string()));
context.commitImage(CSSImageValue::create(KURL(m_styleSheet->baseURL(), uri).string()));
} else if (val->unit == Value::Function) {
RefPtr<CSSValue> value;
if ((equalIgnoringCase(val->function->name, "-webkit-gradient(") && parseGradient(value)) ||
......@@ -4173,39 +4172,27 @@ MediaList* CSSParser::createMediaList()
CSSRule* CSSParser::createCharsetRule(const ParseString& charset)
{
if (!m_styleElement)
return 0;
if (!m_styleElement->isCSSStyleSheet())
if (!m_styleSheet)
return 0;
CSSCharsetRule* rule = new CSSCharsetRule(m_styleElement, charset);
CSSCharsetRule* rule = new CSSCharsetRule(m_styleSheet, charset);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createImportRule(const ParseString& url, MediaList* media)
{
if (!media)
return 0;
if (!m_styleElement)
return 0;
if (!m_styleElement->isCSSStyleSheet())
if (!media || !m_styleSheet)
return 0;
CSSImportRule* rule = new CSSImportRule(m_styleElement, url, media);
CSSImportRule* rule = new CSSImportRule(m_styleSheet, url, media);
m_parsedStyleObjects.append(rule);
return rule;
}
CSSRule* CSSParser::createMediaRule(MediaList* media, CSSRuleList* rules)
{
if (!media)
return 0;
if (!rules)
return 0;
if (!m_styleElement)
return 0;
if (!m_styleElement->isCSSStyleSheet())
if (!media || !rules || !m_styleSheet)
return 0;
CSSMediaRule* rule = new CSSMediaRule(m_styleElement, media, rules);
CSSMediaRule* rule = new CSSMediaRule(m_styleSheet, media, rules);
m_parsedStyleObjects.append(rule);
return rule;
}
......@@ -4223,7 +4210,7 @@ CSSRule* CSSParser::createStyleRule(CSSSelector* selector)
{
CSSStyleRule* rule = 0;
if (selector) {
rule = new CSSStyleRule(m_styleElement);
rule = new CSSStyleRule(m_styleSheet);
m_parsedStyleObjects.append(rule);
rule->setSelector(sinkFloatingSelector(selector));
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, m_parsedProperties, m_numParsedProperties));
......@@ -4234,7 +4221,7 @@ CSSRule* CSSParser::createStyleRule(CSSSelector* selector)
CSSRule* CSSParser::createFontFaceRule()
{
CSSFontFaceRule* rule = new CSSFontFaceRule(m_styleElement);
CSSFontFaceRule* rule = new CSSFontFaceRule(m_styleSheet);
m_parsedStyleObjects.append(rule);
rule->setDeclaration(new CSSMutableStyleDeclaration(rule, m_parsedProperties, m_numParsedProperties));
clearProperties();
......
/*
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -40,7 +41,6 @@ namespace WebCore {
class CSSValueList;
class Document;
class MediaList;
class MediaList;
class MediaQueryExp;
class StyleBase;
class StyleList;
......@@ -216,7 +216,7 @@ namespace WebCore {
bool m_strict;
bool m_important;
int m_id;
StyleList* m_styleElement;
CSSStyleSheet* m_styleSheet;
RefPtr<CSSRule> m_rule;
MediaQuery* m_mediaQuery;
ValueList* m_valueList;
......
/*
Copyright (C) 2008 Eric Seidel <eric@webkit.org>
Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005, 2007 Rob Buis <buis@kde.org>
Copyright (C) 2005, 2006 Apple Computer, Inc.
This file is part of the KDE project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
......
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