1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:07:35 +00:00

LibWeb: Render multiple box-shadows

Because why not? :^)
This commit is contained in:
Sam Atkins 2022-02-08 14:48:37 +00:00 committed by Andreas Kling
parent b51f428165
commit 10c6c77b5c
8 changed files with 107 additions and 65 deletions

View file

@ -104,7 +104,7 @@ public:
CSS::AlignItems align_items() const { return m_noninherited.align_items; }
float opacity() const { return m_noninherited.opacity; }
CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
Optional<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
Vector<BoxShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
CSS::LengthPercentage const& width() const { return m_noninherited.width; }
CSS::LengthPercentage const& min_width() const { return m_noninherited.min_width; }
@ -201,7 +201,7 @@ protected:
CSS::Overflow overflow_x { InitialValues::overflow() };
CSS::Overflow overflow_y { InitialValues::overflow() };
float opacity { InitialValues::opacity() };
Optional<BoxShadowData> box_shadow {};
Vector<BoxShadowData> box_shadow {};
Vector<CSS::Transformation> transformations {};
CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
} m_noninherited;
@ -255,7 +255,7 @@ public:
void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
void set_opacity(float value) { m_noninherited.opacity = value; }
void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
void set_box_shadow(Optional<BoxShadowData> value) { m_noninherited.box_shadow = move(value); }
void set_box_shadow(Vector<BoxShadowData>&& value) { m_noninherited.box_shadow = move(value); }
void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }

View file

@ -518,12 +518,23 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
case CSS::PropertyID::JustifyContent:
return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content()));
case CSS::PropertyID::BoxShadow: {
auto maybe_box_shadow = layout_node.computed_values().box_shadow();
if (!maybe_box_shadow.has_value())
auto box_shadow_layers = layout_node.computed_values().box_shadow();
if (box_shadow_layers.is_empty())
return {};
auto box_shadow_data = maybe_box_shadow.release_value();
// FIXME: Add extra properties to BoxShadowData so we can include them here!
return BoxShadowStyleValue::create(box_shadow_data.color, box_shadow_data.offset_x, box_shadow_data.offset_y, box_shadow_data.blur_radius, Length::make_px(0), BoxShadowPlacement::Outer);
auto make_box_shadow_style_value = [](BoxShadowData const& data) {
// FIXME: Add extra properties to BoxShadowData so we can include them here!
return BoxShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, Length::make_px(0), BoxShadowPlacement::Outer);
};
if (box_shadow_layers.size() == 1)
return make_box_shadow_style_value(box_shadow_layers.first());
NonnullRefPtrVector<StyleValue> box_shadow;
box_shadow.ensure_capacity(box_shadow_layers.size());
for (auto const& layer : box_shadow_layers)
box_shadow.append(make_box_shadow_style_value(layer));
return StyleValueList::create(move(box_shadow), StyleValueList::Separator::Comma);
}
case CSS::PropertyID::Width:
return style_value_for_length_percentage(layout_node.computed_values().width());

View file

@ -769,18 +769,35 @@ Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) c
}
}
Optional<CSS::BoxShadowData> StyleProperties::box_shadow() const
Vector<BoxShadowData> StyleProperties::box_shadow() const
{
auto value_or_error = property(CSS::PropertyID::BoxShadow);
auto value_or_error = property(PropertyID::BoxShadow);
if (!value_or_error.has_value())
return {};
auto value = value_or_error.value();
if (!value->is_box_shadow())
return {};
auto& box = value->as_box_shadow();
return { { box.offset_x(), box.offset_y(), box.blur_radius(), box.color() } };
auto make_box_shadow_data = [](BoxShadowStyleValue const& box) {
return BoxShadowData { box.offset_x(), box.offset_y(), box.blur_radius(), box.color() };
};
if (value->is_value_list()) {
auto& value_list = value->as_value_list();
Vector<BoxShadowData> box_shadow_data;
box_shadow_data.ensure_capacity(value_list.size());
for (auto const& layer_value : value_list.values())
box_shadow_data.append(make_box_shadow_data(layer_value.as_box_shadow()));
return box_shadow_data;
}
if (value->is_box_shadow()) {
auto& box = value->as_box_shadow();
return { make_box_shadow_data(box) };
}
return {};
}
CSS::BoxSizing StyleProperties::box_sizing() const

View file

@ -64,7 +64,7 @@ public:
Optional<CSS::JustifyContent> justify_content() const;
Optional<CSS::Overflow> overflow_x() const;
Optional<CSS::Overflow> overflow_y() const;
Optional<CSS::BoxShadowData> box_shadow() const;
Vector<CSS::BoxShadowData> box_shadow() const;
CSS::BoxSizing box_sizing() const;
Optional<CSS::PointerEvents> pointer_events() const;