mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:17:41 +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
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));
|
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)
|
RefPtr<CSS::StyleValue> parse_css_value(const CSS::DeprecatedParsingContext& context, const StringView& string, CSS::PropertyID property_id)
|
||||||
{
|
{
|
||||||
bool is_bad_length = false;
|
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)) {
|
if (takes_integer_value(property_id)) {
|
||||||
auto integer = string.to_int();
|
auto integer = string.to_int();
|
||||||
if (integer.has_value())
|
if (integer.has_value())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue