diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-07-23 21:28:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-24 22:16:48 +0200 |
commit | 281689e1fa01586722efd0fa47ec1638cca190de (patch) | |
tree | 13c241929a66416d929fec6a7d7f337d538b2978 /Userland/Libraries/LibWeb | |
parent | f1bdaafcf6554ade403552da9e7ec3f832248d52 (diff) | |
download | serenity-281689e1fa01586722efd0fa47ec1638cca190de.zip |
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: <offset_x> <offset_y> <color>
- box-shadow: <offset_x> <offset_y> <blur_radius> <color>
There is other possible data following the property, but those aren't
supported for now.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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<CSS::CalculatedStyleValue::CalcSum> parse_calc_sum(Vector<CalcToke return make<CSS::CalculatedStyleValue::CalcSum>(parsed_calc_product.release_nonnull(), move(additional)); } +static RefPtr<CSS::BoxShadowStyleValue> 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<CSS::StyleValue> 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()) |