ladybird/Libraries/LibHTML/CSS/StyleProperties.cpp
Andreas Kling 847072c2b1 LibHTML: Respect the link color set via <body link>
The default style for "a" tags now has { color: -libhtml-link; }.
We implement this vendor-specific property by querying the containing
document for the appropriate link color.

Currently we only use the basic link color, but in the future this can
be extended to remember visited links, etc.
2019-10-06 10:25:08 +02:00

38 lines
1.1 KiB
C++

#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();
}
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();
}
Color StyleProperties::color_or_fallback(const StringView& property_name, const Document& document, Color fallback) const
{
auto value = property(property_name);
if (!value.has_value())
return fallback;
return value.value()->to_color(document);
}