From f66cac34174b9e8fe051a7a671b540ddca3b5a19 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 10 Jun 2025 14:50:23 -0400 Subject: [PATCH] LibWebView+UI: Define concrete `Application::the` accessor automatically This avoids assuming that the Qt Application is a QApplication, which will not be the case in an upcoming commit. --- Libraries/LibWebView/Application.h | 5 +++++ Tests/LibWeb/test-web/Application.h | 5 ----- UI/Qt/BrowserWindow.cpp | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h index 3078b2be04b..06645073557 100644 --- a/Libraries/LibWebView/Application.h +++ b/Libraries/LibWebView/Application.h @@ -164,4 +164,9 @@ public: \ return WebView::Application::create(arguments); \ } \ \ + static ApplicationType& the() \ + { \ + return static_cast(WebView::Application::the()); \ + } \ + \ ApplicationType(Badge, Main::Arguments&); diff --git a/Tests/LibWeb/test-web/Application.h b/Tests/LibWeb/test-web/Application.h index 494f81cbdba..2fb0721270e 100644 --- a/Tests/LibWeb/test-web/Application.h +++ b/Tests/LibWeb/test-web/Application.h @@ -19,11 +19,6 @@ class Application : public WebView::Application { public: ~Application(); - static Application& the() - { - return static_cast(WebView::Application::the()); - } - virtual void create_platform_arguments(Core::ArgsParser&) override; virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override; diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp index 4a49491f829..e9e29f5484e 100644 --- a/UI/Qt/BrowserWindow.cpp +++ b/UI/Qt/BrowserWindow.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -615,7 +614,7 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, IsPopupWindow tab.focus_location_editor(); }); QObject::connect(m_new_window_action, &QAction::triggered, this, [] { - (void)static_cast(QApplication::instance())->new_window({}); + (void)Application::the().new_window({}); }); QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); QObject::connect(m_tabs_container, &QTabWidget::currentChanged, [this](int index) { @@ -797,7 +796,7 @@ void BrowserWindow::initialize_tab(Tab* tab) tab->view().on_new_web_view = [this, tab](auto activate_tab, Web::HTML::WebViewHints hints, Optional page_index) { if (hints.popup) { - auto& window = static_cast(QApplication::instance())->new_window({}, IsPopupWindow::Yes, tab, AK::move(page_index)); + auto& window = Application::the().new_window({}, IsPopupWindow::Yes, tab, AK::move(page_index)); window.set_window_rect(hints.screen_x, hints.screen_y, hints.width, hints.height); return window.current_tab()->view().handle(); } @@ -1168,7 +1167,7 @@ bool BrowserWindow::event(QEvent* event) #endif if (event->type() == QEvent::WindowActivate) - static_cast(QApplication::instance())->set_active_window(*this); + Application::the().set_active_window(*this); return QMainWindow::event(event); }