mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
LibWeb/Painting: Translate by scroll offset before painting descendants
Fixes painting of nested nodes in scrollable containers by moving painter's scroll offset translation from paint_node() to before_children_paint() and after_children_paint().
This commit is contained in:
parent
325d1553ca
commit
cdf8b9e943
3 changed files with 17 additions and 10 deletions
|
@ -429,6 +429,18 @@ Optional<CSSPixelRect> PaintableBox::calculate_overflow_clipped_rect() const
|
|||
return m_clip_rect;
|
||||
}
|
||||
|
||||
void PaintableBox::before_children_paint(PaintContext& context, PaintPhase) const
|
||||
{
|
||||
auto scroll_offset = -this->scroll_offset();
|
||||
context.painter().translate({ context.enclosing_device_pixels(scroll_offset.x()), context.enclosing_device_pixels(scroll_offset.y()) });
|
||||
}
|
||||
|
||||
void PaintableBox::after_children_paint(PaintContext& context, PaintPhase) const
|
||||
{
|
||||
auto scroll_offset = this->scroll_offset();
|
||||
context.painter().translate({ context.enclosing_device_pixels(scroll_offset.x()), context.enclosing_device_pixels(scroll_offset.y()) });
|
||||
}
|
||||
|
||||
void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase phase) const
|
||||
{
|
||||
if (!AK::first_is_one_of(phase, PaintPhase::Background, PaintPhase::Border, PaintPhase::Foreground))
|
||||
|
|
|
@ -125,6 +125,9 @@ public:
|
|||
DOM::Document const& document() const { return layout_box().document(); }
|
||||
DOM::Document& document() { return layout_box().document(); }
|
||||
|
||||
virtual void before_children_paint(PaintContext&, PaintPhase) const override;
|
||||
virtual void after_children_paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
virtual void apply_clip_overflow_rect(PaintContext&, PaintPhase) const override;
|
||||
virtual void clear_clip_overflow_rect(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -26,16 +26,8 @@ namespace Web::Painting {
|
|||
|
||||
static void paint_node(Layout::Node const& layout_node, PaintContext& context, PaintPhase phase)
|
||||
{
|
||||
if (auto const* paintable = layout_node.paintable()) {
|
||||
if (paintable->containing_block() && paintable->containing_block()->is_scrollable()) {
|
||||
Gfx::PainterStateSaver saver(context.painter());
|
||||
auto scroll_offset = -paintable->containing_block()->paintable_box()->scroll_offset();
|
||||
context.painter().translate({ context.enclosing_device_pixels(scroll_offset.x()), context.enclosing_device_pixels(scroll_offset.y()) });
|
||||
if (auto const* paintable = layout_node.paintable())
|
||||
paintable->paint(context, phase);
|
||||
} else {
|
||||
paintable->paint(context, phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StackingContext::StackingContext(Layout::Box& box, StackingContext* parent, size_t index_in_tree_order)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue