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:
Angus Gibson 2021-03-02 08:36:58 +11:00 committed by Andreas Kling
parent 17e6287333
commit e9c1d9c89a
Notes: sideshowbarker 2024-07-18 21:46:39 +09:00
5 changed files with 13 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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;
}