Ignore:
Timestamp:
Sep 11, 2013, 9:48:20 AM (12 years ago)
Author:
Darin Adler
Message:

Rework CSS parser, eliminating "floating" concept and using %destructor
https://bugs.webkit.org/show_bug.cgi?id=121161

Reviewed by Antti Koivisto.

This is some basic improvement, but there is still room for a lot more
consistent approach and formatting in this file. There is a mix of code that
works by side effects in the CSSParser class and code that works with the
values that bison generates in the union that is more or less random. And
the data structures seem too costly, with too much heap allocation. And the
CSSParser class has grown massive, with a mix of both function for use by
code that wants to trigger parsing, and helper functions called by code in
the grammar file. All of that can benefit from more refinement in the future.

  • css/CSSGrammar.y.in: Made some incremental improvements to the structure

of the grammar file, including:

  • Breaking up the %union so types are declared next to their use
  • Eliminating one shift/reduce conflict caused by two "maybe_space" in a row
  • Breaking the conditional sections out into their own sections instead of scattering them in with the other code.
  • Eliminating unused return values in productions such as charset, ignored_charset, namespace, margin_box, invalid_rule, save_block, invalid_at, and declarations_and_margins.
  • Adding %destructor to productions that return values that need to be deleted or deref'd. This removes the need for CSSParser to separately track these as "floating" to clean up in case of errors.
  • Removing unneeded productions such as media_feature, region_selector, attr_name, and medium.
  • Removing explicit code blocks that just say "$$ = $1" or empty blocks when there is no return type, since those are default.
  • Formatting many productions on single lines since I find them easier to read. Later I think we could make many more CSSParser functions and make even more of the production single lines in the grammar file.
  • Using adoptPtr, adoptRef, delete, deref, leakPtr, and leakRef to put heap allocated values into and out of the union without storage leaks.
  • css/CSSParser.cpp:

