summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-04-21 18:31:00 +0100
committerAndreas Kling <kling@serenityos.org>2023-04-28 09:42:28 +0200
commita5fa5e55efe5e816473d06f93bb3cb2668a44447 (patch)
tree2a2e7a80711ecc8d2184d146325dee079e0c882a
parent2fbe5b969b347ba5002b7cd53fbd3436d88a3e0e (diff)
downloadserenity-a5fa5e55efe5e816473d06f93bb3cb2668a44447.zip
LibWeb: Allow specifying a URL for an SVG fill
This does not do anything yet, but will allow for gradients later!
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp6
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp17
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.h1
-rw-r--r--Userland/Libraries/LibWeb/CSS/Properties.json2
4 files changed, 25 insertions, 1 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
index 4e9f63d65c..717167bda7 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp
@@ -519,6 +519,12 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
output_numeric_value_check(property_generator, "is_time"sv, "as_time().time().to_seconds()"sv, Array { "Time"sv }, min_value, max_value);
} else if (type_name == "url") {
// FIXME: Handle urls!
+ } else if (type_name == "paint") {
+ // https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
+ property_generator.append(R"~~~(
+ if (style_value.has_color() || style_value.is_url())
+ return true;
+)~~~");
} else {
// Assume that any other type names are defined in Enums.json.
// If they're not, the output won't compile, but that's fine since it's invalid.
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 268c0d886c..7266b3473e 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -72,6 +72,7 @@
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
+#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
#include <LibWeb/CSS/StyleValues/UnsetStyleValue.h>
#include <LibWeb/DOM/Document.h>
@@ -2361,6 +2362,14 @@ Optional<AK::URL> Parser::parse_url_function(ComponentValue const& component_val
return {};
}
+RefPtr<StyleValue> Parser::parse_url_value(ComponentValue const& component_value, AllowedDataUrlType allowed_data_url_type)
+{
+ auto url = parse_url_function(component_value, allowed_data_url_type);
+ if (!url.has_value())
+ return {};
+ return URLStyleValue::create(*url);
+}
+
template<typename TElement>
static Optional<Vector<TElement>> parse_color_stop_list(auto& tokens, auto is_position, auto get_position, auto parse_color, auto parse_dimension)
{
@@ -6738,6 +6747,14 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
if (auto parse_value = parse_transform_origin_value(component_values))
return parse_value.release_nonnull();
return ParseError ::SyntaxError;
+ case PropertyID::Fill:
+ if (component_values.size() == 1) {
+ if (auto parsed_url = parse_url_value(component_values.first()))
+ return parsed_url.release_nonnull();
+ }
+ // Allow normal value parsing to continue.
+ // URL is done here to avoid ambiguity with images.
+ break;
default:
break;
}
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
index 4b8afdde31..ac2fbd9f2e 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h
@@ -267,6 +267,7 @@ private:
Font,
};
Optional<AK::URL> parse_url_function(ComponentValue const&, AllowedDataUrlType = AllowedDataUrlType::None);
+ RefPtr<StyleValue> parse_url_value(ComponentValue const&, AllowedDataUrlType = AllowedDataUrlType::None);
Optional<Vector<LinearColorStopListElement>> parse_linear_color_stop_list(TokenStream<ComponentValue>&);
Optional<Vector<AngularColorStopListElement>> parse_angular_color_stop_list(TokenStream<ComponentValue>&);
diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json
index 5b9b2990ab..437b578455 100644
--- a/Userland/Libraries/LibWeb/CSS/Properties.json
+++ b/Userland/Libraries/LibWeb/CSS/Properties.json
@@ -630,7 +630,7 @@
"inherited": true,
"initial": "black",
"valid-types": [
- "color"
+ "paint"
],
"valid-identifiers": [
"none"