diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp index 3abbe3a304..1872ff39f1 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp @@ -34,19 +34,8 @@ Paintable::DispatchEventOfSameName Paintable::handle_mousemove(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) +bool Paintable::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int, int) { - if (auto const* containing_block = this->containing_block()) { - if (!containing_block->is_scrollable()) - return false; - auto new_offset = containing_block->scroll_offset(); - new_offset.translate_by(wheel_delta_x, wheel_delta_y); - // FIXME: This const_cast is gross. - // FIXME: Scroll offset shouldn't live in the layout tree. - const_cast(containing_block)->set_scroll_offset(new_offset); - return true; - } - return false; } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 12cde61398..a577d085ca 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -663,13 +663,16 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const } } -bool PaintableWithLines::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) +bool PaintableBox::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) { if (!layout_box().is_scrollable()) return false; - auto new_offset = layout_box().scroll_offset(); - new_offset.translate_by(wheel_delta_x, wheel_delta_y); - layout_box().set_scroll_offset(new_offset); + auto max_x_offset = scrollable_overflow_rect()->width() - content_size().width(); + auto max_y_offset = scrollable_overflow_rect()->height() - content_size().height(); + auto current_offset = layout_box().scroll_offset(); + auto new_offset_x = clamp(current_offset.x() + wheel_delta_x, 0, max_x_offset); + auto new_offset_y = clamp(current_offset.y() + wheel_delta_y, 0, max_y_offset); + layout_box().set_scroll_offset({ new_offset_x, new_offset_y }); return true; } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.h b/Userland/Libraries/LibWeb/Painting/PaintableBox.h index 99f39a59d5..3727b350a1 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.h @@ -126,6 +126,8 @@ public: virtual Optional hit_test(CSSPixelPoint, HitTestType) const override; + virtual bool handle_mousewheel(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override; + void invalidate_stacking_context(); bool is_out_of_view(PaintContext&) const; @@ -235,7 +237,6 @@ public: virtual void paint(PaintContext&, PaintPhase) const override; virtual bool wants_mouse_events() const override { return false; } - virtual bool handle_mousewheel(Badge, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y) override; virtual Optional hit_test(CSSPixelPoint, HitTestType) const override;