diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebCore/css/CSSStyleRule.cpp | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/css/CSSStyleRule.cpp')
-rw-r--r-- | Source/WebCore/css/CSSStyleRule.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/Source/WebCore/css/CSSStyleRule.cpp b/Source/WebCore/css/CSSStyleRule.cpp index bfabe51ed..e0e30d00f 100644 --- a/Source/WebCore/css/CSSStyleRule.cpp +++ b/Source/WebCore/css/CSSStyleRule.cpp @@ -28,8 +28,9 @@ #include "Document.h" #include "PropertySetCSSStyleDeclaration.h" #include "RuleSet.h" -#include "StylePropertySet.h" +#include "StyleProperties.h" #include "StyleRule.h" +#include <wtf/NeverDestroyed.h> #include <wtf/text/StringBuilder.h> namespace WebCore { @@ -37,11 +38,11 @@ namespace WebCore { typedef HashMap<const CSSStyleRule*, String> SelectorTextCache; static SelectorTextCache& selectorTextCache() { - DEFINE_STATIC_LOCAL(SelectorTextCache, cache, ()); + static NeverDestroyed<SelectorTextCache> cache; return cache; } -CSSStyleRule::CSSStyleRule(StyleRule* styleRule, CSSStyleSheet* parent) +CSSStyleRule::CSSStyleRule(StyleRule& styleRule, CSSStyleSheet* parent) : CSSRule(parent) , m_styleRule(styleRule) { @@ -58,23 +59,16 @@ CSSStyleRule::~CSSStyleRule() } } -CSSStyleDeclaration* CSSStyleRule::style() +CSSStyleDeclaration& CSSStyleRule::style() { - if (!m_propertiesCSSOMWrapper) { - m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_styleRule->mutableProperties(), this); - } - return m_propertiesCSSOMWrapper.get(); + if (!m_propertiesCSSOMWrapper) + m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_styleRule->mutableProperties(), *this); + return *m_propertiesCSSOMWrapper; } String CSSStyleRule::generateSelectorText() const { - StringBuilder builder; - for (const CSSSelector* selector = m_styleRule->selectorList().first(); selector; selector = CSSSelectorList::next(selector)) { - if (selector != m_styleRule->selectorList().first()) - builder.appendLiteral(", "); - builder.append(selector->selectorText()); - } - return builder.toString(); + return m_styleRule->selectorList().selectorsText(); } String CSSStyleRule::selectorText() const @@ -93,6 +87,11 @@ String CSSStyleRule::selectorText() const void CSSStyleRule::setSelectorText(const String& selectorText) { + // FIXME: getMatchedCSSRules can return CSSStyleRules that are missing parent stylesheet pointer while + // referencing StyleRules that are part of stylesheet. Disallow mutations in this case. + if (!parentStyleSheet()) + return; + CSSParser p(parserContext()); CSSSelectorList selectorList; p.parseSelector(selectorText, selectorList); @@ -118,7 +117,7 @@ String CSSStyleRule::cssText() const StringBuilder result; result.append(selectorText()); result.appendLiteral(" { "); - String decls = m_styleRule->properties()->asText(); + String decls = m_styleRule->properties().asText(); result.append(decls); if (!decls.isEmpty()) result.append(' '); @@ -126,11 +125,9 @@ String CSSStyleRule::cssText() const return result.toString(); } -void CSSStyleRule::reattach(StyleRuleBase* rule) +void CSSStyleRule::reattach(StyleRuleBase& rule) { - ASSERT(rule); - ASSERT_WITH_SECURITY_IMPLICATION(rule->isStyleRule()); - m_styleRule = static_cast<StyleRule*>(rule); + m_styleRule = downcast<StyleRule>(rule); if (m_propertiesCSSOMWrapper) m_propertiesCSSOMWrapper->reattach(m_styleRule->mutableProperties()); } |