2019-09-21 15:32:17 +03:00
|
|
|
#include <LibHTML/CSS/StyleProperties.h>
|
|
|
|
|
|
|
|
void StyleProperties::set_property(const String& name, NonnullRefPtr<StyleValue> value)
|
|
|
|
{
|
|
|
|
m_property_values.set(name, move(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<NonnullRefPtr<StyleValue>> StyleProperties::property(const String& name) const
|
|
|
|
{
|
|
|
|
auto it = m_property_values.find(name);
|
|
|
|
if (it == m_property_values.end())
|
|
|
|
return {};
|
|
|
|
return it->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Length StyleProperties::length_or_fallback(const StringView& property_name, const Length& fallback) const
|
|
|
|
{
|
|
|
|
auto value = property(property_name);
|
|
|
|
if (!value.has_value())
|
|
|
|
return fallback;
|
|
|
|
return value.value()->to_length();
|
|
|
|
}
|
2019-09-25 11:55:04 +03:00
|
|
|
|
|
|
|
String StyleProperties::string_or_fallback(const StringView& property_name, const StringView& fallback) const
|
|
|
|
{
|
|
|
|
auto value = property(property_name);
|
|
|
|
if (!value.has_value())
|
|
|
|
return fallback;
|
|
|
|
return value.value()->to_string();
|
|
|
|
}
|
2019-09-28 22:18:19 +02:00
|
|
|
|
2019-10-06 10:25:08 +02:00
|
|
|
Color StyleProperties::color_or_fallback(const StringView& property_name, const Document& document, Color fallback) const
|
2019-09-28 22:18:19 +02:00
|
|
|
{
|
|
|
|
auto value = property(property_name);
|
|
|
|
if (!value.has_value())
|
|
|
|
return fallback;
|
2019-10-06 10:25:08 +02:00
|
|
|
return value.value()->to_color(document);
|
2019-09-28 22:18:19 +02:00
|
|
|
}
|