mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +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:
parent
f68c67bf3f
commit
b2abd1dd05
Notes:
sideshowbarker
2024-07-17 07:31:31 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/b2abd1dd05 Pull-request: https://github.com/SerenityOS/serenity/pull/22359
4 changed files with 35 additions and 26 deletions
|
@ -336,6 +336,33 @@ void LayoutState::resolve_border_radii()
|
|||
}
|
||||
}
|
||||
|
||||
void LayoutState::resolve_box_shadow_data()
|
||||
{
|
||||
for (auto& it : used_values_per_layout_node) {
|
||||
auto& used_values = *it.value;
|
||||
auto& node = const_cast<NodeWithStyle&>(used_values.node());
|
||||
auto* paintable = node.paintable();
|
||||
if (paintable && is<Painting::PaintableBox>(*paintable)) {
|
||||
auto box_shadow_data = node.computed_values().box_shadow();
|
||||
if (box_shadow_data.is_empty())
|
||||
continue;
|
||||
auto& paintable_box = static_cast<Painting::PaintableBox&>(*paintable);
|
||||
Vector<Painting::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(node),
|
||||
layer.offset_y.to_px(node),
|
||||
layer.blur_radius.to_px(node),
|
||||
layer.spread_distance.to_px(node),
|
||||
layer.placement == CSS::ShadowPlacement::Outer ? Painting::ShadowPlacement::Outer : Painting::ShadowPlacement::Inner);
|
||||
}
|
||||
paintable_box.set_box_shadow_data(move(resolved_box_shadow_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutState::commit(Box& root)
|
||||
{
|
||||
// Only the top-level LayoutState should ever be committed.
|
||||
|
@ -432,6 +459,7 @@ void LayoutState::commit(Box& root)
|
|||
}
|
||||
|
||||
resolve_border_radii();
|
||||
resolve_box_shadow_data();
|
||||
}
|
||||
|
||||
void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* containing_block_used_values)
|
||||
|
|
|
@ -187,6 +187,7 @@ struct LayoutState {
|
|||
private:
|
||||
void resolve_relative_positions(Vector<Painting::PaintableWithLines&> const&);
|
||||
void resolve_border_radii();
|
||||
void resolve_box_shadow_data();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue