From 281689e1fa01586722efd0fa47ec1638cca190de Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Fri, 23 Jul 2021 21:28:48 +0200 Subject: LibWeb: Parse box-shadow in the DeprecatedCSSParser This adds support for box-shadows to the DeprecatedCSSParser. When it encounters a box-shadow property, the following syntaxes can get parsed: - box-shadow: - box-shadow: There is other possible data following the property, but those aren't supported for now. --- .../LibWeb/CSS/Parser/DeprecatedCSSParser.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp index 1b509512e5..92d7d636a4 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp @@ -631,10 +631,58 @@ static OwnPtr parse_calc_sum(Vector(parsed_calc_product.release_nonnull(), move(additional)); } +static RefPtr parse_box_shadow(CSS::DeprecatedParsingContext const& context, StringView const& string) +{ + // FIXME: Also support inset, spread-radius and multiple comma-seperated box-shadows + CSS::Length offset_x {}; + CSS::Length offset_y {}; + CSS::Length blur_radius {}; + Color color {}; + + auto parts = string.split_view(' '); + + if (parts.size() < 3 || parts.size() > 4) + return nullptr; + + bool bad_length = false; + offset_x = parse_length(context, parts[0], bad_length); + if (bad_length) + return nullptr; + + bad_length = false; + offset_y = parse_length(context, parts[1], bad_length); + if (bad_length) + return nullptr; + + if (parts.size() == 3) { + auto parsed_color = parse_color(context, parts[2]); + if (!parsed_color) + return nullptr; + color = parsed_color->color(); + } else if (parts.size() == 4) { + bad_length = false; + blur_radius = parse_length(context, parts[2], bad_length); + if (bad_length) + return nullptr; + + auto parsed_color = parse_color(context, parts[3]); + if (!parsed_color) + return nullptr; + color = parsed_color->color(); + } + return CSS::BoxShadowStyleValue::create(offset_x, offset_y, blur_radius, color); +} + RefPtr parse_css_value(const CSS::DeprecatedParsingContext& context, const StringView& string, CSS::PropertyID property_id) { bool is_bad_length = false; + if (property_id == CSS::PropertyID::BoxShadow) { + auto parsed_box_shadow = parse_box_shadow(context, string); + if (parsed_box_shadow) + return parsed_box_shadow; + } + if (takes_integer_value(property_id)) { auto integer = string.to_int(); if (integer.has_value()) -- cgit v1.2.3