Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: Source/core/css/StyleSheetContents.cpp

Issue 1321943002: Support for CSSOM CSSNamespaceRule interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per review comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/StyleSheetContents.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/StyleSheetContents.cpp
diff --git a/Source/core/css/StyleSheetContents.cpp b/Source/core/css/StyleSheetContents.cpp
index 5c7304253063c8bdda010bf1297a5f51fe3003cf..c974948ee5ef4a48160d7a8521be645d509142a3 100644
--- a/Source/core/css/StyleSheetContents.cpp
+++ b/Source/core/css/StyleSheetContents.cpp
@@ -76,6 +76,7 @@ StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
: m_ownerRule(nullptr)
, m_originalURL(o.m_originalURL)
, m_importRules(o.m_importRules.size())
+ , m_namespaceRules(o.m_namespaceRules.size())
, m_childRules(o.m_childRules.size())
, m_namespaces(o.m_namespaces)
, m_defaultNamespace(o.m_defaultNamespace)
@@ -158,10 +159,12 @@ void StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
}
if (rule->isNamespaceRule()) {
- // Parser enforces that @namespace rules come before anything else
+ // Parser enforces that @namespace rules come before all rules other than
+ // import/charset rules
ASSERT(m_childRules.isEmpty());
StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule);
parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
+ m_namespaceRules.append(&namespaceRule);
return;
}
@@ -186,12 +189,18 @@ StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const
return m_importRules[index].get();
index -= m_importRules.size();
+
+ if (index < m_namespaceRules.size())
+ return m_namespaceRules[index].get();
+
+ index -= m_namespaceRules.size();
+
return m_childRules[index].get();
}
unsigned StyleSheetContents::ruleCount() const
{
- return m_importRules.size() + m_childRules.size();
+ return m_importRules.size() + m_namespaceRules.size() + m_childRules.size();
}
void StyleSheetContents::clearRules()
@@ -201,6 +210,7 @@ void StyleSheetContents::clearRules()
m_importRules[i]->clearParentStyleSheet();
}
m_importRules.clear();
+ m_namespaceRules.clear();
m_childRules.clear();
}
@@ -233,13 +243,37 @@ bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase>
index -= m_importRules.size();
+ if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) {
+ // Inserting non-namespace rules other than import rule before @namespace is not allowed.
+ if (!rule->isNamespaceRule())
+ return false;
+ // Inserting @namespace rule when rules other than import/namespace/charset are present is not allowed.
+ if (!m_childRules.isEmpty())
+ return false;
+
+ StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get());
+ m_namespaceRules.insert(index, namespaceRule);
+ // For now to be compatible with IE and Firefox if namespace rule with same prefix is added
+ // irrespective of adding the rule at any index, last added rule's value is considered.
+ // TODO (ramya.v@samsung.com): As per spec last valid rule should be considered,
+ // which means if namespace rule is added in the middle of existing namespace rules,
+ // rule which comes later in rule list with same prefix needs to be considered.
+ parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri());
+ return true;
+ }
+
+ if (rule->isNamespaceRule())
+ return false;
+
+ index -= m_namespaceRules.size();
+
if (rule->isFontFaceRule())
setHasFontFaceRule(true);
m_childRules.insert(index, rule);
return true;
}
-void StyleSheetContents::wrapperDeleteRule(unsigned index)
+bool StyleSheetContents::wrapperDeleteRule(unsigned index)
{
ASSERT(m_isMutable);
ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount());
@@ -249,13 +283,22 @@ void StyleSheetContents::wrapperDeleteRule(unsigned index)
if (m_importRules[index]->isFontFaceRule())
notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].get()));
m_importRules.remove(index);
- return;
+ return true;
}
index -= m_importRules.size();
+ if (index < m_namespaceRules.size()) {
+ if (!m_childRules.isEmpty())
+ return false;
+ m_namespaceRules.remove(index);
+ return true;
+ }
+ index -= m_namespaceRules.size();
+
if (m_childRules[index]->isFontFaceRule())
notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get()));
m_childRules.remove(index);
+ return true;
}
void StyleSheetContents::parserAddNamespace(const AtomicString& prefix, const AtomicString& uri)
@@ -631,6 +674,7 @@ DEFINE_TRACE(StyleSheetContents)
#if ENABLE(OILPAN)
visitor->trace(m_ownerRule);
visitor->trace(m_importRules);
+ visitor->trace(m_namespaceRules);
visitor->trace(m_childRules);
visitor->trace(m_loadingClients);
visitor->trace(m_completedClients);
« no previous file with comments | « Source/core/css/StyleSheetContents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698