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

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: Removed unused IDL callback definition Created 7 years, 6 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
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));

Powered by Google App Engine
This is Rietveld 408576698