1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:47:34 +00:00

Userland: Add horizontal mouse scroll support

This commit is contained in:
Dmitry Petrov 2021-12-13 23:22:28 +01:00 committed by Andreas Kling
parent d61cc47055
commit 1662213737
43 changed files with 112 additions and 84 deletions

View file

@ -237,7 +237,7 @@ void InProcessWebView::mouseup_event(GUI::MouseEvent& event)
void InProcessWebView::mousewheel_event(GUI::MouseEvent& event)
{
page().handle_mousewheel(to_content_position(event.position()), event.button(), event.modifiers(), event.wheel_delta());
page().handle_mousewheel(to_content_position(event.position()), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y());
GUI::AbstractScrollableWidget::mousewheel_event(event);
}

View file

@ -136,12 +136,12 @@ void BlockContainer::set_scroll_offset(const Gfx::FloatPoint& offset)
set_needs_display();
}
bool BlockContainer::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta)
bool BlockContainer::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta_x, int wheel_delta_y)
{
if (!is_scrollable())
return false;
auto new_offset = m_scroll_offset;
new_offset.translate_by(0, wheel_delta);
new_offset.translate_by(wheel_delta_x, wheel_delta_y);
set_scroll_offset(new_offset);
return true;

View file

@ -50,7 +50,7 @@ protected:
private:
virtual bool is_block_container() const final { return true; }
virtual bool wants_mouse_events() const override { return false; }
virtual bool 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_x, int wheel_delta_y) override;
bool should_clip_overflow() const;

View file

@ -494,13 +494,13 @@ void Node::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned,
{
}
bool 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_x, int wheel_delta_y)
{
if (auto* containing_block = this->containing_block()) {
if (!containing_block->is_scrollable())
return false;
auto new_offset = containing_block->scroll_offset();
new_offset.translate_by(0, wheel_delta);
new_offset.translate_by(wheel_delta_x, wheel_delta_y);
containing_block->set_scroll_offset(new_offset);
return true;
}

View file

@ -89,7 +89,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 bool 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_x, int wheel_delta_y);
virtual void before_children_paint(PaintContext&, PaintPhase) {};
virtual void paint(PaintContext&, PaintPhase) = 0;

View file

@ -183,7 +183,7 @@ void OutOfProcessWebView::mousemove_event(GUI::MouseEvent& event)
void OutOfProcessWebView::mousewheel_event(GUI::MouseEvent& event)
{
client().async_mouse_wheel(to_content_position(event.position()), event.button(), event.buttons(), event.modifiers(), event.wheel_delta());
client().async_mouse_wheel(to_content_position(event.position()), event.button(), event.buttons(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y());
}
void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event)

View file

@ -112,7 +112,7 @@ Layout::InitialContainingBlock* EventHandler::layout_root()
return m_frame.active_document()->layout_node();
}
bool EventHandler::handle_mousewheel(const Gfx::IntPoint& position, unsigned int buttons, unsigned int modifiers, int wheel_delta)
bool EventHandler::handle_mousewheel(const Gfx::IntPoint& position, unsigned int buttons, unsigned int modifiers, int wheel_delta_x, int wheel_delta_y)
{
if (!layout_root())
return false;
@ -121,12 +121,12 @@ bool EventHandler::handle_mousewheel(const Gfx::IntPoint& position, unsigned int
auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact);
if (result.layout_node) {
if (result.layout_node->handle_mousewheel({}, position, buttons, modifiers, wheel_delta))
if (result.layout_node->handle_mousewheel({}, position, buttons, modifiers, wheel_delta_x, wheel_delta_y))
return true;
}
if (auto* page = m_frame.page()) {
page->client().page_did_request_scroll(0, wheel_delta * 20);
page->client().page_did_request_scroll(wheel_delta_x * 20, wheel_delta_y * 20);
return true;
}

View file

@ -25,7 +25,7 @@ public:
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
bool handle_mousedown(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
bool handle_mousemove(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers);
bool handle_mousewheel(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta);
bool handle_mousewheel(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);

View file

@ -61,9 +61,9 @@ CSS::PreferredColorScheme Page::preferred_color_scheme() const
return m_client.preferred_color_scheme();
}
bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta)
bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta_x, int wheel_delta_y)
{
return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);
return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta_x, wheel_delta_y);
}
bool Page::handle_mouseup(const Gfx::IntPoint& position, unsigned button, unsigned modifiers)

View file

@ -50,7 +50,7 @@ public:
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
bool handle_mousedown(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
bool handle_mousemove(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers);
bool handle_mousewheel(const Gfx::IntPoint&, unsigned button, unsigned modifiers, int wheel_delta);
bool handle_mousewheel(const Gfx::IntPoint&, unsigned button, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);