summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Iastrubni <diegoiast@gmail.com>2022-09-14 22:32:01 +0300
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commitd579ed7e466491be088520c720427ab8935c0123 (patch)
treee33828698d1633a658bf61e2478fec065570810c
parent561303829e6e3b564d33b1354e21e5d4300a6395 (diff)
downloadserenity-d579ed7e466491be088520c720427ab8935c0123.zip
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
-rw-r--r--Ladybird/WebView.cpp20
1 files changed, 20 insertions, 0 deletions
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);
}