StyleCustomPropertyData.h [plain text]
#pragma once
#include "CSSCustomPropertyValue.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/text/AtomicStringHash.h>
namespace WebCore {
class StyleCustomPropertyData : public RefCounted<StyleCustomPropertyData> {
public:
static Ref<StyleCustomPropertyData> create() { return adoptRef(*new StyleCustomPropertyData); }
Ref<StyleCustomPropertyData> copy() const { return adoptRef(*new StyleCustomPropertyData(*this)); }
bool operator==(const StyleCustomPropertyData& other) const
{
if (containsVariables != other.containsVariables)
return false;
if (values.size() != other.values.size())
return false;
for (auto& entry : values) {
auto otherEntry = other.values.find(entry.key);
if (otherEntry == other.values.end() || !entry.value->equals(*otherEntry->value))
return false;
}
return true;
}
bool operator!=(const StyleCustomPropertyData& other) const { return !(*this == other); }
void setCustomPropertyValue(const AtomicString& name, Ref<CSSCustomPropertyValue>&& value)
{
if (value->containsVariables())
containsVariables = true;
values.set(name, WTFMove(value));
}
CustomPropertyValueMap values;
bool containsVariables { false };
private:
StyleCustomPropertyData() = default;
StyleCustomPropertyData(const StyleCustomPropertyData& other)
: RefCounted<StyleCustomPropertyData>()
, values(other.values)
, containsVariables(other.containsVariables)
{ }
};
}