| Index: Source/core/css/StylePropertySet.cpp
|
| diff --git a/Source/core/css/StylePropertySet.cpp b/Source/core/css/StylePropertySet.cpp
|
| index 81467555886c2c1843a5b55395a29910d6d99ea4..0906ea6d6f95e0f461fbbf9949525df15468d747 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"
|
| @@ -131,6 +132,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 static_cast<CSSVariableValue*>(propertyAt(index).value())->value();
|
| +}
|
| +
|
| bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
|
| {
|
| StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
|
| @@ -265,6 +286,28 @@ unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert
|
| return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForLonghand(prefixingVariant));
|
| }
|
|
|
| +bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const String& value, ExceptionCode&, 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();
|
| + ASSERT(cssValue && cssValue->isVariableValue());
|
| + if (static_cast<CSSVariableValue*>(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);
|
| @@ -442,6 +485,8 @@ bool MutableStylePropertySet::removePropertiesInSet(const CSSPropertyID* set, un
|
|
|
| int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
|
| {
|
| + // CSS variables share the same property ID, findVariableIndex() should be used for variables instead.
|
| + ASSERT(propertyID != CSSPropertyVariable);
|
| for (int n = propertyCount() - 1 ; n >= 0; --n) {
|
| if (propertyID == propertyAt(n).id()) {
|
| // Only enabled properties should be part of the style.
|
| @@ -452,6 +497,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 && static_cast<const CSSVariableValue*>(property.value())->name() == name)
|
| + return i;
|
| + }
|
| + return notFound;
|
| +}
|
| +
|
| CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID propertyID)
|
| {
|
| int foundPropertyIndex = findPropertyIndex(propertyID);
|
| @@ -496,6 +552,32 @@ 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());
|
| + bool removed = false;
|
| + int i = 0;
|
| + while (i < propertyCount()) {
|
| + if (propertyAt(i).id() == CSSPropertyVariable) {
|
| + removed = true;
|
| + m_propertyVector.remove(i);
|
| + } else {
|
| + i++;
|
| + }
|
| + }
|
| + return removed;
|
| +}
|
| +
|
| PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
|
| {
|
| return adoptRef(new MutableStylePropertySet(*this));
|
|
|