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

Unified Diff: Source/core/css/StylePropertySet.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/StylePropertySet.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/StylePropertySet.cpp
diff --git a/Source/core/css/StylePropertySet.cpp b/Source/core/css/StylePropertySet.cpp
index d19d158eba9555f2bfe6082dd22c21c549356ff4..c551e994d741e484839f0652fcfb38417a8f88e9 100644
--- a/Source/core/css/StylePropertySet.cpp
+++ b/Source/core/css/StylePropertySet.cpp
@@ -286,17 +286,18 @@ bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const S
size_t index = findVariableIndex(name);
if (index != kNotFound) {
- CSSValue* cssValue = m_propertyVector.at(index).value();
+ const CSSValue* cssValue = m_propertyVector.at(index).value();
if (toCSSVariableValue(cssValue)->value() == value)
return false;
}
CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, value), important);
- if (index == kNotFound)
+ if (index == kNotFound) {
m_propertyVector.append(property);
- else
- m_propertyVector.at(index) = property;
- return true;
+ return true;
+ }
+ m_propertyVector.at(index) = property;
+ return false;
}
void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
@@ -563,6 +564,58 @@ bool MutableStylePropertySet::clearVariables()
return removePropertiesInSet(&variablesId, 1);
}
+PassRefPtr<MutableStylePropertySet::VariablesIterator> MutableStylePropertySet::VariablesIterator::create(MutableStylePropertySet* propertySet)
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ const size_t propertyCount = propertySet->propertyCount();
+ size_t variableCount = 0;
+ Vector<AtomicString> remainingNames(propertyCount);
+ for (int i = propertyCount; i--; ) {
+ const PropertyReference& property = propertySet->propertyAt(i);
+ if (property.id() == CSSPropertyVariable)
+ remainingNames[variableCount++] = toCSSVariableValue(property.value())->name();
+ }
+ remainingNames.shrink(variableCount);
+
+ RefPtr<VariablesIterator> iterator = adoptRef(new VariablesIterator(propertySet));
+ // FIXME: Make use of the Vector move constructor when rvalues are supported on all platforms.
+ iterator->takeRemainingNames(remainingNames);
+ return iterator.release();
+}
+
+void MutableStylePropertySet::VariablesIterator::addedVariable(const AtomicString& name)
+{
+ ASSERT(!m_remainingNames.contains(name));
+ ASSERT(!m_newNames.contains(name));
+ m_newNames.append(name);
+}
+
+void MutableStylePropertySet::VariablesIterator::removedVariable(const AtomicString& name)
+{
+ size_t index = m_remainingNames.find(name);
+ if (index != kNotFound)
+ m_remainingNames.remove(index);
+ index = m_newNames.find(name);
+ if (index != kNotFound)
+ m_newNames.remove(index);
+}
+
+void MutableStylePropertySet::VariablesIterator::clearedVariables()
+{
+ m_remainingNames.clear();
+ m_newNames.clear();
+}
+
+void MutableStylePropertySet::VariablesIterator::advance()
+{
+ if (!atEnd())
+ m_remainingNames.removeLast();
+ if (!m_newNames.isEmpty()) {
+ m_remainingNames.appendVector(m_newNames);
+ m_newNames.clear();
+ }
+}
+
PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
{
return adoptRef(new MutableStylePropertySet(*this));
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698