summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Layout/BlockBox.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-22 19:48:24 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-22 21:47:00 +0100
commitcd79b807dd6fd5e5ab24838dde749cc1e0467964 (patch)
tree32b3e0c7cace9b2da051865b29a4facb048d9fe9 /Userland/Libraries/LibWeb/Layout/BlockBox.cpp
parentded8c728d296537de0969668237f4d6c6b4a9590 (diff)
downloadserenity-cd79b807dd6fd5e5ab24838dde749cc1e0467964.zip
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. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout/BlockBox.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Layout/BlockBox.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp
index c0a05cae33..a23d33d1e2 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp
@@ -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);
+}
+
}