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.
This commit is contained in:
Sam Atkins 2021-10-19 16:07:24 +01:00 committed by Andreas Kling
parent 3f311ec0ac
commit 450b782c18
Notes: sideshowbarker 2024-07-18 02:09:48 +09:00

View file

@ -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") {