From 918a3082d6dc6c8769a67ae2fd76bed839d400cb Mon Sep 17 00:00:00 2001 From: MacDue Date: Sun, 5 Mar 2023 22:31:44 +0000 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/Layout/Node.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 2e6b1e86d7..1342715d5b 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -262,6 +262,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) { auto& computed_values = static_cast(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(*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.