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

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 8769973ac24db5e64a08a10153db03957ce0627b..4f240e9e00879ce63d095ec90c5b5929586f6245 100644
--- a/Source/core/css/StyleSheetContents.cpp
+++ b/Source/core/css/StyleSheetContents.cpp
@@ -75,6 +75,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_hasSyntacticallyValidCSSHeader(o.m_hasSyntacticallyValidCSSHeader)
@@ -156,10 +157,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/namespace/charset rules
Timothy Loh 2015/09/04 01:35:50 not sure you want to write namespace here
ramya.v 2015/09/07 09:06:28 Done.
ASSERT(m_childRules.isEmpty());
StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule);
parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
+ m_namespaceRules.append(&namespaceRule);
return;
}
@@ -184,12 +187,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()
@@ -199,6 +208,7 @@ void StyleSheetContents::clearRules()
m_importRules[i]->clearParentStyleSheet();
}
m_importRules.clear();
+ m_namespaceRules.clear();
m_childRules.clear();
}
@@ -231,13 +241,32 @@ 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.size() > 0)
+ return false;
+
+ StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule.get());
+ m_namespaceRules.insert(index, namespaceRule);
+ parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri());
Timothy Loh 2015/09/04 01:35:50 parserAddNamespace won't do what you want here. If
ramya.v 2015/09/07 05:28:23 Hi Tim just one doubt. As per spec it was given If
+ 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());
@@ -247,13 +276,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.size() > 0)
Timothy Loh 2015/09/04 01:35:50 !m_childRules.isEmpty() probably reads better
ramya.v 2015/09/07 09:06:28 Done.
+ 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)
@@ -624,6 +662,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