1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:07:44 +00:00

LibWeb: Resolve box shadow data for paintable boxes during layout

Step towards making the paintable tree independent of the layout tree.
This commit is contained in:
Aliaksandr Kalenik 2023-12-19 19:42:00 +01:00 committed by Andreas Kling
parent f68c67bf3f
commit b2abd1dd05
4 changed files with 35 additions and 26 deletions

View file

@ -148,8 +148,7 @@ CSSPixelRect PaintableBox::compute_absolute_paint_rect() const
if (computed_values().overflow_y() == CSS::Overflow::Visible)
rect.unite_vertically(scrollable_overflow_rect);
}
auto resolved_box_shadow_data = resolve_box_shadow_data();
for (auto const& shadow : resolved_box_shadow_data) {
for (auto const& shadow : box_shadow_data()) {
if (shadow.placement == ShadowPlacement::Inner)
continue;
auto inflate = shadow.spread_distance + shadow.blur_radius;
@ -355,30 +354,9 @@ void PaintableBox::paint_background(PaintContext& context) const
Painting::paint_background(context, layout_box(), background_rect, background_color, computed_values().image_rendering(), background_layers, normalized_border_radii_data());
}
Vector<ShadowData> PaintableBox::resolve_box_shadow_data() const
{
auto box_shadow_data = computed_values().box_shadow();
if (box_shadow_data.is_empty())
return {};
Vector<ShadowData> resolved_box_shadow_data;
resolved_box_shadow_data.ensure_capacity(box_shadow_data.size());
for (auto const& layer : box_shadow_data) {
resolved_box_shadow_data.empend(
layer.color,
layer.offset_x.to_px(layout_box()),
layer.offset_y.to_px(layout_box()),
layer.blur_radius.to_px(layout_box()),
layer.spread_distance.to_px(layout_box()),
layer.placement == CSS::ShadowPlacement::Outer ? ShadowPlacement::Outer : ShadowPlacement::Inner);
}
return resolved_box_shadow_data;
}
void PaintableBox::paint_box_shadow(PaintContext& context) const
{
auto resolved_box_shadow_data = resolve_box_shadow_data();
auto const& resolved_box_shadow_data = box_shadow_data();
if (resolved_box_shadow_data.is_empty())
return;
auto borders_data = BordersData {

View file

@ -191,6 +191,9 @@ public:
BorderRadiiData const& border_radii_data() const { return m_border_radii_data; }
void set_border_radii_data(BorderRadiiData const& border_radii_data) { m_border_radii_data = border_radii_data; }
void set_box_shadow_data(Vector<ShadowData> box_shadow_data) { m_box_shadow_data = move(box_shadow_data); }
Vector<ShadowData> const& box_shadow_data() const { return m_box_shadow_data; }
PaintableBox const* nearest_scrollable_ancestor() const;
protected:
@ -206,8 +209,6 @@ protected:
virtual CSSPixelRect compute_absolute_rect() const;
virtual CSSPixelRect compute_absolute_paint_rect() const;
Vector<ShadowData> resolve_box_shadow_data() const;
private:
[[nodiscard]] virtual bool is_paintable_box() const final { return true; }
@ -230,6 +231,7 @@ private:
Optional<TableCellCoordinates> m_table_cell_coordinates;
BorderRadiiData m_border_radii_data;
Vector<ShadowData> m_box_shadow_data;
};
class PaintableWithLines : public PaintableBox {