mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
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.
This commit is contained in:
parent
f1bdaafcf6
commit
281689e1fa
Notes:
sideshowbarker
2024-07-18 08:23:02 +09:00
Author: https://github.com/TobyAsE Commit: https://github.com/SerenityOS/serenity/commit/281689e1fa0 Pull-request: https://github.com/SerenityOS/serenity/pull/8968
1 changed files with 48 additions and 0 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue