Commit 3c931302 authored by antti@apple.com's avatar antti@apple.com
Browse files

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

Eliminate m_tagHistory pointer from CSSSelector

Reviewed by Darin Adler.

Keep the component selectors in the array in CSSSelectorList instead
of maintaining a linked list between them. This allows eliminating
m_tagHistory pointer, shrinking CSSSelector by 25% (selection performance
seems to improve some too due to better locality).

* WebCore.xcodeproj/project.pbxproj:
        
    Make CSSSelector.h a private header.
        
* css/CSSGrammar.y:
        
    Use CSSParserSelector during parsing to keep the tag history in 
    a linked list. This is flattened to an array after parsing.
    Use accessors for setting selector values.
    Use OwnPtr in selector vector.
            
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::CSSPageRule):
* css/CSSPageRule.h:
(WebCore::CSSPageRule::create):
        
    Simplify.
    
* css/CSSParser.cpp:
(WebCore::CSSParser::~CSSParser):
(WebCore::CSSParser::createFloatingSelector):
(WebCore::CSSParser::sinkFloatingSelector):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::updateSpecifiersWithElementName):
(WebCore::CSSParser::createPageRule):
* css/CSSParser.h:
(WebCore::CSSParser::reusableSelectorVector):
        
    CSSSelector -> CSSParserSelector.
    Use OwnPtr in selector vector.
            
* css/CSSParserValues.cpp:
(WebCore::CSSParserSelector::CSSParserSelector):
(WebCore::CSSParserSelector::~CSSParserSelector):
* css/CSSParserValues.h:
(WebCore::CSSParserSelector::releaseSelector):
(WebCore::CSSParserSelector::setTag):
(WebCore::CSSParserSelector::setValue):
(WebCore::CSSParserSelector::setAttribute):
(WebCore::CSSParserSelector::setArgument):
(WebCore::CSSParserSelector::setSimpleSelector):
(WebCore::CSSParserSelector::setMatch):
(WebCore::CSSParserSelector::setRelation):
(WebCore::CSSParserSelector::setForPage):
(WebCore::CSSParserSelector::pseudoType):
(WebCore::CSSParserSelector::isUnknownPseudoElement):
(WebCore::CSSParserSelector::isSimple):
(WebCore::CSSParserSelector::tagHistory):
(WebCore::CSSParserSelector::setTagHistory):
        
    Linked list used during parsing.
    Avoid recursive destruction.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::extractPseudoType):
(WebCore::CSSSelector::operator==):
(WebCore::CSSSelector::selectorText):
(WebCore::CSSSelector::setSimpleSelector):
* css/CSSSelector.h:
(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::~CSSSelector):
(WebCore::CSSSelector::tagHistory):
(WebCore::CSSSelector::tag):
(WebCore::CSSSelector::value):
(WebCore::CSSSelector::setTag):
(WebCore::CSSSelector::isLastInTagHistory):
(WebCore::CSSSelector::setNotLastInTagHistory):
(WebCore::CSSSelector::RareData::RareData):
(WebCore::CSSSelector::RareData::~RareData):
(WebCore::CSSSelector::createRareData):
(WebCore::CSSSelector::setValue):
        
    Remove m_tagHistory.
    Keep m_value in the union with the rare data pointer instead.
    Make m_value and m_tag private, implement accessors.
    Add a new bit to indicate end of the tag history (multipart selector).
    Eliminate complex destruction. Selectors are now deleted as an array or by a CSSParserSelector chain.
            
* css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::adoptSelectorVector):
        
    Flatten everything to an array.
        
(WebCore::SelectorNeedsNamespaceResolutionFunctor::operator()):
* css/CSSSelectorList.h:
(WebCore::CSSSelectorList::hasOneSelector):
(WebCore::CSSSelectorList::next):
        
    Skip over the subparts of multipart selectors to find the next selector.
    
* css/CSSStyleRule.h:
(WebCore::CSSStyleRule::adoptSelectorVector):
        
    CSSSelector -> CSSParserSelector.
            
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::SelectorChecker::checkOneSelector):
(WebCore::CSSRuleSet::addRule):
(WebCore::collectIdsAndSiblingRulesFromList):
(WebCore::CSSStyleSelector::matchPageRulesForList):
* dom/Node.cpp:
(WebCore::Node::querySelector):
* dom/SelectorNodeList.cpp:
(WebCore::createSelectorNodeList):
        
    Use accessors.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76648 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 13aa0664
2011-01-23 Antti Koivisto <antti@apple.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=52983
Eliminate m_tagHistory pointer from CSSSelector
Keep the component selectors in the array in CSSSelectorList instead
of maintaining a linked list between them. This allows eliminating
m_tagHistory pointer, shrinking CSSSelector by 25% (selection performance
seems to improve some too due to better locality).
* WebCore.xcodeproj/project.pbxproj:
Make CSSSelector.h a private header.
* css/CSSGrammar.y:
Use CSSParserSelector during parsing to keep the tag history in
a linked list. This is flattened to an array after parsing.
Use accessors for setting selector values.
Use OwnPtr in selector vector.
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::CSSPageRule):
* css/CSSPageRule.h:
(WebCore::CSSPageRule::create):
Simplify.
* css/CSSParser.cpp:
(WebCore::CSSParser::~CSSParser):
(WebCore::CSSParser::createFloatingSelector):
(WebCore::CSSParser::sinkFloatingSelector):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::updateSpecifiersWithElementName):
(WebCore::CSSParser::createPageRule):
* css/CSSParser.h:
(WebCore::CSSParser::reusableSelectorVector):
CSSSelector -> CSSParserSelector.
Use OwnPtr in selector vector.
* css/CSSParserValues.cpp:
(WebCore::CSSParserSelector::CSSParserSelector):
(WebCore::CSSParserSelector::~CSSParserSelector):
* css/CSSParserValues.h:
(WebCore::CSSParserSelector::releaseSelector):
(WebCore::CSSParserSelector::setTag):
(WebCore::CSSParserSelector::setValue):
(WebCore::CSSParserSelector::setAttribute):
(WebCore::CSSParserSelector::setArgument):
(WebCore::CSSParserSelector::setSimpleSelector):
(WebCore::CSSParserSelector::setMatch):
(WebCore::CSSParserSelector::setRelation):
(WebCore::CSSParserSelector::setForPage):
(WebCore::CSSParserSelector::pseudoType):
(WebCore::CSSParserSelector::isUnknownPseudoElement):
(WebCore::CSSParserSelector::isSimple):
(WebCore::CSSParserSelector::tagHistory):
(WebCore::CSSParserSelector::setTagHistory):
Linked list used during parsing.
Avoid recursive destruction.
* css/CSSSelector.cpp:
(WebCore::CSSSelector::extractPseudoType):
(WebCore::CSSSelector::operator==):
(WebCore::CSSSelector::selectorText):
(WebCore::CSSSelector::setSimpleSelector):
* css/CSSSelector.h:
(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::~CSSSelector):
(WebCore::CSSSelector::tagHistory):
(WebCore::CSSSelector::tag):
(WebCore::CSSSelector::value):
(WebCore::CSSSelector::setTag):
(WebCore::CSSSelector::isLastInTagHistory):
(WebCore::CSSSelector::setNotLastInTagHistory):
(WebCore::CSSSelector::RareData::RareData):
(WebCore::CSSSelector::RareData::~RareData):
(WebCore::CSSSelector::createRareData):
(WebCore::CSSSelector::setValue):
Remove m_tagHistory.
Keep m_value in the union with the rare data pointer instead.
Make m_value and m_tag private, implement accessors.
Add a new bit to indicate end of the tag history (multipart selector).
Eliminate complex destruction. Selectors are now deleted as an array or by a CSSParserSelector chain.
* css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::adoptSelectorVector):
Flatten everything to an array.
(WebCore::SelectorNeedsNamespaceResolutionFunctor::operator()):
* css/CSSSelectorList.h:
(WebCore::CSSSelectorList::hasOneSelector):
(WebCore::CSSSelectorList::next):
Skip over the subparts of multipart selectors to find the next selector.
* css/CSSStyleRule.h:
(WebCore::CSSStyleRule::adoptSelectorVector):
CSSSelector -> CSSParserSelector.
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::SelectorChecker::checkOneSelector):
(WebCore::CSSRuleSet::addRule):
(WebCore::collectIdsAndSiblingRulesFromList):
(WebCore::CSSStyleSelector::matchPageRulesForList):
* dom/Node.cpp:
(WebCore::Node::querySelector):
* dom/SelectorNodeList.cpp:
(WebCore::createSelectorNodeList):
Use accessors.
2011-01-25 James Simonsen <simonjam@chromium.org>
 
Reviewed by Tony Chang.
......@@ -3273,7 +3273,7 @@
A80E734F0A199C77007FB8C5 /* CSSSelector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E73480A199C77007FB8C5 /* CSSSelector.cpp */; };
A80E73500A199C77007FB8C5 /* StyleBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E73490A199C77007FB8C5 /* StyleBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
A80E73510A199C77007FB8C5 /* StyleList.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E734A0A199C77007FB8C5 /* StyleList.h */; };
A80E73520A199C77007FB8C5 /* CSSSelector.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E734B0A199C77007FB8C5 /* CSSSelector.h */; };
A80E73520A199C77007FB8C5 /* CSSSelector.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E734B0A199C77007FB8C5 /* CSSSelector.h */; settings = {ATTRIBUTES = (Private, ); }; };
A80E73530A199C77007FB8C5 /* StyleBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E734C0A199C77007FB8C5 /* StyleBase.cpp */; };
A80E7A170A19C3D6007FB8C5 /* JSHTMLMetaElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A80E7A150A19C3D6007FB8C5 /* JSHTMLMetaElement.cpp */; };
A80E7A180A19C3D6007FB8C5 /* JSHTMLMetaElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A80E7A160A19C3D6007FB8C5 /* JSHTMLMetaElement.h */; };
......@@ -69,8 +69,8 @@ using namespace HTMLNames;
CSSRule* rule;
CSSRuleList* ruleList;
CSSSelector* selector;
Vector<CSSSelector*>* selectorList;
CSSParserSelector* selector;
Vector<OwnPtr<CSSParserSelector> >* selectorList;
CSSSelector::MarginBoxType marginBox;
CSSSelector::Relation relation;
MediaList* mediaList;
......@@ -663,14 +663,14 @@ page_selector:
IDENT {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace);
$$->setTag(QualifiedName(nullAtom, $1, p->m_defaultNamespace));
$$->setForPage();
}
| IDENT pseudo_page {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = $2;
if ($$) {
$$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace);
$$->setTag(QualifiedName(nullAtom, $1, p->m_defaultNamespace));
$$->setForPage();
}
}
......@@ -812,7 +812,6 @@ selector_list:
if ($1) {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->reusableSelectorVector();
deleteAllValues(*$$);
$$->shrink(0);
$$->append(p->sinkFloatingSelector($1));
p->updateLastSelectorLineAndPosition();
......@@ -853,10 +852,10 @@ selector:
$$ = 0;
else if ($$) {
CSSParser* p = static_cast<CSSParser*>(parser);
CSSSelector* end = $$;
CSSParserSelector* end = $$;
while (end->tagHistory())
end = end->tagHistory();
end->m_relation = CSSSelector::Descendant;
end->setRelation(CSSSelector::Descendant);
end->setTagHistory(p->sinkFloatingSelector($1));
if (Document* doc = p->document())
doc->setUsesDescendantRules(true);
......@@ -868,10 +867,10 @@ selector:
$$ = 0;
else if ($$) {
CSSParser* p = static_cast<CSSParser*>(parser);
CSSSelector* end = $$;
CSSParserSelector* end = $$;
while (end->tagHistory())
end = end->tagHistory();
end->m_relation = $2;
end->setRelation($2);
end->setTagHistory(p->sinkFloatingSelector($1));
if ($2 == CSSSelector::Child) {
if (Document* doc = p->document())
......@@ -897,7 +896,7 @@ simple_selector:
element_name {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_tag = QualifiedName(nullAtom, $1, p->m_defaultNamespace);
$$->setTag(QualifiedName(nullAtom, $1, p->m_defaultNamespace));
}
| element_name specifier_list {
$$ = $2;
......@@ -914,10 +913,10 @@ simple_selector:
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
if (p->m_styleSheet)
$$->m_tag = QualifiedName(namespacePrefix, $2,
p->m_styleSheet->determineNamespace(namespacePrefix));
$$->setTag(QualifiedName(namespacePrefix, $2,
p->m_styleSheet->determineNamespace(namespacePrefix)));
else // FIXME: Shouldn't this case be an error?
$$->m_tag = QualifiedName(nullAtom, $2, p->m_defaultNamespace);
$$->setTag(QualifiedName(nullAtom, $2, p->m_defaultNamespace));
}
| namespace_selector element_name specifier_list {
$$ = $3;
......@@ -956,8 +955,8 @@ specifier_list:
$$ = 0;
else if ($1) {
CSSParser* p = static_cast<CSSParser*>(parser);
CSSSelector* end;
CSSSelector* history;
CSSParserSelector* end;
CSSParserSelector* history;
// Ensure that unknown pseudo element always stays at the top of selector chain.
if ($2->isUnknownPseudoElement()) {
end = $2;
......@@ -969,7 +968,7 @@ specifier_list:
$$ = end;
while(end->tagHistory())
end = end->tagHistory();
end->m_relation = CSSSelector::SubSelector;
end->setRelation(CSSSelector::SubSelector);
end->setTagHistory(p->sinkFloatingSelector(history));
}
}
......@@ -982,10 +981,10 @@ specifier:
IDSEL {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::Id;
$$->setMatch(CSSSelector::Id);
if (!p->m_strict)
$1.lower();
$$->m_value = $1;
$$->setValue($1);
}
| HEX {
if ($1.characters[0] >= '0' && $1.characters[0] <= '9') {
......@@ -993,10 +992,10 @@ specifier:
} else {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::Id;
$$->setMatch(CSSSelector::Id);
if (!p->m_strict)
$1.lower();
$$->m_value = $1;
$$->setValue($1);
}
}
| class
......@@ -1008,10 +1007,10 @@ class:
'.' IDENT {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::Class;
$$->setMatch(CSSSelector::Class);
if (!p->m_strict)
$2.lower();
$$->m_value = $2;
$$->setValue($2);
}
;
......@@ -1030,13 +1029,13 @@ attrib:
'[' maybe_space attr_name ']' {
$$ = static_cast<CSSParser*>(parser)->createFloatingSelector();
$$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
$$->m_match = CSSSelector::Set;
$$->setMatch(CSSSelector::Set);
}
| '[' maybe_space attr_name match maybe_space ident_or_string maybe_space ']' {
$$ = static_cast<CSSParser*>(parser)->createFloatingSelector();
$$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
$$->m_match = (CSSSelector::Match)$4;
$$->m_value = $6;
$$->setMatch((CSSSelector::Match)$4);
$$->setValue($6);
}
| '[' maybe_space namespace_selector attr_name ']' {
AtomicString namespacePrefix = $3;
......@@ -1044,7 +1043,7 @@ attrib:
$$ = p->createFloatingSelector();
$$->setAttribute(QualifiedName(namespacePrefix, $4,
p->m_styleSheet->determineNamespace(namespacePrefix)));
$$->m_match = CSSSelector::Set;
$$->setMatch(CSSSelector::Set);
}
| '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' {
AtomicString namespacePrefix = $3;
......@@ -1052,8 +1051,8 @@ attrib:
$$ = p->createFloatingSelector();
$$->setAttribute(QualifiedName(namespacePrefix, $4,
p->m_styleSheet->determineNamespace(namespacePrefix)));
$$->m_match = (CSSSelector::Match)$5;
$$->m_value = $7;
$$->setMatch((CSSSelector::Match)$5);
$$->setValue($7);
}
;
......@@ -1086,9 +1085,9 @@ ident_or_string:
pseudo_page:
':' IDENT {
$$ = static_cast<CSSParser*>(parser)->createFloatingSelector();
$$->m_match = CSSSelector::PagePseudoClass;
$$->setMatch(CSSSelector::PagePseudoClass);
$2.lower();
$$->m_value = $2;
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoUnknown)
$$ = 0;
......@@ -1097,9 +1096,9 @@ pseudo_page:
pseudo:
':' IDENT {
$$ = static_cast<CSSParser*>(parser)->createFloatingSelector();
$$->m_match = CSSSelector::PseudoClass;
$$->setMatch(CSSSelector::PseudoClass);
$2.lower();
$$->m_value = $2;
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoUnknown)
$$ = 0;
......@@ -1131,9 +1130,9 @@ pseudo:
}
| ':' ':' IDENT {
$$ = static_cast<CSSParser*>(parser)->createFloatingSelector();
$$->m_match = CSSSelector::PseudoElement;
$$->setMatch(CSSSelector::PseudoElement);
$3.lower();
$$->m_value = $3;
$$->setValue($3);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoFirstLine) {
CSSParser* p = static_cast<CSSParser*>(parser);
......@@ -1150,9 +1149,9 @@ pseudo:
| ':' FUNCTION maybe_space NTH maybe_space ')' {
CSSParser *p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::PseudoClass;
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument($4);
$$->m_value = $2;
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoUnknown)
$$ = 0;
......@@ -1168,9 +1167,9 @@ pseudo:
| ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space ')' {
CSSParser *p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::PseudoClass;
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument(String::number($4 * $5));
$$->m_value = $2;
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoUnknown)
$$ = 0;
......@@ -1186,10 +1185,10 @@ pseudo:
| ':' FUNCTION maybe_space IDENT maybe_space ')' {
CSSParser *p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::PseudoClass;
$$->setMatch(CSSSelector::PseudoClass);
$$->setArgument($4);
$2.lower();
$$->m_value = $2;
$$->setValue($2);
CSSSelector::PseudoType type = $$->pseudoType();
if (type == CSSSelector::PseudoUnknown)
$$ = 0;
......@@ -1211,10 +1210,10 @@ pseudo:
else {
CSSParser* p = static_cast<CSSParser*>(parser);
$$ = p->createFloatingSelector();
$$->m_match = CSSSelector::PseudoClass;
$$->setSimpleSelector(p->sinkFloatingSelector($4));
$$->setMatch(CSSSelector::PseudoClass);
$$->setSimpleSelector(p->sinkFloatingSelector($4)->releaseSelector());
$2.lower();
$$->m_value = $2;
$$->setValue($2);
}
}
;
......
......@@ -27,12 +27,9 @@
namespace WebCore {
CSSPageRule::CSSPageRule(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine)
CSSPageRule::CSSPageRule(CSSStyleSheet* parent, int sourceLine)
: CSSStyleRule(parent, sourceLine)
{
Vector<CSSSelector*> selectors;
selectors.append(selector);
adoptSelectorVector(selectors);
}
CSSPageRule::~CSSPageRule()
......
......@@ -34,9 +34,9 @@ class CSSSelectorList;
class CSSPageRule : public CSSStyleRule {
public:
static PassRefPtr<CSSPageRule> create(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine)
static PassRefPtr<CSSPageRule> create(CSSStyleSheet* parent, int sourceLine)
{
return adoptRef(new CSSPageRule(parent, selector, sourceLine));
return adoptRef(new CSSPageRule(parent, sourceLine));
}
virtual ~CSSPageRule();
......@@ -44,7 +44,7 @@ public:
virtual String selectorText() const;
private:
CSSPageRule(CSSStyleSheet* parent, CSSSelector* selector, int sourceLine);
CSSPageRule(CSSStyleSheet* parent, int sourceLine);
virtual bool isPageRule() { return true; }
......
......@@ -179,7 +179,6 @@ CSSParser::~CSSParser()
fastDeleteAllValues(m_floatingSelectors);
deleteAllValues(m_floatingValueLists);
deleteAllValues(m_floatingFunctions);
deleteAllValues(m_reusableSelectorVector);
}
void CSSParserString::lower()
......@@ -5700,20 +5699,20 @@ void CSSParser::countLines()
}
}
CSSSelector* CSSParser::createFloatingSelector()
CSSParserSelector* CSSParser::createFloatingSelector()
{
CSSSelector* selector = fastNew<CSSSelector>();
CSSParserSelector* selector = new CSSParserSelector;
m_floatingSelectors.add(selector);
return selector;
}
CSSSelector* CSSParser::sinkFloatingSelector(CSSSelector* selector)
PassOwnPtr<CSSParserSelector> CSSParser::sinkFloatingSelector(CSSParserSelector* selector)
{
if (selector) {
ASSERT(m_floatingSelectors.contains(selector));
m_floatingSelectors.remove(selector);
}
return selector;
return adoptPtr(selector);
}
CSSParserValueList* CSSParser::createFloatingValueList()
......@@ -5855,7 +5854,7 @@ WebKitCSSKeyframesRule* CSSParser::createKeyframesRule()
return rulePtr;
}
CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors)
CSSRule* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
{
CSSStyleRule* result = 0;
markRuleBodyEnd();
......@@ -5917,21 +5916,21 @@ void CSSParser::addNamespace(const AtomicString& prefix, const AtomicString& uri
m_styleSheet->addNamespace(this, prefix, uri);
}
void CSSParser::updateSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSSelector* specifiers)
void CSSParser::updateSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector* specifiers)
{
AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
QualifiedName tag = QualifiedName(namespacePrefix, elementName, determinedNamespace);
if (!specifiers->isUnknownPseudoElement()) {
specifiers->m_tag = tag;
specifiers->setTag(tag);
return;
}
if (Document* doc = document())
doc->setUsesDescendantRules(true);
specifiers->m_relation = CSSSelector::ShadowDescendant;
if (CSSSelector* history = specifiers->tagHistory()) {
history->m_tag = tag;
specifiers->setRelation(CSSSelector::ShadowDescendant);
if (CSSParserSelector* history = specifiers->tagHistory()) {
history->setTag(tag);
return;
}
......@@ -5940,19 +5939,22 @@ void CSSParser::updateSpecifiersWithElementName(const AtomicString& namespacePre
if (elementName == starAtom && m_defaultNamespace == starAtom)
return;
CSSSelector* elementNameSelector = fastNew<CSSSelector>();
elementNameSelector->m_tag = tag;
CSSParserSelector* elementNameSelector = new CSSParserSelector;
elementNameSelector->setTag(tag);
specifiers->setTagHistory(elementNameSelector);
}
CSSRule* CSSParser::createPageRule(CSSSelector* pageSelector)
CSSRule* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
{
// FIXME: Margin at-rules are ignored.
m_allowImportRules = m_allowNamespaceDeclarations = false;
CSSPageRule* pageRule = 0;
if (pageSelector) {
RefPtr<CSSPageRule> rule = CSSPageRule::create(m_styleSheet, pageSelector, m_lastSelectorLineNumber);
RefPtr<CSSPageRule> rule = CSSPageRule::create(m_styleSheet, m_lastSelectorLineNumber);
Vector<OwnPtr<CSSParserSelector> > selectorVector;
selectorVector.append(pageSelector);
rule->adoptSelectorVector(selectorVector);
rule->setDeclaration(CSSMutableStyleDeclaration::create(rule.get(), m_parsedProperties, m_numParsedProperties));
pageRule = rule.get();
m_parsedStyleObjects.append(rule.release());
......
......@@ -170,8 +170,8 @@ namespace WebCore {
int yyparse();
CSSSelector* createFloatingSelector();
CSSSelector* sinkFloatingSelector(CSSSelector*);
CSSParserSelector* createFloatingSelector();
PassOwnPtr<CSSParserSelector> sinkFloatingSelector(CSSParserSelector*);
CSSParserValueList* createFloatingValueList();
CSSParserValueList* sinkFloatingValueList(CSSParserValueList*);
......@@ -188,9 +188,9 @@ namespace WebCore {
WebKitCSSKeyframesRule* createKeyframesRule();
CSSRule* createMediaRule(MediaList*, CSSRuleList*);
CSSRuleList* createRuleList();
CSSRule* createStyleRule(Vector<CSSSelector*>* selectors);
CSSRule* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
CSSRule* createFontFaceRule();
CSSRule* createPageRule(CSSSelector* pageSelector);
CSSRule* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
CSSRule* createMarginAtRule(CSSSelector::MarginBoxType marginBox);
void startDeclarationsForMarginBox();
void endDeclarationsForMarginBox();
......@@ -204,11 +204,11 @@ namespace WebCore {
PassOwnPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
void addNamespace(const AtomicString& prefix, const AtomicString& uri);
void updateSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSSelector*);
void updateSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector*);
void invalidBlockHit();
Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; }
Vector<OwnPtr<CSSParserSelector> >* reusableSelectorVector() { return &m_reusableSelectorVector; }
void updateLastSelectorLineAndPosition();
......@@ -302,7 +302,7 @@ namespace WebCore {
Vector<RefPtr<StyleBase> > m_parsedStyleObjects;
Vector<RefPtr<CSSRuleList> > m_parsedRuleLists;
HashSet<CSSSelector*> m_floatingSelectors;
HashSet<CSSParserSelector*> m_floatingSelectors;
HashSet<CSSParserValueList*> m_floatingValueLists;
HashSet<CSSParserFunction*> m_floatingFunctions;
......@@ -310,7 +310,7 @@ namespace WebCore {
OwnPtr<MediaQueryExp> m_floatingMediaQueryExp;
OwnPtr<Vector<OwnPtr<MediaQueryExp> > > m_floatingMediaQueryExpList;
Vector<CSSSelector*> m_reusableSelectorVector;
Vector<OwnPtr<CSSParserSelector> > m_reusableSelectorVector;
// defines units allowed for a certain property, used in parseUnit
enum Units {
......
......@@ -20,11 +20,15 @@
#include "config.h"
#include "CSSParserValues.h"
#include "CSSPrimitiveValue.h"
#include "CSSFunctionValue.h"
#include "CSSQuirkPrimitiveValue.h"
#include "CSSSelector.h"
namespace WebCore {
using namespace WTF;
CSSParserValueList::~CSSParserValueList()
{
......@@ -70,6 +74,27 @@ PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
parsedValue = CSSQuirkPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_EMS);
return parsedValue;
}
CSSParserSelector::CSSParserSelector()
: m_selector(adoptPtr(fastNew<CSSSelector>()))
{
}
CSSParserSelector::~CSSParserSelector()
{
if (!m_tagHistory)
return;
Vector<CSSParserSelector*, 16> toDelete;
CSSParserSelector* selector = m_tagHistory.leakPtr();
while (true) {
toDelete.append(selector);
CSSParserSelector* next = selector->m_tagHistory.leakPtr();
if (!next)
break;
selector = next;
}
deleteAllValues(toDelete);
}
}
......@@ -21,11 +21,13 @@
#ifndef CSSParserValues_h
#define CSSParserValues_h
#include "CSSSelector.h"