summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Painting/Paintable.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-10 22:46:35 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-11 00:21:49 +0100
commitcb0c5390ff9a0189ae79cfd690f6c089ba73c4a7 (patch)
treef6b3f94c65f92cb195e67eb75add5eb9815e8cc2 /Userland/Libraries/LibWeb/Painting/Paintable.cpp
parented84fbce474a86721ff85aa9559213e12bd556ba (diff)
downloadserenity-cb0c5390ff9a0189ae79cfd690f6c089ba73c4a7.zip
LibWeb: Move mouse event and label logic from layout to painting tree
Input events have nothing to do with layout, so let's not send them to layout nodes. The job of Paintable starts to become clear. It represents a paintable item that can be rendered into the viewport, which means it can also be targeted by the mouse cursor.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting/Paintable.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Painting/Paintable.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
index 2e9eda8f9c..8747e80a16 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
@@ -287,4 +287,52 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
}
}
+void Paintable::handle_mousedown(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
+{
+}
+
+void Paintable::handle_mouseup(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
+{
+}
+
+void Paintable::handle_mousemove(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned)
+{
+}
+
+bool Paintable::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint const&, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y)
+{
+ if (auto* containing_block = layout_node().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<Layout::BlockContainer*>(containing_block)->set_scroll_offset(new_offset);
+ return true;
+ }
+
+ return false;
+}
+
+bool PaintableWithLines::handle_mousewheel(Badge<EventHandler>, Gfx::IntPoint const&, 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);
+ const_cast<Layout::BlockContainer&>(layout_box()).set_scroll_offset(new_offset);
+ return true;
+}
+
+Layout::BlockContainer const& PaintableWithLines::layout_box() const
+{
+ return static_cast<Layout::BlockContainer const&>(PaintableBox::layout_box());
+}
+
+Layout::BlockContainer& PaintableWithLines::layout_box()
+{
+ return static_cast<Layout::BlockContainer&>(PaintableBox::layout_box());
+}
+
}