1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibWeb: Move mouse wheel handling from Paintable to PaintableBox

It is only PaintableBox that can have scrollable overflow so it doesn't
make sense to have handle_mousewheel() implementation in Paintable.

Also new implementation of handle_mousewheel() takes in account overflow
limits from scrollable_overflow_rect().
This commit is contained in:
Aliaksandr Kalenik 2023-08-06 14:28:23 +02:00 committed by Andreas Kling
parent 55b5c61a79
commit c7673605bb
3 changed files with 10 additions and 17 deletions

View file

@ -663,13 +663,16 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
}
}
bool PaintableWithLines::handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
bool PaintableBox::handle_mousewheel(Badge<EventHandler>, 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;
}