Skip to content

Truly independent web browser

UI/Qt: Keep all input out of the page's native window

Andreas Kling647c602fcaeb
diff --git a/Tests/UI/Qt/TestNativeWindowContainerFocus.cpp b/Tests/UI/Qt/TestNativeWindowContainerFocus.cpp
index 5db55d71492..336239eaf03 100644
--- a/Tests/UI/Qt/TestNativeWindowContainerFocus.cpp
+++ b/Tests/UI/Qt/TestNativeWindowContainerFocus.cpp
@@ -4,11 +4,14 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Vector.h>
#include <LibTest/TestCase.h>
#include <QApplication>
-#include <QKeyEvent>
+#include <QDragEnterEvent>
+#include <QMimeData>
#include <QMouseEvent>
+#include <QUrl>
#include <QWidget>
#include <QWindow>
#include <UI/Qt/NativeWindowContainer.h>
@@ -25,12 +28,17 @@ QApplication& application()
struct TestWindow {
TestWindow()
: host(*new QWidget(&window))
- , container(*new QWidget(&host))
, sibling(*new QWidget(&window))
+ , native_window(*new QWindow)
+ , container(*Ladybird::create_native_window_container(native_window, host))
{
+ window.resize(200, 100);
+ host.setGeometry(0, 0, 100, 100);
+ sibling.setGeometry(100, 0, 100, 100);
+ container.setGeometry(host.rect());
+
host.setFocusPolicy(Qt::StrongFocus);
sibling.setFocusPolicy(Qt::StrongFocus);
- container.setFocusPolicy(Qt::StrongFocus);
container.hide();
window.show();
@@ -40,57 +48,43 @@ struct TestWindow {
QWidget window;
QWidget& host;
- QWidget& container;
QWidget& sibling;
+ QWindow& native_window;
+ QWidget& container;
};
-class FocusEventRecorder final : public QObject {
+class EventRecorder final : public QObject {
public:
- QEvent::Type last_focus_event { QEvent::None };
+ Vector<QEvent::Type> received;
private:
virtual bool eventFilter(QObject*, QEvent* event) override
{
- if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut)
- last_focus_event = event->type();
+ received.append(event->type());
return false;
}
};
-class KeyEventRecorder final : public QObject {
-public:
- Qt::Key last_key { Qt::Key_unknown };
-
-private:
- virtual bool eventFilter(QObject*, QEvent* event) override
- {
- if (event->type() != QEvent::KeyPress)
- return false;
- last_key = static_cast<Qt::Key>(static_cast<QKeyEvent*>(event)->key());
- return true;
- }
-};
+}
+static void send_mouse_event(QWidget& window, QEvent::Type type, Qt::MouseButtons buttons)
+{
+ QPointF const position { 50, 50 };
+ auto const global_position = window.mapToGlobal(position);
+ QMouseEvent event { type, position, position, global_position, Qt::LeftButton, buttons, Qt::NoModifier };
+ QCoreApplication::sendEvent(window.windowHandle(), &event);
}
-TEST_CASE(focus_proxy_follows_container_visibility)
+TEST_CASE(native_window_takes_no_input)
{
application();
TestWindow widgets;
- EXPECT(!widgets.host.focusProxy());
-
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- EXPECT(widgets.container.isVisible());
- EXPECT_EQ(widgets.host.focusProxy(), &widgets.container);
- EXPECT_EQ(widgets.container.geometry(), widgets.host.rect());
-
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, false);
- EXPECT(!widgets.container.isVisible());
- EXPECT(!widgets.host.focusProxy());
+ EXPECT(widgets.native_window.flags().testFlag(Qt::WindowTransparentForInput));
+ EXPECT(widgets.native_window.flags().testFlag(Qt::WindowDoesNotAcceptFocus));
}
-TEST_CASE(keyboard_focus_moves_with_the_container)
+TEST_CASE(host_keeps_the_keyboard_focus)
{
application();
TestWindow widgets;
@@ -99,10 +93,10 @@ TEST_CASE(keyboard_focus_moves_with_the_container)
QApplication::processEvents();
EXPECT_EQ(QApplication::focusWidget(), &widgets.host);
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- EXPECT_EQ(QApplication::focusWidget(), &widgets.container);
+ widgets.container.show();
+ EXPECT_EQ(QApplication::focusWidget(), &widgets.host);
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, false);
+ widgets.container.hide();
EXPECT_EQ(QApplication::focusWidget(), &widgets.host);
}
@@ -115,109 +109,57 @@ TEST_CASE(focus_is_not_stolen_from_other_widgets)
QApplication::processEvents();
EXPECT_EQ(QApplication::focusWidget(), &widgets.sibling);
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- EXPECT_EQ(widgets.host.focusProxy(), &widgets.container);
+ widgets.container.show();
EXPECT_EQ(QApplication::focusWidget(), &widgets.sibling);
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, false);
+ widgets.container.hide();
EXPECT_EQ(QApplication::focusWidget(), &widgets.sibling);
}
-TEST_CASE(container_focus_events_are_forwarded_to_the_host)
+TEST_CASE(pointer_input_goes_past_the_container)
{
application();
TestWindow widgets;
- QWindow native_window;
- Ladybird::install_native_window_container_event_forwarding(widgets.host, native_window, widgets.container);
-
- FocusEventRecorder recorder;
- widgets.host.installEventFilter(&recorder);
-
- widgets.host.setFocus();
- QApplication::processEvents();
-
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- EXPECT_EQ(QApplication::focusWidget(), &widgets.container);
- EXPECT_EQ(recorder.last_focus_event, QEvent::FocusIn);
-
- widgets.sibling.setFocus();
- EXPECT_EQ(recorder.last_focus_event, QEvent::FocusOut);
-
- widgets.container.setFocus();
- EXPECT_EQ(recorder.last_focus_event, QEvent::FocusIn);
-
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, false);
- EXPECT_EQ(QApplication::focusWidget(), &widgets.host);
- EXPECT_EQ(recorder.last_focus_event, QEvent::FocusIn);
+ widgets.container.show();
+ EXPECT_EQ(widgets.window.childAt(50, 50), &widgets.host);
}
-TEST_CASE(native_window_mouse_press_focuses_the_container)
+TEST_CASE(press_continues_while_the_container_hides)
{
application();
TestWindow widgets;
- QWindow native_window;
- Ladybird::install_native_window_container_event_forwarding(widgets.host, native_window, widgets.container);
-
- FocusEventRecorder recorder;
+ EventRecorder recorder;
widgets.host.installEventFilter(&recorder);
+ widgets.container.show();
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- widgets.sibling.setFocus();
- QApplication::processEvents();
- EXPECT_EQ(QApplication::focusWidget(), &widgets.sibling);
-
- recorder.last_focus_event = QEvent::None;
+ send_mouse_event(widgets.window, QEvent::MouseButtonPress, Qt::LeftButton);
+ EXPECT(recorder.received.contains_slow(QEvent::MouseButtonPress));
- QMouseEvent mouse_press {
- QEvent::MouseButtonPress,
- QPointF { 1, 1 },
- QPointF { 1, 1 },
- Qt::LeftButton,
- Qt::LeftButton,
- Qt::NoModifier
- };
- QApplication::sendEvent(&native_window, &mouse_press);
+ widgets.container.hide();
- EXPECT_EQ(QApplication::focusWidget(), &widgets.container);
- EXPECT_EQ(recorder.last_focus_event, QEvent::FocusIn);
+ send_mouse_event(widgets.window, QEvent::MouseButtonRelease, Qt::NoButton);
+ EXPECT(recorder.received.contains_slow(QEvent::MouseButtonRelease));
}
-TEST_CASE(container_key_events_are_forwarded_to_the_host)
+TEST_CASE(drags_go_past_the_container)
{
application();
TestWindow widgets;
- QWindow native_window;
- Ladybird::install_native_window_container_event_forwarding(widgets.host, native_window, widgets.container);
-
- KeyEventRecorder recorder;
+ EventRecorder recorder;
widgets.host.installEventFilter(&recorder);
+ widgets.host.setAcceptDrops(true);
+ widgets.container.show();
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- widgets.host.setFocus();
- QApplication::processEvents();
- EXPECT_EQ(QApplication::focusWidget(), &widgets.container);
-
- QKeyEvent tab_press { QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier };
- QApplication::sendEvent(&widgets.container, &tab_press);
-
- EXPECT_EQ(recorder.last_key, Qt::Key_Tab);
- EXPECT_EQ(QApplication::focusWidget(), &widgets.container);
-}
-
-TEST_CASE(visibility_changes_are_idempotent)
-{
- application();
- TestWindow widgets;
+ QMimeData mime_data;
+ mime_data.setUrls({ QUrl { "file:///dragged" } });
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, false);
- EXPECT(!widgets.container.isVisible());
- EXPECT(!widgets.host.focusProxy());
+ QDragEnterEvent drag_enter { QPoint { 50, 50 }, Qt::CopyAction, &mime_data, Qt::LeftButton, Qt::NoModifier };
+ QCoreApplication::sendEvent(widgets.window.windowHandle(), &drag_enter);
+ EXPECT(recorder.received.contains_slow(QEvent::DragEnter));
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- Ladybird::set_native_window_container_visible(widgets.host, widgets.container, true);
- EXPECT(widgets.container.isVisible());
- EXPECT_EQ(widgets.host.focusProxy(), &widgets.container);
+ QDragLeaveEvent drag_leave;
+ QCoreApplication::sendEvent(widgets.window.windowHandle(), &drag_leave);
}
diff --git a/UI/Qt/NativeWindowContainer.cpp b/UI/Qt/NativeWindowContainer.cpp
index 7ceb4dbc905..7ae8c186185 100644
--- a/UI/Qt/NativeWindowContainer.cpp
+++ b/UI/Qt/NativeWindowContainer.cpp
@@ -7,8 +7,7 @@
#include <AK/kmalloc.h>
#include <UI/Qt/NativeWindowContainer.h>
-#include <QCoreApplication>
-#include <QFocusEvent>
+#include <QEvent>
#include <QWidget>
#include <QWindow>
@@ -16,89 +15,37 @@ namespace Ladybird {
namespace {
-class EventForwarder final : public QObject {
+class ContainerPaintFilter final : public QObject {
public:
AK_ALLOC_WITH_KMALLOC;
- EventForwarder(QWidget& host, QWidget& container)
- : QObject(&container)
- , m_host(host)
- , m_container(container)
- {
- }
+ using QObject::QObject;
private:
- virtual bool eventFilter(QObject* watched, QEvent* event) override
+ virtual bool eventFilter(QObject*, QEvent* event) override
{
- switch (event->type()) {
- case QEvent::FocusIn:
- case QEvent::FocusOut:
- if (watched == &m_container) {
- QFocusEvent forwarded_event { event->type(), static_cast<QFocusEvent*>(event)->reason() };
- QCoreApplication::sendEvent(&m_host, &forwarded_event);
- }
- break;
-
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- // Keyboard input belongs to the host, not the container. Forwarding it from an event filter also preempts
- // QWidget's Tab focus navigation, which would otherwise consume Tab before the host sees it.
- if (watched == &m_container)
- return QCoreApplication::sendEvent(&m_host, event);
- break;
-
- case QEvent::MouseButtonPress:
- if (m_host.focusProxy() == &m_container)
- m_container.setFocus(Qt::MouseFocusReason);
- break;
-
- case QEvent::Paint:
- // NB: QWindowContainer clears its whole area to transparent on platforms that may stack native child
- // windows below their parent. Ours are always above it, and the clear would only hide the host's own
- // painting wherever the native window has nothing on screen yet.
- if (watched == &m_container)
- return true;
- break;
-
- default:
- break;
- }
-
- return false;
+ // NB: QWindowContainer clears its whole area to transparent on platforms that may stack native child windows
+ // below their parent. Ours are always above it, and the clear would only hide the host's own painting
+ // wherever the native window has nothing on screen yet.
+ return event->type() == QEvent::Paint;
}
-
- QWidget& m_host;
- QWidget& m_container;
};
}
-void set_native_window_container_visible(QWidget& host, QWidget& container, bool visible)
-{
- if (container.isVisible() == visible)
- return;
-
- if (visible) {
- bool host_had_focus = host.hasFocus();
- container.setGeometry(host.rect());
- container.show();
- host.setFocusProxy(&container);
- if (host_had_focus)
- container.setFocus();
- } else {
- bool container_had_focus = container.hasFocus();
- host.setFocusProxy(nullptr);
- container.hide();
- if (container_had_focus)
- host.setFocus();
- }
-}
-
-void install_native_window_container_event_forwarding(QWidget& host, QWindow& native_window, QWidget& container)
+QWidget* create_native_window_container(QWindow& native_window, QWidget& host)
{
- auto* forwarder = new EventForwarder(host, container);
- native_window.installEventFilter(forwarder);
- container.installEventFilter(forwarder);
+ // NB: The host takes all pointer input and drags, as the receiver of a press keeps getting events while it is
+ // dragged out of the browser window, or while the container hides. The window must not take the focus either:
+ // On X11, a window that is transparent for input doesn't ask for key events, and X doesn't pass them on past
+ // the window with the input focus.
+ native_window.setFlag(Qt::WindowTransparentForInput);
+ native_window.setFlag(Qt::WindowDoesNotAcceptFocus);
+
+ auto* container = QWidget::createWindowContainer(&native_window, &host);
+ container->setAttribute(Qt::WA_TransparentForMouseEvents);
+ container->installEventFilter(new ContainerPaintFilter(container));
+ return container;
}
}
diff --git a/UI/Qt/NativeWindowContainer.h b/UI/Qt/NativeWindowContainer.h
index 581e1865325..638c5ddb555 100644
--- a/UI/Qt/NativeWindowContainer.h
+++ b/UI/Qt/NativeWindowContainer.h
@@ -11,10 +11,8 @@ class QWindow;
namespace Ladybird {
-// Shows or hides a container widget that embeds a native window inside a host widget — keeping keyboard focus
-// consistent: The container is the host's focus proxy only while it's visible.
-void set_native_window_container_visible(QWidget& host, QWidget& container, bool visible);
-
-void install_native_window_container_event_forwarding(QWidget& host, QWindow& native_window, QWidget& container);
+// Embeds a native window in a host widget. The native window only presents what is on screen, while the host takes all
+// of its input and keeps the keyboard focus.
+QWidget* create_native_window_container(QWindow& native_window, QWidget& host);
}
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index 285602c48f4..37af09a083f 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -1118,17 +1118,10 @@ void WebContentView::focusOutEvent(QFocusEvent*)
void WebContentView::update_page_focus()
{
- // Focus can move between this widget, the native window container, and the embedded native window in bursts of
- // events whose order is not meaningful (e.g. the container reports losing focus after native focus has already
- // moved to the embedded window). Instead of trusting individual events, evaluate the resulting focus state once
- // the burst has settled.
+ // A change of the active window and the change of focus it leads to arrive as separate events. Instead of trusting
+ // individual events, evaluate the resulting focus state once they have all arrived.
QTimer::singleShot(0, this, [this] {
- auto focused = hasFocus();
-#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
- if (!focused)
- focused = vulkan_window_has_native_focus();
-#endif
- set_has_system_focus(focused);
+ set_has_system_focus(hasFocus());
});
}
@@ -2237,64 +2230,64 @@ void WebContentView::update_cursor(Gfx::Cursor cursor)
cursor.visit([this](Gfx::StandardCursor standard_cursor) {
switch (standard_cursor) {
case Gfx::StandardCursor::Hidden:
- apply_web_content_cursor(Qt::BlankCursor);
+ setCursor(Qt::BlankCursor);
break;
case Gfx::StandardCursor::Arrow:
- apply_web_content_cursor(Qt::ArrowCursor);
+ setCursor(Qt::ArrowCursor);
break;
case Gfx::StandardCursor::Crosshair:
- apply_web_content_cursor(Qt::CrossCursor);
+ setCursor(Qt::CrossCursor);
break;
case Gfx::StandardCursor::IBeam:
- apply_web_content_cursor(Qt::IBeamCursor);
+ setCursor(Qt::IBeamCursor);
break;
case Gfx::StandardCursor::ResizeHorizontal:
- apply_web_content_cursor(Qt::SizeHorCursor);
+ setCursor(Qt::SizeHorCursor);
break;
case Gfx::StandardCursor::ResizeVertical:
- apply_web_content_cursor(Qt::SizeVerCursor);
+ setCursor(Qt::SizeVerCursor);
break;
case Gfx::StandardCursor::ResizeDiagonalTLBR:
- apply_web_content_cursor(Qt::SizeFDiagCursor);
+ setCursor(Qt::SizeFDiagCursor);
break;
case Gfx::StandardCursor::ResizeDiagonalBLTR:
- apply_web_content_cursor(Qt::SizeBDiagCursor);
+ setCursor(Qt::SizeBDiagCursor);
break;
case Gfx::StandardCursor::ResizeColumn:
- apply_web_content_cursor(Qt::SplitHCursor);
+ setCursor(Qt::SplitHCursor);
break;
case Gfx::StandardCursor::ResizeRow:
- apply_web_content_cursor(Qt::SplitVCursor);
+ setCursor(Qt::SplitVCursor);
break;
case Gfx::StandardCursor::Hand:
- apply_web_content_cursor(Qt::PointingHandCursor);
+ setCursor(Qt::PointingHandCursor);
break;
case Gfx::StandardCursor::Help:
- apply_web_content_cursor(Qt::WhatsThisCursor);
+ setCursor(Qt::WhatsThisCursor);
break;
case Gfx::StandardCursor::OpenHand:
- apply_web_content_cursor(Qt::OpenHandCursor);
+ setCursor(Qt::OpenHandCursor);
break;
case Gfx::StandardCursor::Drag:
- apply_web_content_cursor(Qt::ClosedHandCursor);
+ setCursor(Qt::ClosedHandCursor);
break;
case Gfx::StandardCursor::DragCopy:
- apply_web_content_cursor(Qt::DragCopyCursor);
+ setCursor(Qt::DragCopyCursor);
break;
case Gfx::StandardCursor::Move:
- apply_web_content_cursor(Qt::DragMoveCursor);
+ setCursor(Qt::DragMoveCursor);
break;
case Gfx::StandardCursor::Wait:
- apply_web_content_cursor(Qt::BusyCursor);
+ setCursor(Qt::BusyCursor);
break;
case Gfx::StandardCursor::Disallowed:
- apply_web_content_cursor(Qt::ForbiddenCursor);
+ setCursor(Qt::ForbiddenCursor);
break;
case Gfx::StandardCursor::Eyedropper:
case Gfx::StandardCursor::Zoom:
// FIXME: No corresponding Qt cursors, default to Arrow
default:
- apply_web_content_cursor(Qt::ArrowCursor);
+ setCursor(Qt::ArrowCursor);
break;
} },
[this](Gfx::ImageCursor const& image_cursor) {
@@ -2313,18 +2306,10 @@ void WebContentView::update_cursor(Gfx::Cursor cursor)
dbgln("Failed to set cursor: Couldn't create QPixmap from QImage.");
return;
}
- apply_web_content_cursor(QCursor { qpixmap, image_cursor.hotspot.x(), image_cursor.hotspot.y() });
+ setCursor(QCursor { qpixmap, image_cursor.hotspot.x(), image_cursor.hotspot.y() });
});
}
-void WebContentView::apply_web_content_cursor(QCursor const& cursor)
-{
- setCursor(cursor);
-#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
- set_vulkan_window_cursor(cursor);
-#endif
-}
-
Web::DevicePixelPoint WebContentView::node_picker_position_for(QSinglePointEvent const& event) const
{
return { event.position().x() * m_device_pixel_ratio, event.position().y() * m_device_pixel_ratio };
@@ -2490,78 +2475,6 @@ bool WebContentView::handle_native_gesture_event(QNativeGestureEvent const& even
}
}
-#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
-bool WebContentView::handle_vulkan_window_event(QEvent* event)
-{
- switch (event->type()) {
- case QEvent::KeyPress:
- keyPressEvent(static_cast<QKeyEvent*>(event));
- return true;
- case QEvent::KeyRelease:
- keyReleaseEvent(static_cast<QKeyEvent*>(event));
- return true;
- case QEvent::MouseMove:
- mouseMoveEvent(static_cast<QMouseEvent*>(event));
- return true;
- case QEvent::MouseButtonPress:
- mousePressEvent(static_cast<QMouseEvent*>(event));
- return true;
- case QEvent::MouseButtonRelease:
- mouseReleaseEvent(static_cast<QMouseEvent*>(event));
- return true;
- case QEvent::MouseButtonDblClick:
- // QWindow sends a MouseButtonPress before MouseButtonDblClick for the second click, so the press has already
- // been forwarded and included in the click count.
- return true;
- case QEvent::Wheel:
- wheelEvent(static_cast<QWheelEvent*>(event));
- // An ignored event is reserved for a browser shortcut such as Ctrl+wheel zoom. A native window has no widget
- // ancestors to propagate it through, so send it to the top-level window directly.
- if (!event->isAccepted())
- return QCoreApplication::sendEvent(window(), event);
- return true;
- case QEvent::Leave:
- leaveEvent(event);
- return true;
- case QEvent::FocusIn:
- focusInEvent(static_cast<QFocusEvent*>(event));
- return true;
- case QEvent::FocusOut:
- focusOutEvent(static_cast<QFocusEvent*>(event));
- return true;
- case QEvent::InputMethod:
- inputMethodEvent(static_cast<QInputMethodEvent*>(event));
- return true;
- case QEvent::DragEnter:
- dragEnterEvent(static_cast<QDragEnterEvent*>(event));
- return true;
- case QEvent::DragMove:
- dragMoveEvent(static_cast<QDragMoveEvent*>(event));
- return true;
- case QEvent::DragLeave:
- dragLeaveEvent(static_cast<QDragLeaveEvent*>(event));
- return true;
- case QEvent::Drop:
- dropEvent(static_cast<QDropEvent*>(event));
- return true;
- case QEvent::NativeGesture:
- return handle_native_gesture_event(*static_cast<QNativeGestureEvent const*>(event));
- case QEvent::ShortcutOverride: {
- auto* key_event = static_cast<QKeyEvent*>(event);
- if (is_browser_reserved_shortcut(*key_event)) {
- event->ignore();
- return false;
- }
-
- event->accept();
- return true;
- }
- default:
- return false;
- }
-}
-#endif
-
void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePointEvent const& event, Optional<Web::ScrollGesturePhase> scroll_gesture_phase_the_platform_reports)
{
Web::DevicePixelPoint position = { event.position().x() * m_device_pixel_ratio, event.position().y() * m_device_pixel_ratio };
diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.h
index d3162513ee4..e2beb0cc356 100644
--- a/UI/Qt/WebContentView.h
+++ b/UI/Qt/WebContentView.h
@@ -252,7 +252,6 @@ private:
void update_viewport_size();
void update_cursor(Gfx::Cursor cursor);
- void apply_web_content_cursor(QCursor const&);
void schedule_repaint();
#ifdef LADYBIRD_QT_USE_RHI_WIDGET
void schedule_frame_damage_repaint();
@@ -420,9 +419,6 @@ private:
bool current_paintable_can_use_vulkan_window() const;
void schedule_vulkan_window_update();
void update_vulkan_window_geometry();
- void set_vulkan_window_cursor(QCursor const&);
- bool handle_vulkan_window_event(QEvent*);
- bool vulkan_window_has_native_focus() const;
void set_vulkan_window_container_visible(bool);
void fall_back_to_bitmap_rendering();
void vulkan_window_exposure_changed();
diff --git a/UI/Qt/WebContentViewLinux.cpp b/UI/Qt/WebContentViewLinux.cpp
index 27bc0505da1..f5eb396e24f 100644
--- a/UI/Qt/WebContentViewLinux.cpp
+++ b/UI/Qt/WebContentViewLinux.cpp
@@ -1042,8 +1042,6 @@ struct WebContentView::VulkanWindow final : public QVulkanWindow {
virtual bool event(QEvent* event) override
{
- if (m_view && m_view->handle_vulkan_window_event(event))
- return true;
// NB: Every step of a resize asks to present again, which recreates the swap chain at the new size only to show
// the same frame in it. Until the page has a frame for the new size, keep the last one on screen. Its
// surface keeps its size until it presents again, and the view paints the edge it leaves bare.
@@ -1089,31 +1087,21 @@ void WebContentView::create_vulkan_window()
VK_FORMAT_R8G8B8A8_UNORM,
});
- m_vulkan_window_container = QWidget::createWindowContainer(m_vulkan_window, this);
- m_vulkan_window_container->setAcceptDrops(true);
- m_vulkan_window_container->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
- m_vulkan_window_container->setMouseTracking(true);
+ m_vulkan_window_container = create_native_window_container(*m_vulkan_window, *this);
m_vulkan_window_container->setGeometry(rect());
m_vulkan_window_container->hide();
- install_native_window_container_event_forwarding(*this, *m_vulkan_window, *m_vulkan_window_container);
-
m_unexposed_vulkan_window_timer.setSingleShot(true);
m_unexposed_vulkan_window_timer.setInterval(500);
QObject::connect(&m_unexposed_vulkan_window_timer, &QTimer::timeout, this, [this] { remap_unexposed_vulkan_window(); });
}
-bool WebContentView::vulkan_window_has_native_focus() const
-{
- return m_vulkan_window && QGuiApplication::focusWindow() == m_vulkan_window;
-}
-
void WebContentView::set_vulkan_window_container_visible(bool visible)
{
if (!visible)
m_presented_page_window_size = {};
if (m_vulkan_window_container)
- set_native_window_container_visible(*this, *m_vulkan_window_container, visible);
+ m_vulkan_window_container->setVisible(visible);
}
bool WebContentView::vulkan_window_update_would_only_resize() const
@@ -1195,7 +1183,6 @@ void WebContentView::fall_back_to_bitmap_rendering()
void WebContentView::destroy_vulkan_window()
{
- setFocusProxy(nullptr);
if (m_vulkan_window)
m_vulkan_window->clear_view();
@@ -1535,12 +1522,13 @@ void WebContentView::update_vulkan_window_mask()
if (!m_vulkan_window || !m_vulkan_window_container)
return;
- // On X11, the native window's bounding shape exposes the regions painted transparent for hover-expanded chrome.
- // Wayland instead uses the renderer's alpha output and empties the native window's input region separately.
+ // On X11, the native window's bounding shape exposes the regions of hover-expanded chrome, with or without alpha
+ // blending. Wayland instead uses the renderer's alpha output and empties the native window's input region
+ // separately.
auto size = m_vulkan_window_container->size();
QRegion window_mask { QRect { QPoint { 0, 0 }, size } };
- if (m_vulkan_window_supports_alpha_blending.value_or(false)) {
+ if (QGuiApplication::platformName() == "xcb" || m_vulkan_window_supports_alpha_blending.value_or(false)) {
if (m_vertical_tab_overlay_left > 0)
window_mask -= QRect { 0, 0, m_vertical_tab_overlay_left, size.height() };
if (m_vertical_tab_overlay_right > 0)
@@ -1589,20 +1577,8 @@ void WebContentView::update_vulkan_alpha_blending_support()
m_vulkan_window_supports_alpha_blending = color_format_has_alpha && (capabilities.supportedCompositeAlpha & blending_modes) != 0;
- // Route pointer input through QWidget when it can also display widgets beneath the Vulkan surface. QWidget's
- // implicit mouse capture then preserves move and release events while the pointer is outside the browser window.
- m_vulkan_window->setFlag(Qt::WindowTransparentForInput, *m_vulkan_window_supports_alpha_blending);
-
// The window mask was computed while support was still unknown; refresh it now that any stored insets can apply.
update_vulkan_window_mask();
}
-void WebContentView::set_vulkan_window_cursor(QCursor const& cursor)
-{
- if (m_vulkan_window_container)
- m_vulkan_window_container->setCursor(cursor);
- if (m_vulkan_window)
- m_vulkan_window->setCursor(cursor);
-}
-
}