From d579ed7e466491be088520c720427ab8935c0123 Mon Sep 17 00:00:00 2001 From: Diego Iastrubni Date: Wed, 14 Sep 2022 22:32:01 +0300 Subject: [PATCH] Ladybird: Don't propagate unrecognized button clicks to the web engine There are a lot of unsupported mouse click events that the engine cannot handle. It such event (0) reaches the web engine - it will assert. Don't even propagate them - this is the safe way. As of today! I also added back/forward buttons to the translation. Should fix #27 --- Ladybird/WebView.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp index 24e5baf8b8..7e7a33d740 100644 --- a/Ladybird/WebView.cpp +++ b/Ladybird/WebView.cpp @@ -115,6 +115,10 @@ unsigned get_button_from_qt_event(QMouseEvent const& event) return 2; if (event.button() == Qt::MouseButton::MiddleButton) return 4; + if (event.button() == Qt::MouseButton::BackButton) + return 8; + if (event.buttons() == Qt::MouseButton::ForwardButton) + return 16; return 0; } @@ -127,6 +131,10 @@ unsigned get_buttons_from_qt_event(QMouseEvent const& event) buttons |= 2; if (event.buttons() & Qt::MouseButton::MiddleButton) buttons |= 4; + if (event.buttons() & Qt::MouseButton::BackButton) + buttons |= 8; + if (event.buttons() & Qt::MouseButton::ForwardButton) + buttons |= 16; return buttons; } @@ -296,6 +304,12 @@ void WebView::mousePressEvent(QMouseEvent* event) { Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio); auto button = get_button_from_qt_event(*event); + if (button == 0) { + // We could not convert Qt buttons to something that Lagom can + // recognize - don't even bother propagating this to the web engine + // as it will not handle it anyway, and it will (currently) assert + return; + } auto modifiers = get_modifiers_from_qt_mouse_event(*event); m_page_client->page().handle_mousedown(to_content(position), button, modifiers); } @@ -304,6 +318,12 @@ void WebView::mouseReleaseEvent(QMouseEvent* event) { Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio); auto button = get_button_from_qt_event(*event); + if (button == 0) { + // We could not convert Qt buttons to something that Lagom can + // recognize - don't even bother propagating this to the web engine + // as it will not handle it anyway, and it will (currently) assert + return; + } auto modifiers = get_modifiers_from_qt_mouse_event(*event); m_page_client->page().handle_mouseup(to_content(position), button, modifiers); }