mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
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.
This commit is contained in:
parent
17e6287333
commit
e9c1d9c89a
Notes:
sideshowbarker
2024-07-18 21:46:39 +09:00
Author: https://github.com/angus-g Commit: https://github.com/SerenityOS/serenity/commit/e9c1d9c89af Pull-request: https://github.com/SerenityOS/serenity/pull/5554 Issue: https://github.com/SerenityOS/serenity/issues/5515
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user