LibWeb: Fix currentColor as a background-color (and maybe other places)

This moves color to be the first value resolved, this ensures that
calls to .to_color() on style values for other properties will always
be able to resolve the current color.

This change fixes the `background-color: currentColor` example in
colors.html.
This commit is contained in:
MacDue 2023-03-05 22:31:44 +00:00 committed by Linus Groh
parent 77fbd912b7
commit 918a3082d6
Notes: sideshowbarker 2024-07-17 08:42:05 +09:00

View file

@ -262,6 +262,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
{
auto& computed_values = static_cast<CSS::MutableComputedValues&>(m_computed_values);
// NOTE: color must be set first to ensure currentColor can be resolved in other properties (e.g. background-color).
computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
// NOTE: We have to be careful that font-related properties get set in the right order.
// m_font is used by Length::to_px() when resolving sizes against this layout node.
// That's why it has to be set before everything else.
@ -531,8 +534,6 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
const_cast<CSS::AbstractImageStyleValue&>(*m_list_style_image).load_any_resources(document());
}
computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
// FIXME: The default text decoration color value is `currentcolor`, but since we can't resolve that easily,
// we just manually grab the value from `color`. This makes it dependent on `color` being
// specified first, so it's far from ideal.