summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-12-03 12:52:14 +0000
committerAndreas Kling <kling@serenityos.org>2021-12-09 21:30:31 +0100
commit67e1125b4c5471f70a834067968222c4b88dd2e5 (patch)
tree6b70a4f7e2e35e64d2bafbf381ce59e52e68f679
parent23dc0dac88a248d4ac9b1be36212d065c7112629 (diff)
downloadserenity-67e1125b4c5471f70a834067968222c4b88dd2e5.zip
LibWeb: Handle fallback values for CSS variables :^)
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp12
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.h2
2 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 9b0e4afa33..c8ab27f583 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -452,7 +452,7 @@ struct MatchingDeclarations {
Vector<MatchingRule> author_rules;
};
-bool StyleComputer::expand_unresolved_values(DOM::Element& element, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest) const
+bool StyleComputer::expand_unresolved_values(DOM::Element& element, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index) const
{
// FIXME: Do this better!
// We build a copy of the tree of StyleComponentValueRules, with all var()s replaced with their contents.
@@ -468,7 +468,8 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, Vector<Style
return nullptr;
};
- for (auto& value : source) {
+ for (size_t source_index = source_start_index; source_index < source.size(); source_index++) {
+ auto& value = source[source_index];
if (value.is_function()) {
if (value.function().name().equals_ignoring_case("var"sv)) {
auto& var_contents = value.function().values();
@@ -489,7 +490,12 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, Vector<Style
continue;
}
- // TODO: Handle fallback value
+ // Use the provided fallback value, if any.
+ if (var_contents.size() > 2 && var_contents[1].is(Token::Type::Comma)) {
+ if (!expand_unresolved_values(element, var_contents, dest, 2))
+ return false;
+ continue;
+ }
}
auto& source_function = value.function();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index 3df5eff4d1..e3a6a1b106 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -62,7 +62,7 @@ private:
void compute_defaulted_property_value(StyleProperties&, DOM::Element const*, CSS::PropertyID) const;
RefPtr<StyleValue> resolve_unresolved_style_value(DOM::Element&, PropertyID, UnresolvedStyleValue const&) const;
- bool expand_unresolved_values(DOM::Element&, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest) const;
+ bool expand_unresolved_values(DOM::Element&, Vector<StyleComponentValueRule> const& source, Vector<StyleComponentValueRule>& dest, size_t source_start_index = 0) const;
template<typename Callback>
void for_each_stylesheet(CascadeOrigin, Callback) const;