diff options
author | Angus Gibson <angus@agibson.me> | 2021-03-02 08:36:58 +1100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-02 13:20:03 +0100 |
commit | e9c1d9c89af74239e27f872355897a4ba35818ad (patch) | |
tree | 9e01766bd5008d97bb123cd891f8dfd0c14bf059 /Userland | |
parent | 17e6287333517d98189596b169e7a10c184424b0 (diff) | |
download | serenity-e9c1d9c89af74239e27f872355897a4ba35818ad.zip |
LibWeb: Return whether handle_mousewheel was handled
We try scrolling a Node with the handle_mousewheel event, but if it
isn't scrollable, the event should be passed back up to the page
host. This is the first step in that process.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockBox.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockBox.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Page/EventHandler.cpp | 3 |
5 files changed, 13 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp index d46b743721..5a9f2b5c43 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp @@ -156,13 +156,15 @@ void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset) set_needs_display(); } -void BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta) +bool BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta) { if (!is_scrollable()) - return; + return false; auto new_offset = m_scroll_offset; new_offset.move_by(0, wheel_delta); set_scroll_offset(new_offset); + + return true; } } diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.h b/Userland/Libraries/LibWeb/Layout/BlockBox.h index 5d6951a0e0..269a6b939c 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.h +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.h @@ -60,7 +60,7 @@ public: private: virtual bool is_block_box() const final { return true; } virtual bool wants_mouse_events() const override { return true; } - virtual void handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta) override; + virtual bool handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta) override; bool should_clip_overflow() const; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 7a72dfbca5..b2c1cd4661 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -322,15 +322,18 @@ void Node::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, { } -void Node::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned, int wheel_delta) +bool Node::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned, int wheel_delta) { if (auto* containing_block = this->containing_block()) { if (!containing_block->is_scrollable()) - return; + return false; auto new_offset = containing_block->scroll_offset(); new_offset.move_by(0, wheel_delta); containing_block->set_scroll_offset(new_offset); + return true; } + + return false; } bool Node::is_root_element() const diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 653baa5264..917f9607b3 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -109,7 +109,7 @@ public: virtual void handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers); virtual void handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers); virtual void handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers); - virtual void handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta); + virtual bool handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta); virtual void before_children_paint(PaintContext&, PaintPhase) {}; virtual void paint(PaintContext&, PaintPhase); diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 688dc0b9c2..f4f4cd886d 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -139,7 +139,8 @@ bool EventHandler::handle_mousewheel(const Gfx::IntPoint& position, unsigned int auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact); if (result.layout_node) { - result.layout_node->handle_mousewheel({}, position, buttons, modifiers, wheel_delta); + if (result.layout_node->handle_mousewheel({}, position, buttons, modifiers, wheel_delta)) + return true; return true; } |