LibWeb: Parse and store filter property

This shares its implementation with `backdrop-filter`.
This commit is contained in:
Jelle Raaijmakers 2024-10-25 11:00:22 +02:00 committed by Andreas Kling
commit 29974de852
Notes: github-actions[bot] 2024-10-26 09:28:54 +00:00
14 changed files with 104 additions and 75 deletions

View file

@ -512,34 +512,38 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
computed_values.set_order(computed_style.order());
computed_values.set_clip(computed_style.clip());
if (computed_style.backdrop_filter().has_filters()) {
CSS::ResolvedBackdropFilter resolved_backdrop_filter;
for (auto& filter : computed_style.backdrop_filter().filters()) {
auto resolve_filter = [this](CSS::Filter const& computed_filter) -> CSS::ResolvedFilter {
CSS::ResolvedFilter resolved_filter;
for (auto const& filter : computed_filter.filters()) {
filter.visit(
[&](CSS::Filter::Blur const& blur) {
resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::Blur {
[&](CSS::FilterOperation::Blur const& blur) {
resolved_filter.filters.append(CSS::ResolvedFilter::Blur {
.radius = blur.resolved_radius(*this) });
},
[&](CSS::Filter::DropShadow const& drop_shadow) {
[&](CSS::FilterOperation::DropShadow const& drop_shadow) {
// The default value for omitted values is missing length values set to 0
// and the missing used color is taken from the color property.
resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::DropShadow {
resolved_filter.filters.append(CSS::ResolvedFilter::DropShadow {
.offset_x = drop_shadow.offset_x.to_px(*this).to_double(),
.offset_y = drop_shadow.offset_y.to_px(*this).to_double(),
.radius = drop_shadow.radius.has_value() ? drop_shadow.radius->to_px(*this).to_double() : 0.0,
.color = drop_shadow.color.has_value() ? *drop_shadow.color : this->computed_values().color() });
},
[&](CSS::Filter::Color const& color_operation) {
resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::ColorOperation {
.operation = color_operation.operation,
[&](CSS::FilterOperation::Color const& color_operation) {
resolved_filter.filters.append(CSS::ResolvedFilter::Color {
.type = color_operation.operation,
.amount = color_operation.resolved_amount() });
},
[&](CSS::Filter::HueRotate const& hue_rotate) {
resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::HueRotate { .angle_degrees = hue_rotate.angle_degrees() });
[&](CSS::FilterOperation::HueRotate const& hue_rotate) {
resolved_filter.filters.append(CSS::ResolvedFilter::HueRotate { .angle_degrees = hue_rotate.angle_degrees() });
});
}
computed_values.set_backdrop_filter(resolved_backdrop_filter);
}
return resolved_filter;
};
if (computed_style.backdrop_filter().has_filters())
computed_values.set_backdrop_filter(resolve_filter(computed_style.backdrop_filter()));
if (computed_style.filter().has_filters())
computed_values.set_filter(resolve_filter(computed_style.filter()));
auto justify_content = computed_style.justify_content();
if (justify_content.has_value())