Skip to content

Truly independent web browser

UI/Qt: Open select dropdowns from the top-level window

Andreas Klingf4a0f50e5530
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index aa83d046bd4..89400bc5f17 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -417,6 +417,10 @@ WebContentView::WebContentView(QWidget* window, Optional<WebView::CanonicalTrave
};
on_request_select_dropdown = [this](Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items) {
+ // NB: The view has a native window of its own, which Qt refuses as the transient parent of a popup. The
+ // dropdown opens from the top-level window instead, which can change when the tab moves to another one.
+ if (m_select_dropdown->parentWidget() != this->window())
+ m_select_dropdown->setParent(this->window(), m_select_dropdown->windowFlags());
m_select_dropdown->open(map_point_to_global_position(content_position), minimum_width, items);
};
}
@@ -437,6 +441,9 @@ WebContentView::~WebContentView()
# endif
#endif
+ // NB: The dropdown can belong to the top-level window, which outlives the view.
+ delete m_select_dropdown;
+
#if !defined(Q_OS_WIN)
QAccessible::removeActivationObserver(this);
#endif
@@ -461,6 +468,10 @@ void WebContentView::prepare_for_window_move()
void WebContentView::finish_window_move()
{
+ // NB: The dropdown moves to the new top-level window too, because the old one can close and delete it.
+ if (m_select_dropdown->parentWidget() != window())
+ m_select_dropdown->setParent(window(), m_select_dropdown->windowFlags());
+
#ifdef LADYBIRD_QT_USE_RHI_WIDGET
create();
# if defined(Q_OS_MACOS)
diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.h
index 8b53b8bcc9f..505960ce5e3 100644
--- a/UI/Qt/WebContentView.h
+++ b/UI/Qt/WebContentView.h
@@ -322,7 +322,7 @@ private:
QPointF m_last_click_position;
int m_click_count { 0 };
- SelectDropdown* m_select_dropdown { nullptr };
+ QPointer<SelectDropdown> m_select_dropdown;
PageOverlay* m_crash_overlay { nullptr };
CrashOverlayUrlLabel* m_crash_overlay_url { nullptr };