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

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

Issue 21006006: Add forEach() to CSSVariablesMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and review changes Created 7 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/CSSVariablesMap.h ('k') | Source/core/css/CSSVariablesMap.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSVariablesMap.cpp
diff --git a/Source/core/css/CSSVariablesMap.cpp b/Source/core/css/CSSVariablesMap.cpp
index 599a9dca63968fd571a71c0b2611833ad770ba76..48e67ebca7ec01f03a423b9f3dfdc3b5ce234ef0 100644
--- a/Source/core/css/CSSVariablesMap.cpp
+++ b/Source/core/css/CSSVariablesMap.cpp
@@ -55,23 +55,68 @@ bool CSSVariablesMap::has(const AtomicString& name) const
return false;
}
-void CSSVariablesMap::set(const AtomicString& name, const String& value, ExceptionState& es) const
+void CSSVariablesMap::set(const AtomicString& name, const String& value, ExceptionState& es)
{
- if (m_styleDeclaration)
- m_styleDeclaration->setVariableValue(name, value, es);
+ if (!m_styleDeclaration)
+ return;
+ if (m_styleDeclaration->setVariableValue(name, value, es)) {
+ Iterators::iterator end = m_activeIterators.end();
+ for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it)
+ (*it)->addedVariable(name);
+ }
}
-bool CSSVariablesMap::remove(const AtomicString& name) const
+bool CSSVariablesMap::remove(const AtomicString& name)
{
- if (m_styleDeclaration)
- return m_styleDeclaration->removeVariable(name);
+ if (!m_styleDeclaration)
+ return false;
+ if (m_styleDeclaration->removeVariable(name)) {
+ Iterators::iterator end = m_activeIterators.end();
+ for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it)
+ (*it)->removedVariable(name);
+ return true;
+ }
return false;
}
-void CSSVariablesMap::clear(ExceptionState& es) const
+void CSSVariablesMap::clear(ExceptionState& es)
{
- if (m_styleDeclaration)
- return m_styleDeclaration->clearVariables(es);
+ if (!m_styleDeclaration)
+ return;
+ if (m_styleDeclaration->clearVariables(es)) {
+ Iterators::iterator end = m_activeIterators.end();
+ for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it)
+ (*it)->clearedVariables();
+ }
+}
+
+void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callback, ScriptValue& thisArg) const
+{
+ forEach(callback, &thisArg);
+}
+
+void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callback) const
+{
+ forEach(callback, 0);
+}
+
+void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callback, ScriptValue* thisArg) const
+{
+ if (!m_styleDeclaration)
+ return;
+ RefPtr<CSSVariablesIterator> iterator = m_styleDeclaration->variablesIterator();
+ m_activeIterators.append(iterator.get());
+ while (!iterator->atEnd()) {
+ String name = iterator->name();
+ String value = iterator->value();
+ if (thisArg)
+ callback->handleItem(*thisArg, value, name, const_cast<CSSVariablesMap*>(this));
+ else
+ callback->handleItem(value, name, const_cast<CSSVariablesMap*>(this));
+ iterator->advance();
+ }
+ ASSERT(m_activeIterators.last() == iterator.get());
+ m_activeIterators.removeLast();
}
} // namespace WebCore
« no previous file with comments | « Source/core/css/CSSVariablesMap.h ('k') | Source/core/css/CSSVariablesMap.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698