mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-02 16:25:34 +03:00
Ladybird: Plumb Qt mouse events into LibWeb
This commit is contained in:
parent
f16ba7945a
commit
9b8fe16e3d
Notes:
sideshowbarker
2024-07-17 02:50:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9b8fe16e3d Pull-request: https://github.com/SerenityOS/serenity/pull/16583 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
@ -48,6 +48,7 @@
|
||||
#include <LibWebSocket/ConnectionInfo.h>
|
||||
#include <LibWebSocket/Message.h>
|
||||
#include <LibWebSocket/WebSocket.h>
|
||||
#include <QMouseEvent>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
@ -189,9 +190,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void page_did_invalidate(Gfx::IntRect const&) override
|
||||
virtual void page_did_invalidate(Gfx::IntRect const& rect) override
|
||||
{
|
||||
m_view.update();
|
||||
m_view.viewport()->update();
|
||||
}
|
||||
|
||||
virtual void page_did_change_favicon(Gfx::Bitmap const&) override
|
||||
@ -262,6 +263,8 @@ private:
|
||||
|
||||
WebView::WebView()
|
||||
{
|
||||
setMouseTracking(true);
|
||||
|
||||
m_page_client = HeadlessBrowserPageClient::create(*this);
|
||||
|
||||
m_page_client->setup_palette(Gfx::load_system_theme("/home/kling/src/serenity/Base/res/themes/Default.ini"));
|
||||
@ -279,6 +282,65 @@ void WebView::load(String const& url)
|
||||
m_page_client->load(AK::URL(url));
|
||||
}
|
||||
|
||||
unsigned get_button_from_qt_event(QMouseEvent const& event)
|
||||
{
|
||||
if (event.button() == Qt::MouseButton::LeftButton)
|
||||
return 1;
|
||||
if (event.button() == Qt::MouseButton::RightButton)
|
||||
return 2;
|
||||
if (event.button() == Qt::MouseButton::MiddleButton)
|
||||
return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned get_buttons_from_qt_event(QMouseEvent const& event)
|
||||
{
|
||||
unsigned buttons = 0;
|
||||
if (event.buttons() & Qt::MouseButton::LeftButton)
|
||||
buttons |= 1;
|
||||
if (event.buttons() & Qt::MouseButton::RightButton)
|
||||
buttons |= 2;
|
||||
if (event.buttons() & Qt::MouseButton::MiddleButton)
|
||||
buttons |= 4;
|
||||
return buttons;
|
||||
}
|
||||
|
||||
unsigned get_modifiers_from_qt_event(QMouseEvent const& event)
|
||||
{
|
||||
unsigned modifiers = 0;
|
||||
if (event.modifiers() & Qt::Modifier::ALT)
|
||||
modifiers |= 1;
|
||||
if (event.modifiers() & Qt::Modifier::CTRL)
|
||||
modifiers |= 2;
|
||||
if (event.modifiers() & Qt::Modifier::SHIFT)
|
||||
modifiers |= 4;
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
void WebView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
Gfx::IntPoint position(event->x(), event->y());
|
||||
auto buttons = get_buttons_from_qt_event(*event);
|
||||
auto modifiers = get_modifiers_from_qt_event(*event);
|
||||
m_page_client->page().handle_mousemove(position, buttons, modifiers);
|
||||
}
|
||||
|
||||
void WebView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
Gfx::IntPoint position(event->x(), event->y());
|
||||
auto button = get_button_from_qt_event(*event);
|
||||
auto modifiers = get_modifiers_from_qt_event(*event);
|
||||
m_page_client->page().handle_mousedown(position, button, modifiers);
|
||||
}
|
||||
|
||||
void WebView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
Gfx::IntPoint position(event->x(), event->y());
|
||||
auto button = get_button_from_qt_event(*event);
|
||||
auto modifiers = get_modifiers_from_qt_event(*event);
|
||||
m_page_client->page().handle_mouseup(position, button, modifiers);
|
||||
}
|
||||
|
||||
void WebView::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(viewport());
|
||||
|
@ -24,6 +24,9 @@ public:
|
||||
|
||||
virtual void paintEvent(QPaintEvent*) override;
|
||||
virtual void resizeEvent(QResizeEvent*) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent*) override;
|
||||
virtual void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent*) override;
|
||||
|
||||
private:
|
||||
OwnPtr<HeadlessBrowserPageClient> m_page_client;
|
||||
|
Loading…
Reference in New Issue
Block a user