This text should be black.
diff --git a/Tests/LibWeb/Ref/css-invalid-var.html b/Tests/LibWeb/Ref/css-invalid-var.html
new file mode 100644
index 0000000000..286e38186e
--- /dev/null
+++ b/Tests/LibWeb/Ref/css-invalid-var.html
@@ -0,0 +1,6 @@
+
This text should be black.
diff --git a/Tests/LibWeb/Ref/manifest.json b/Tests/LibWeb/Ref/manifest.json
index 9dadf9a29f..56960d37e8 100644
--- a/Tests/LibWeb/Ref/manifest.json
+++ b/Tests/LibWeb/Ref/manifest.json
@@ -3,6 +3,7 @@
"css-any-link-selector.html": "css-any-link-selector-ref.html",
"css-gradient-currentcolor.html": "css-gradient-currentcolor-ref.html",
"css-gradients.html": "css-gradients-ref.html",
+ "css-invalid-var.html": "css-invalid-var-ref.html",
"css-lang-selector.html": "css-lang-selector-ref.html",
"css-local-link-selector.html": "css-local-link-selector-ref.html",
"css-placeholder-shown-selector.html": "css-placeholder-shown-selector-ref.html",
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 253fbef348..42419bca1c 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -64,6 +64,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -940,10 +941,8 @@ void StyleComputer::set_all_properties(DOM::Element& element, Optional property_value = value;
- if (property_value->is_unresolved()) {
- if (auto resolved = resolve_unresolved_style_value(element, pseudo_element, property_id, property_value->as_unresolved()))
- property_value = resolved.release_nonnull();
- }
+ if (property_value->is_unresolved())
+ property_value = resolve_unresolved_style_value(element, pseudo_element, property_id, property_value->as_unresolved());
if (!property_value->is_unresolved())
set_property_expanding_shorthands(style, property_id, property_value, document, declaration, properties_for_revert);
@@ -1161,28 +1160,30 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
return true;
}
-RefPtr StyleComputer::resolve_unresolved_style_value(DOM::Element& element, Optional pseudo_element, PropertyID property_id, UnresolvedStyleValue const& unresolved) const
+NonnullRefPtr StyleComputer::resolve_unresolved_style_value(DOM::Element& element, Optional pseudo_element, PropertyID property_id, UnresolvedStyleValue const& unresolved) const
{
// Unresolved always contains a var() or attr(), unless it is a custom property's value, in which case we shouldn't be trying
// to produce a different StyleValue from it.
VERIFY(unresolved.contains_var_or_attr());
+ // If the value is invalid, we fall back to `unset`: https://www.w3.org/TR/css-variables-1/#invalid-at-computed-value-time
+
Parser::TokenStream unresolved_values_without_variables_expanded { unresolved.values() };
Vector values_with_variables_expanded;
HashMap> dependencies;
if (!expand_variables(element, pseudo_element, string_from_property_id(property_id), dependencies, unresolved_values_without_variables_expanded, values_with_variables_expanded))
- return {};
+ return UnsetStyleValue::the();
Parser::TokenStream unresolved_values_with_variables_expanded { values_with_variables_expanded };
Vector expanded_values;
if (!expand_unresolved_values(element, string_from_property_id(property_id), unresolved_values_with_variables_expanded, expanded_values))
- return {};
+ return UnsetStyleValue::the();
if (auto parsed_value = Parser::Parser::parse_css_value({}, Parser::ParsingContext { document() }, property_id, expanded_values))
return parsed_value.release_nonnull();
- return {};
+ return UnsetStyleValue::the();
}
void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& element, Optional pseudo_element, Vector const& matching_rules, CascadeOrigin cascade_origin, Important important) const
@@ -1200,10 +1201,8 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e
}
auto property_value = property.value;
- if (property.value->is_unresolved()) {
- if (auto resolved = resolve_unresolved_style_value(element, pseudo_element, property.property_id, property.value->as_unresolved()))
- property_value = resolved.release_nonnull();
- }
+ if (property.value->is_unresolved())
+ property_value = resolve_unresolved_style_value(element, pseudo_element, property.property_id, property.value->as_unresolved());
if (!property_value->is_unresolved())
set_property_expanding_shorthands(style, property.property_id, property_value, m_document, &match.rule->declaration(), properties_for_revert);
}
@@ -1221,10 +1220,8 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e
}
auto property_value = property.value;
- if (property.value->is_unresolved()) {
- if (auto resolved = resolve_unresolved_style_value(element, pseudo_element, property.property_id, property.value->as_unresolved()))
- property_value = resolved.release_nonnull();
- }
+ if (property.value->is_unresolved())
+ property_value = resolve_unresolved_style_value(element, pseudo_element, property.property_id, property.value->as_unresolved());
if (!property_value->is_unresolved())
set_property_expanding_shorthands(style, property.property_id, property_value, m_document, inline_style, properties_for_revert);
}
@@ -1769,10 +1766,8 @@ ErrorOr StyleComputer::compute_cascaded_values(StyleProperties& style, DOM
for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
auto property_id = (CSS::PropertyID)i;
auto& property = style.m_property_values[i];
- if (property.has_value() && property->style->is_unresolved()) {
- if (auto resolved = resolve_unresolved_style_value(element, pseudo_element, property_id, property->style->as_unresolved()))
- property->style = resolved.release_nonnull();
- }
+ if (property.has_value() && property->style->is_unresolved())
+ property->style = resolve_unresolved_style_value(element, pseudo_element, property_id, property->style->as_unresolved());
}
}
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index 43b526ab02..53888af33e 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -153,7 +153,7 @@ private:
void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID, Optional) const;
- RefPtr resolve_unresolved_style_value(DOM::Element&, Optional, PropertyID, UnresolvedStyleValue const&) const;
+ NonnullRefPtr resolve_unresolved_style_value(DOM::Element&, Optional, PropertyID, UnresolvedStyleValue const&) const;
bool expand_variables(DOM::Element&, Optional, StringView property_name, HashMap>& dependencies, Parser::TokenStream& source, Vector& dest) const;
bool expand_unresolved_values(DOM::Element&, StringView property_name, Parser::TokenStream& source, Vector& dest) const;