Chromium Code Reviews| Index: Source/core/css/StylePropertySet.cpp |
| diff --git a/Source/core/css/StylePropertySet.cpp b/Source/core/css/StylePropertySet.cpp |
| index 81467555886c2c1843a5b55395a29910d6d99ea4..fbde2a42095956bf8c09c469d8bbcbc1f2e2d3e8 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, 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) |
|
esprehn
2013/07/10 02:42:11
Please add toCSSVariableValue() that does the cssV
alancutter (OOO until 2018)
2013/07/10 11:18:13
Done.
|
| + 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,29 @@ 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; |
| + for (size_t i = propertyCount(); i--;) { |
| + if (propertyAt(i).id() == CSSPropertyVariable) { |
| + removed = true; |
| + m_propertyVector.remove(i); |
| + } |
| + } |
| + return removed; |
|
esprehn
2013/07/10 02:42:11
This can just be
CSSPropertyID variableId = CSSP
alancutter (OOO until 2018)
2013/07/10 11:18:13
Fantastic! Done.
|
| +} |
| + |
| PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const |
| { |
| return adoptRef(new MutableStylePropertySet(*this)); |