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

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

Issue 18311002: Partial implementation of CSSVariablesMap for CSS Variables CSSOM (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased onto ToT, cleaned up includes Created 7 years, 5 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') | Source/core/css/resolver/StyleResolver.cpp » ('j') | 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 9a06b9f128981936664ddd3e1f1d0457ea592747..241d39e33124f33397ffcc781471eea1b29677a1 100644
--- a/Source/core/css/StylePropertySet.cpp
+++ b/Source/core/css/StylePropertySet.cpp
@@ -22,6 +22,7 @@
#include "config.h"
#include "core/css/StylePropertySet.h"
+#include "RuntimeEnabledFeatures.h"
#include "core/css/CSSParser.h"
#include "core/css/CSSValuePool.h"
#include "core/css/CSSVariableValue.h"
@@ -121,6 +122,26 @@ PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert
return propertyAt(foundPropertyIndex).value();
}
+unsigned StylePropertySet::variableCount() const
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ unsigned count = 0;
+ for (unsigned i = 0; i < propertyCount(); ++i) {
+ if (propertyAt(i).id() == CSSPropertyVariable)
+ count++;
+ }
+ return count;
+}
+
+String StylePropertySet::variableValue(const AtomicString& name) const
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ size_t index = findVariableIndex(name);
+ if (index == notFound)
+ return String();
+ return toCSSVariableValue(propertyAt(index).value())->value();
+}
+
bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
{
StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
@@ -255,6 +276,27 @@ unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert
return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForLonghand(prefixingVariant));
}
+bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const String& value, bool important)
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ if (value.isEmpty())
+ return removeVariable(name);
+
+ size_t index = findVariableIndex(name);
+ if (index != notFound) {
+ CSSValue* cssValue = m_propertyVector.at(index).value();
+ if (toCSSVariableValue(cssValue)->value() == value)
+ return false;
+ }
+
+ CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, value), important);
+ if (index == notFound)
+ m_propertyVector.append(property);
+ else
+ m_propertyVector.at(index) = property;
+ return true;
+}
+
void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
{
m_propertyVector.append(property);
@@ -445,6 +487,17 @@ int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
return -1;
}
+size_t StylePropertySet::findVariableIndex(const AtomicString& name) const
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ for (int i = propertyCount() - 1; i >= 0; --i) {
+ const PropertyReference& property = propertyAt(i);
+ if (property.id() == CSSPropertyVariable && toCSSVariableValue(property.value())->name() == name)
+ return i;
+ }
+ return notFound;
+}
+
CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID propertyID)
{
int foundPropertyIndex = findPropertyIndex(propertyID);
@@ -489,6 +542,23 @@ void MutableStylePropertySet::removeEquivalentProperties(const CSSStyleDeclarati
removeProperty(propertiesToRemove[i]);
}
+bool MutableStylePropertySet::removeVariable(const AtomicString& name)
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ size_t index = findVariableIndex(name);
+ if (index == notFound)
+ return false;
+ m_propertyVector.remove(index);
+ return true;
+}
+
+bool MutableStylePropertySet::clearVariables()
+{
+ ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
+ CSSPropertyID variablesId = CSSPropertyVariable;
+ return removePropertiesInSet(&variablesId, 1);
+}
+
PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
{
return adoptRef(new MutableStylePropertySet(*this));
@@ -564,10 +634,9 @@ PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro
String StylePropertySet::PropertyReference::cssName() const
{
if (id() == CSSPropertyVariable) {
- ASSERT(propertyValue()->isVariableValue());
if (!propertyValue()->isVariableValue())
return emptyString(); // Should not happen, but if it does, avoid a bad cast.
- return "var-" + static_cast<const CSSVariableValue*>(propertyValue())->name();
+ return "var-" + toCSSVariableValue(propertyValue())->name();
}
return getPropertyNameString(id());
}
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698