| 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());
|
| }
|
|
|