summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@gmail.com>2021-08-16 17:42:09 +0100
committerAndreas Kling <kling@serenityos.org>2021-08-25 12:14:34 +0200
commit8995839e3f0d4bc3018cb86a2dbd45d49460c969 (patch)
treefe5db6f3ed9d0f3c0f5844b1ad9c856732d3a4f6
parent38ee69adfa25c81c6327bde2d1613d350a2e7e4a (diff)
downloadserenity-8995839e3f0d4bc3018cb86a2dbd45d49460c969.zip
LibWeb: Generate property_initial_value() function from Properties.json
Since we have initial-value data in Properties.json already, it makes sense to use that instead of needing to duplicate the same information in ComputedValues.h However, converting a StyleValue to the kind of types used in InitialValues is non-trivial. So this may or may not actually be useful.
-rw-r--r--Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_cpp.cpp32
-rw-r--r--Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_h.cpp2
2 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_cpp.cpp b/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_cpp.cpp
index 22937da989..9852fd57d9 100644
--- a/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_cpp.cpp
+++ b/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_cpp.cpp
@@ -45,7 +45,9 @@ int main(int argc, char** argv)
generator.append(R"~~~(
#include <AK/Assertions.h>
+#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h>
+#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {
@@ -153,6 +155,36 @@ bool is_pseudo_property(PropertyID property_id)
}
}
+RefPtr<StyleValue> property_initial_value(PropertyID property_id)
+{
+ static HashMap<PropertyID, NonnullRefPtr<StyleValue>> initial_values;
+ if (initial_values.is_empty()) {
+ ParsingContext parsing_context;
+)~~~");
+
+ json.value().as_object().for_each_member([&](auto& name, auto& value) {
+ VERIFY(value.is_object());
+
+ if (value.as_object().has("initial")) {
+ auto& initial_value = value.as_object().get("initial");
+ VERIFY(initial_value.is_string());
+ auto initial_value_string = initial_value.as_string();
+
+ auto member_generator = generator.fork();
+ member_generator.set("name:titlecase", title_casify(name));
+ member_generator.set("initial_value_string", initial_value_string);
+ member_generator.append(R"~~~(
+ if (auto parsed_value = Parser(parsing_context, "@initial_value_string@").parse_as_css_value(PropertyID::@name:titlecase@))
+ initial_values.set(PropertyID::@name:titlecase@, parsed_value.release_nonnull());
+)~~~");
+ }
+ });
+
+ generator.append(R"~~~(
+ }
+ return initial_values.get(property_id).value_or(nullptr);
+}
+
} // namespace Web::CSS
)~~~");
diff --git a/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_h.cpp b/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_h.cpp
index 89ad93c4d1..355d77b28f 100644
--- a/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_h.cpp
+++ b/Userland/Libraries/LibWeb/CodeGenerators/Generate_CSS_PropertyID_h.cpp
@@ -47,6 +47,7 @@ int main(int argc, char** argv)
#include <AK/StringView.h>
#include <AK/Traits.h>
+#include <LibWeb/Forward.h>
namespace Web::CSS {
@@ -73,6 +74,7 @@ PropertyID property_id_from_string(const StringView&);
const char* string_from_property_id(PropertyID);
bool is_inherited_property(PropertyID);
bool is_pseudo_property(PropertyID);
+RefPtr<StyleValue> property_initial_value(PropertyID);
} // namespace Web::CSS