summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-19 16:07:24 +0100
committerAndreas Kling <kling@serenityos.org>2021-10-19 19:12:09 +0200
commit450b782c18bed4a2025b5464dc4dd207994ee655 (patch)
treece7ffbf6dfe2f93463fb8bf9f4d6377479a8bc35
parent3f311ec0ac255c13a7c769e265a1496d1e03938e (diff)
downloadserenity-450b782c18bed4a2025b5464dc4dd207994ee655.zip
LibWeb: Distinguish between length and percentage values
Though most CSS properties accept either, some do not, so distinguishing between them lets us catch some invalid values at parse time.
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp
index 53f3a70def..c7d3d82ba6 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -334,10 +335,14 @@ bool property_accepts_value(PropertyID property_id, StyleValue& style_value)
if (style_value.is_image())
return true;
)~~~");
- } else if (type_name == "length" || type_name == "percentage") {
- // FIXME: Handle lengths and percentages separately
+ } else if (type_name == "length") {
property_generator.append(R"~~~(
- if (style_value.has_length() || style_value.is_calculated())
+ if ((style_value.has_length() && !style_value.to_length().is_percentage()) || style_value.is_calculated())
+ return true;
+)~~~");
+ } else if (type_name == "percentage") {
+ property_generator.append(R"~~~(
+ if ((style_value.has_length() && style_value.to_length().is_percentage()) || style_value.is_calculated())
return true;
)~~~");
} else if (type_name == "number" || type_name == "integer") {