StylePropertyMapReadOnly.cpp [plain text]
#include "config.h"
#include "StylePropertyMapReadOnly.h"
#if ENABLE(CSS_TYPED_OM)
#include "CSSImageValue.h"
#include "TypedOMCSSImageValue.h"
#include "TypedOMCSSUnitValue.h"
#include "TypedOMCSSUnparsedValue.h"
#include <wtf/HashMap.h>
namespace WebCore {
RefPtr<TypedOMCSSStyleValue> StylePropertyMapReadOnly::reifyValue(CSSValue* value, Document& document, Element*)
{
if (!value)
return nullptr;
if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).primitiveType() == CSSPrimitiveValue::CSS_PX)
return TypedOMCSSUnitValue::create(downcast<CSSPrimitiveValue>(*value).doubleValue(), "px");
if (is<CSSImageValue>(*value))
return TypedOMCSSImageValue::create(downcast<CSSImageValue>(*value), document);
return TypedOMCSSUnparsedValue::create(value->cssText());
}
RefPtr<TypedOMCSSStyleValue> StylePropertyMapReadOnly::customPropertyValueOrDefault(const String& name, Document& document, CSSValue* inputValue, Element* element)
{
if (!inputValue) {
auto* registered = document.getCSSRegisteredCustomPropertySet().get(name);
if (registered && registered->initialValue()) {
auto value = registered->initialValueCopy();
return StylePropertyMapReadOnly::reifyValue(value.get(), document, element);
}
return TypedOMCSSUnparsedValue::create(emptyString());
}
return StylePropertyMapReadOnly::reifyValue(inputValue, document, element);
}
}
#endif