diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.h b/Userland/Libraries/LibWeb/Painting/PaintContext.h index a5326fbb9b..343d46502a 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintContext.h +++ b/Userland/Libraries/LibWeb/Painting/PaintContext.h @@ -59,6 +59,9 @@ public: double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; } + CSSPixelPoint scroll_offset() const { return m_scroll_offset; } + void translate_scroll_offset_by(CSSPixelPoint offset) { m_scroll_offset.translate_by(offset); } + private: Gfx::Painter& m_painter; Palette m_palette; @@ -66,6 +69,7 @@ private: DevicePixelRect m_device_viewport_rect; bool m_should_show_line_box_borders { false }; bool m_focus { false }; + CSSPixelPoint m_scroll_offset; }; } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 3277c57c20..14f441327a 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -432,12 +432,14 @@ Optional PaintableBox::calculate_overflow_clipped_rect() const void PaintableBox::before_children_paint(PaintContext& context, PaintPhase) const { auto scroll_offset = -this->scroll_offset(); + context.translate_scroll_offset_by(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.translate_scroll_offset_by(scroll_offset); context.painter().translate({ context.enclosing_device_pixels(scroll_offset.x()), context.enclosing_device_pixels(scroll_offset.y()) }); } @@ -456,7 +458,10 @@ void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase ph if (!m_clipping_overflow) { context.painter().save(); + auto scroll_offset = context.scroll_offset(); + context.painter().translate({ -context.enclosing_device_pixels(scroll_offset.x()), -context.enclosing_device_pixels(scroll_offset.y()) }); context.painter().add_clip_rect(context.enclosing_device_rect(*clip_rect).to_type()); + context.painter().translate({ context.enclosing_device_pixels(scroll_offset.x()), context.enclosing_device_pixels(scroll_offset.y()) }); m_clipping_overflow = true; }