(WebCore::CSSParser::~CSSParser): Remove the now-unneeded deleteAllValues for
the various colections of floating things.
(WebCore::CSSParser::createFilterRule): Don't put the rule into m_parsedRules,
just return a PassRefPtr instead.
(WebCore::CSSParser::createImportRule): Ditto.
(WebCore::CSSParser::createMediaRule): Ditto.
(WebCore::CSSParser::createEmptyMediaRule): Ditto.
(WebCore::CSSParser::createSupportsRule): Ditto.
(WebCore::CSSParser::createKeyframesRule): Ditto.
(WebCore::CSSParser::createStyleRule): Ditto.
(WebCore::CSSParser::createFontFaceRule): Ditto.
(WebCore::CSSParser::createHostRule): Ditto.
(WebCore::CSSParser::rewriteSpecifiersWithNamespaceIfNeeded): Got rid of the
unused return value from this function and changed it to to take a reference
instead of a pointer.
(WebCore::CSSParser::rewriteSpecifiersWithElementName): Ditto.
(WebCore::CSSParser::rewriteSpecifiers): Changed this to take and return OwnPtr.
(WebCore::CSSParser::createPageRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.
(WebCore::CSSParser::createSelectorVector): Added. Used to implement the
optimization where we recycle a single selector vector. Not sure we still need
this, or maybe we need more optimizations like it, but for now keep it.
(WebCore::CSSParser::recycleSelectorVector): Ditto.
(WebCore::CSSParser::createRegionRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.
(WebCore::CSSParser::createMarginAtRule): Got rid of unused return value.
When this function is implemented for real, we might add a return value.
(WebCore::CSSParser::createKeyframe): Don't put keyframe into m_parsedKeyframes,
return PassRefPtr instead.
(WebCore::CSSParser::createViewportRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.

  • css/CSSParser.h: Removed many now-needed functions to manage floating items.

Changed rule creation functions to return PassRefPtr. Other changes as mentioned above.

  • css/CSSParserValues.cpp:

(WebCore::destroy): Added.
(WebCore::CSSParserValueList::~CSSParserValueList): Updated to call destroy.

  • css/CSSParserValues.h: Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSParser.cpp

    r155496 r155536  
    358358{
    359359    clearProperties();
    360 
    361     deleteAllValues(m_floatingSelectors);
    362     deleteAllValues(m_floatingSelectorVectors);
    363     deleteAllValues(m_floatingValueLists);
    364     deleteAllValues(m_floatingFunctions);
    365360}
    366361
     
    523518#if ENABLE(CSS3_TEXT)
    524519    case CSSPropertyWebkitTextDecorationColor:
    525 #endif // CSS3_TEXT
     520#endif
    526521    case CSSPropertyWebkitTextEmphasisColor:
    527522    case CSSPropertyWebkitTextFillColor:
     
    92389233}
    92399234
    9240 StyleRuleBase* CSSParser::createFilterRule(const CSSParserString& filterName)
     9235PassRefPtr<StyleRuleBase> CSSParser::createFilterRule(const CSSParserString& filterName)
    92419236{
    92429237    RefPtr<StyleRuleFilter> rule = StyleRuleFilter::create(filterName, createStylePropertySet());
    92439238    clearProperties();
    9244     StyleRuleFilter* result = rule.get();
    9245     m_parsedRules.append(rule.release());
    92469239    processAndAddNewRuleToSourceTreeIfNeeded();
    9247     return result;
     9240    return rule.release();
    92489241}
    92499242
     
    1146511458}
    1146611459
    11467 CSSParserSelector* CSSParser::createFloatingSelectorWithTagName(const QualifiedName& tagQName)
    11468 {
    11469     CSSParserSelector* selector = new CSSParserSelector(tagQName);
    11470     m_floatingSelectors.add(selector);
    11471     return selector;
    11472 }
    11473 
    11474 CSSParserSelector* CSSParser::createFloatingSelector()
    11475 {
    11476     CSSParserSelector* selector = new CSSParserSelector;
    11477     m_floatingSelectors.add(selector);
    11478     return selector;
    11479 }
    11480 
    11481 PassOwnPtr<CSSParserSelector> CSSParser::sinkFloatingSelector(CSSParserSelector* selector)
    11482 {
    11483     if (selector) {
    11484         ASSERT(m_floatingSelectors.contains(selector));
    11485         m_floatingSelectors.remove(selector);
    11486     }
    11487     return adoptPtr(selector);
    11488 }
    11489 
    11490 Vector<OwnPtr<CSSParserSelector> >* CSSParser::createFloatingSelectorVector()
    11491 {
    11492     Vector<OwnPtr<CSSParserSelector> >* selectorVector = new Vector<OwnPtr<CSSParserSelector> >;
    11493     m_floatingSelectorVectors.add(selectorVector);
    11494     return selectorVector;
    11495 }
    11496 
    11497 PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > CSSParser::sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectorVector)
    11498 {
    11499     if (selectorVector) {
    11500         ASSERT(m_floatingSelectorVectors.contains(selectorVector));
    11501         m_floatingSelectorVectors.remove(selectorVector);
    11502     }
    11503     return adoptPtr(selectorVector);
    11504 }
    11505 
    11506 CSSParserValueList* CSSParser::createFloatingValueList()
    11507 {
    11508     CSSParserValueList* list = new CSSParserValueList;
    11509     m_floatingValueLists.add(list);
    11510     return list;
    11511 }
    11512 
    11513 PassOwnPtr<CSSParserValueList> CSSParser::sinkFloatingValueList(CSSParserValueList* list)
    11514 {
    11515     if (list) {
    11516         ASSERT(m_floatingValueLists.contains(list));
    11517         m_floatingValueLists.remove(list);
    11518     }
    11519     return adoptPtr(list);
    11520 }
    11521 
    11522 CSSParserFunction* CSSParser::createFloatingFunction()
    11523 {
    11524     CSSParserFunction* function = new CSSParserFunction;
    11525     m_floatingFunctions.add(function);
    11526     return function;
    11527 }
    11528 
    11529 PassOwnPtr<CSSParserFunction> CSSParser::sinkFloatingFunction(CSSParserFunction* function)
    11530 {
    11531     if (function) {
    11532         ASSERT(m_floatingFunctions.contains(function));
    11533         m_floatingFunctions.remove(function);
    11534     }
    11535     return adoptPtr(function);
    11536 }
    11537 
    11538 CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value)
    11539 {
    11540     if (value.unit == CSSParserValue::Function) {
    11541         ASSERT(m_floatingFunctions.contains(value.function));
    11542         m_floatingFunctions.remove(value.function);
    11543     }
    11544     return value;
    11545 }
    11546 
    11547 MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values)
    11548 {
    11549     m_floatingMediaQueryExp = MediaQueryExp::create(mediaFeature, values);
    11550     return m_floatingMediaQueryExp.get();
    11551 }
    11552 
    11553 PassOwnPtr<MediaQueryExp> CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* expression)
    11554 {
    11555     ASSERT_UNUSED(expression, expression == m_floatingMediaQueryExp);
    11556     return m_floatingMediaQueryExp.release();
    11557 }
    11558 
    11559 Vector<OwnPtr<MediaQueryExp> >* CSSParser::createFloatingMediaQueryExpList()
    11560 {
    11561     m_floatingMediaQueryExpList = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
    11562     return m_floatingMediaQueryExpList.get();
    11563 }
    11564 
    11565 PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > CSSParser::sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >* list)
    11566 {
    11567     ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList);
    11568     return m_floatingMediaQueryExpList.release();
    11569 }
    11570 
    11571 MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
    11572 {
    11573     m_floatingMediaQuery = adoptPtr(new MediaQuery(restrictor, mediaType, expressions));
    11574     return m_floatingMediaQuery.get();
    11575 }
    11576 
    11577 MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
    11578 {
    11579     return createFloatingMediaQuery(MediaQuery::None, "all", expressions);
    11580 }
    11581 
    11582 PassOwnPtr<MediaQuery> CSSParser::sinkFloatingMediaQuery(MediaQuery* query)
    11583 {
    11584     ASSERT_UNUSED(query, query == m_floatingMediaQuery);
    11585     return m_floatingMediaQuery.release();
    11586 }
    11587 
    11588 Vector<RefPtr<StyleKeyframe> >* CSSParser::createFloatingKeyframeVector()
    11589 {
    11590     m_floatingKeyframeVector = adoptPtr(new Vector<RefPtr<StyleKeyframe> >());
    11591     return m_floatingKeyframeVector.get();
    11592 }
    11593 
    11594 PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > CSSParser::sinkFloatingKeyframeVector(Vector<RefPtr<StyleKeyframe> >* keyframeVector)
    11595 {
    11596     ASSERT_UNUSED(keyframeVector, m_floatingKeyframeVector == keyframeVector);
    11597     return m_floatingKeyframeVector.release();
    11598 }
    11599 
    11600 MediaQuerySet* CSSParser::createMediaQuerySet()
    11601 {
    11602     RefPtr<MediaQuerySet> queries = MediaQuerySet::create();
    11603     MediaQuerySet* result = queries.get();
    11604     m_parsedMediaQuerySets.append(queries.release());
    11605     return result;
    11606 }
    11607 
    11608 StyleRuleBase* CSSParser::createImportRule(const CSSParserString& url, MediaQuerySet* media)
     11460PassRefPtr<StyleRuleBase> CSSParser::createImportRule(const CSSParserString& url, PassRefPtr<MediaQuerySet> media)
    1160911461{
    1161011462    if (!media || !m_allowImportRules) {
     
    1161311465    }
    1161411466    RefPtr<StyleRuleImport> rule = StyleRuleImport::create(url, media);
    11615     StyleRuleImport* result = rule.get();
    11616     m_parsedRules.append(rule.release());
    1161711467    processAndAddNewRuleToSourceTreeIfNeeded();
    11618     return result;
    11619 }
    11620 
    11621 StyleRuleBase* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules)
     11468    return rule.release();
     11469}
     11470
     11471PassRefPtr<StyleRuleBase> CSSParser::createMediaRule(PassRefPtr<MediaQuerySet> media, RuleList* rules)
    1162211472{
    1162311473    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1163011480    } else
    1163111481        rule = StyleRuleMedia::create(media, rules ? *rules : emptyRules);
    11632     StyleRuleMedia* result = rule.get();
    11633     m_parsedRules.append(rule.release());
    1163411482    processAndAddNewRuleToSourceTreeIfNeeded();
    11635     return result;
    11636 }
    11637 
    11638 StyleRuleBase* CSSParser::createEmptyMediaRule(RuleList* rules)
    11639 {
    11640     return createMediaRule(MediaQuerySet::create().get(), rules);
     11483    return rule.release();
     11484}
     11485
     11486PassRefPtr<StyleRuleBase> CSSParser::createEmptyMediaRule(RuleList* rules)
     11487{
     11488    return createMediaRule(MediaQuerySet::create(), rules);
    1164111489}
    1164211490
    1164311491#if ENABLE(CSS3_CONDITIONAL_RULES)
    11644 StyleRuleBase* CSSParser::createSupportsRule(bool conditionIsSupported, RuleList* rules)
     11492PassRefPtr<StyleRuleBase> CSSParser::createSupportsRule(bool conditionIsSupported, RuleList* rules)
    1164511493{
    1164611494    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1166411512    }
    1166511513
    11666     StyleRuleSupports* result = rule.get();
    11667     m_parsedRules.append(rule.release());
    1166811514    processAndAddNewRuleToSourceTreeIfNeeded();
    1166911515
    11670     return result;
     11516    return rule.release();
    1167111517}
    1167211518
     
    1170011546
    1170111547#endif
    11702 
    11703 CSSParser::RuleList* CSSParser::createRuleList()
    11704 {
    11705     OwnPtr<RuleList> list = adoptPtr(new RuleList);
    11706     RuleList* listPtr = list.get();
    11707 
    11708     m_parsedRuleLists.append(list.release());
    11709     return listPtr;
    11710 }
    1171111548
    1171211549void CSSParser::processAndAddNewRuleToSourceTreeIfNeeded()
     
    1177411611void CSSParser::logError(const String& message, int lineNumber)
    1177511612{
    11776     // FIXME: <http://webkit.org/b/114313> CSS Parser ConsoleMessage errors should include column numbers
     11613    // FIXME: <http://webkit.org/b/114313> CSS parser console message errors should include column numbers.
    1177711614    PageConsole& console = m_styleSheet->singleOwnerDocument()->page()->console();
    1177811615    console.addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleSheet->baseURL().string(), lineNumber + 1, 0);
    1177911616}
    1178011617
    11781 StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > popKeyframes)
    11782 {
    11783     OwnPtr<Vector<RefPtr<StyleKeyframe> > > keyframes = popKeyframes;
     11618PassRefPtr<StyleRuleKeyframes> CSSParser::createKeyframesRule(const String& name, PassOwnPtr<Vector<RefPtr<StyleKeyframe>>> popKeyframes)
     11619{
     11620    OwnPtr<Vector<RefPtr<StyleKeyframe>>> keyframes = popKeyframes;
    1178411621    m_allowImportRules = m_allowNamespaceDeclarations = false;
    1178511622    RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create();
     
    1178711624        rule->parserAppendKeyframe(keyframes->at(i));
    1178811625    rule->setName(name);
    11789     StyleRuleKeyframes* rulePtr = rule.get();
    11790     m_parsedRules.append(rule.release());
    1179111626    processAndAddNewRuleToSourceTreeIfNeeded();
    11792     return rulePtr;
    11793 }
    11794 
    11795 StyleRuleBase* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
    11796 {
    11797     StyleRule* result = 0;
     11627    return rule.release();
     11628}
     11629
     11630PassRefPtr<StyleRuleBase> CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector>>* selectors)
     11631{
     11632    RefPtr<StyleRule> rule;
    1179811633    if (selectors) {
    1179911634        m_allowImportRules = false;
     
    1180111636        if (m_hasFontFaceOnlyValues)
    1180211637            deleteFontFaceOnlyValues();
    11803         RefPtr<StyleRule> rule = StyleRule::create(m_lastSelectorLineNumber, createStylePropertySet());
     11638        rule = StyleRule::create(m_lastSelectorLineNumber, createStylePropertySet());
    1180411639        rule->parserAdoptSelectorVector(*selectors);
    11805         result = rule.get();
    11806         m_parsedRules.append(rule.release());
    1180711640        processAndAddNewRuleToSourceTreeIfNeeded();
    1180811641    } else
    1180911642        popRuleData();
    1181011643    clearProperties();
    11811     return result;
    11812 }
    11813 
    11814 StyleRuleBase* CSSParser::createFontFaceRule()
     11644    return rule.release();
     11645}
     11646
     11647PassRefPtr<StyleRuleBase> CSSParser::createFontFaceRule()
    1181511648{
    1181611649    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1183111664    RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create(createStylePropertySet());
    1183211665    clearProperties();
    11833     StyleRuleFontFace* result = rule.get();
    11834     m_parsedRules.append(rule.release());
    1183511666    processAndAddNewRuleToSourceTreeIfNeeded();
    11836     return result;
     11667    return rule.release();
    1183711668}
    1183811669
    1183911670#if ENABLE(SHADOW_DOM)
    11840 StyleRuleBase* CSSParser::createHostRule(RuleList* rules)
     11671PassRefPtr<StyleRuleBase> CSSParser::createHostRule(RuleList* rules)
    1184111672{
    1184211673    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1184811679        rule = StyleRuleHost::create(emptyRules);
    1184911680    }
    11850     StyleRuleHost* result = rule.get();
    11851     m_parsedRules.append(rule.release());
    1185211681    processAndAddNewRuleToSourceTreeIfNeeded();
    11853     return result;
     11682    return rule.release();
    1185411683}
    1185511684#endif
     
    1187211701}
    1187311702
    11874 CSSParserSelector* CSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector* specifiers)
    11875 {
    11876     if (m_defaultNamespace != starAtom || specifiers->isCustomPseudoElement())
    11877         return rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers, /*tagIsForNamespaceRule*/true);
    11878     return specifiers;
    11879 }
    11880 
    11881 CSSParserSelector* CSSParser::rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule)
     11703void CSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector& specifiers)
     11704{
     11705    if (m_defaultNamespace != starAtom || specifiers.isCustomPseudoElement())
     11706        rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers, /*tagIsForNamespaceRule*/true);
     11707}
     11708
     11709void CSSParser::rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector& specifiers, bool tagIsForNamespaceRule)
    1188211710{
    1188311711    AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
    1188411712    QualifiedName tag(namespacePrefix, elementName, determinedNamespace);
    1188511713
    11886     if (!specifiers->isCustomPseudoElement()) {
     11714    if (!specifiers.isCustomPseudoElement()) {
    1188711715        if (tag == anyQName())
    11888             return specifiers;
     11716            return;
    1188911717#if ENABLE(VIDEO_TRACK)
    11890         if (!(specifiers->pseudoType() == CSSSelector::PseudoCue))
     11718        if (specifiers.pseudoType() != CSSSelector::PseudoCue)
    1189111719#endif
    11892             specifiers->prependTagSelector(tag, tagIsForNamespaceRule);
    11893         return specifiers;
    11894     }
    11895 
    11896     CSSParserSelector* lastShadowDescendant = specifiers;
    11897     CSSParserSelector* history = specifiers;
     11720            specifiers.prependTagSelector(tag, tagIsForNamespaceRule);
     11721        return;
     11722    }
     11723
     11724    CSSParserSelector* lastShadowDescendant = &specifiers;
     11725    CSSParserSelector* history = &specifiers;
    1189811726    while (history->tagHistory()) {
    1189911727        history = history->tagHistory();
     
    1190511733        if (tag != anyQName())
    1190611734            lastShadowDescendant->tagHistory()->prependTagSelector(tag, tagIsForNamespaceRule);
    11907         return specifiers;
     11735        return;
    1190811736    }
    1190911737
    1191011738    // For shadow-ID pseudo-elements to be correctly matched, the ShadowDescendant combinator has to be used.
    1191111739    // We therefore create a new Selector with that combinator here in any case, even if matching any (host) element in any namespace (i.e. '*').
    11912     OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelector(tag));
    11913     lastShadowDescendant->setTagHistory(elementNameSelector.release());
     11740    lastShadowDescendant->setTagHistory(adoptPtr(new CSSParserSelector(tag)));
    1191411741    lastShadowDescendant->setRelation(CSSSelector::ShadowDescendant);
    11915     return specifiers;
    11916 }
    11917 
    11918 CSSParserSelector* CSSParser::rewriteSpecifiers(CSSParserSelector* specifiers, CSSParserSelector* newSpecifier)
     11742}
     11743
     11744OwnPtr<CSSParserSelector> CSSParser::rewriteSpecifiers(OwnPtr<CSSParserSelector> specifiers, OwnPtr<CSSParserSelector> newSpecifier)
    1191911745{
    1192011746#if ENABLE(VIDEO_TRACK)
     
    1192411750#endif
    1192511751        // Unknown pseudo element always goes at the top of selector chain.
    11926         newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, sinkFloatingSelector(specifiers));
     11752        newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, specifiers.release());
    1192711753        return newSpecifier;
    1192811754    }
    1192911755    if (specifiers->isCustomPseudoElement()) {
    1193011756        // Specifiers for unknown pseudo element go right behind it in the chain.
    11931         specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::ShadowDescendant);
     11757        specifiers->insertTagHistory(CSSSelector::SubSelector, newSpecifier.release(), CSSSelector::ShadowDescendant);
    1193211758        return specifiers;
    1193311759    }
    11934     specifiers->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier));
     11760    specifiers->appendTagHistory(CSSSelector::SubSelector, newSpecifier.release());
    1193511761    return specifiers;
    1193611762}
    1193711763
    11938 StyleRuleBase* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
     11764PassRefPtr<StyleRuleBase> CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
    1193911765{
    1194011766    // FIXME: Margin at-rules are ignored.
    1194111767    m_allowImportRules = m_allowNamespaceDeclarations = false;
    11942     StyleRulePage* pageRule = 0;
     11768    RefPtr<StyleRulePage> rule;
    1194311769    if (pageSelector) {
    11944         RefPtr<StyleRulePage> rule = StyleRulePage::create(createStylePropertySet());
    11945         Vector<OwnPtr<CSSParserSelector> > selectorVector;
     11770        rule = StyleRulePage::create(createStylePropertySet());
     11771        Vector<OwnPtr<CSSParserSelector>> selectorVector;
    1194611772        selectorVector.append(pageSelector);
    1194711773        rule->parserAdoptSelectorVector(selectorVector);
    11948         pageRule = rule.get();
    11949         m_parsedRules.append(rule.release());
    1195011774        processAndAddNewRuleToSourceTreeIfNeeded();
    1195111775    } else
    1195211776        popRuleData();
    1195311777    clearProperties();
    11954     return pageRule;
    11955 }
    11956 
    11957 void CSSParser::setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectors)
    11958 {
    11959     if (selectors)
    11960         m_reusableRegionSelectorVector.swap(*selectors);
    11961 }
    11962 
    11963 StyleRuleBase* CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules)
     11778    return rule.release();
     11779}
     11780
     11781OwnPtr<Vector<OwnPtr<CSSParserSelector>>> CSSParser::createSelectorVector()
     11782{
     11783    if (m_recycledSelectorVector) {
     11784        m_recycledSelectorVector->shrink(0);
     11785        return std::move(m_recycledSelectorVector);
     11786    }
     11787    return adoptPtr(new Vector<OwnPtr<CSSParserSelector>>);
     11788}
     11789
     11790void CSSParser::recycleSelectorVector(OwnPtr<Vector<OwnPtr<CSSParserSelector>>> vector)
     11791{
     11792    if (vector && !m_recycledSelectorVector)
     11793        m_recycledSelectorVector = std::move(vector);
     11794}
     11795
     11796PassRefPtr<StyleRuleBase> CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector>>* regionSelector, RuleList* rules)
    1196411797{
    1196511798    if (!cssRegionsEnabled() || !regionSelector || !rules) {
     
    1197211805    RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(regionSelector, *rules);
    1197311806
    11974     StyleRuleRegion* result = regionRule.get();
    11975     m_parsedRules.append(regionRule.release());
    1197611807    if (isExtractingSourceData())
    1197711808        addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
    1197811809
    11979     return result;
    11980 }
    11981 
    11982 StyleRuleBase* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
     11810    return regionRule.release();
     11811}
     11812
     11813void CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
    1198311814{
    1198411815    // FIXME: Implement margin at-rule here, using:
     
    1198811819
    1198911820    endDeclarationsForMarginBox();
    11990     return 0; // until this method is implemented.
    1199111821}
    1199211822
     
    1201511845}
    1201611846
    12017 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
     11847PassRefPtr<StyleKeyframe> CSSParser::createKeyframe(CSSParserValueList& keys)
    1201811848{
    1201911849    // Create a key string from the passed keys
    1202011850    StringBuilder keyString;
    12021     for (unsigned i = 0; i < keys->size(); ++i) {
     11851    for (unsigned i = 0; i < keys.size(); ++i) {
    1202211852        // Just as per the comment below, we ignore keyframes with
    1202311853        // invalid key values (plain numbers or unknown identifiers)
    1202411854        // marked as CSSPrimitiveValue::CSS_UNKNOWN during parsing.
    12025         if (keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_UNKNOWN) {
     11855        if (keys.valueAt(i)->unit == CSSPrimitiveValue::CSS_UNKNOWN) {
    1202611856            clearProperties();
    1202711857            return 0;
    1202811858        }
    1202911859
    12030         ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
    12031         float key = static_cast<float>(keys->valueAt(i)->fValue);
     11860        ASSERT(keys.valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
     11861        float key = static_cast<float>(keys.valueAt(i)->fValue);
    1203211862        if (key < 0 || key > 100) {
    1203311863            // As per http://www.w3.org/TR/css3-animations/#keyframes,
     
    1204811878    clearProperties();
    1204911879
    12050     StyleKeyframe* keyframePtr = keyframe.get();
    12051     m_parsedKeyframes.append(keyframe.release());
    12052     return keyframePtr;
     11880    return keyframe.release();
    1205311881}
    1205411882
     
    1225812086
    1225912087#if ENABLE(CSS_DEVICE_ADAPTATION)
    12260 StyleRuleBase* CSSParser::createViewportRule()
     12088PassRefPtr<StyleRuleBase> CSSParser::createViewportRule()
    1226112089{
    1226212090    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1226512093    clearProperties();
    1226612094
    12267     StyleRuleViewport* result = rule.get();
    12268     m_parsedRules.append(rule.release());
    1226912095    processAndAddNewRuleToSourceTreeIfNeeded();
    1227012096
    12271     return result;
     12097    return rule.release();
    1227212098}
    1227312099
Note: See TracChangeset for help on using the changeset viewer.