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

LibWeb: Allow scrolling overflowed content with the mouse wheel :^)

This is rather crude, but you can now use the mouse wheel to scroll up
and down in block-level boxes with clipped overflowing content.
There's no limit to how far you can scroll in either direction, since
we don't yet track how much overflow there is. But it's a start. :^)
This commit is contained in:
Andreas Kling 2021-02-22 19:48:24 +01:00
parent ded8c728d2
commit cd79b807dd
5 changed files with 44 additions and 0 deletions

View file

@ -68,6 +68,7 @@ void BlockBox::paint(PaintContext& context, PaintPhase phase)
context.painter().save();
// FIXME: Handle overflow-x and overflow-y being different values.
context.painter().add_clip_rect(enclosing_int_rect(padded_rect()));
context.painter().translate(-m_scroll_offset.to_type<int>());
}
for (auto& line_box : m_line_boxes) {
@ -141,4 +142,19 @@ void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode lay
line_box->add_fragment(*this, 0, 0, border_box_width(), height());
}
void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset)
{
if (m_scroll_offset == offset)
return;
m_scroll_offset = offset;
set_needs_display();
}
void BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta)
{
auto new_offset = m_scroll_offset;
new_offset.move_by(0, wheel_delta);
set_scroll_offset(new_offset);
}
}