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.
This commit is contained in:
Timothy Flynn 2025-06-10 14:50:23 -04:00 committed by Tim Ledbetter
commit f66cac3417
Notes: github-actions[bot] 2025-06-10 22:12:05 +00:00
3 changed files with 8 additions and 9 deletions

View file

@ -164,4 +164,9 @@ public: \
return WebView::Application::create<ApplicationType>(arguments); \ return WebView::Application::create<ApplicationType>(arguments); \
} \ } \
\ \
static ApplicationType& the() \
{ \
return static_cast<ApplicationType&>(WebView::Application::the()); \
} \
\
ApplicationType(Badge<WebView::Application>, Main::Arguments&); ApplicationType(Badge<WebView::Application>, Main::Arguments&);

View file

@ -19,11 +19,6 @@ class Application : public WebView::Application {
public: public:
~Application(); ~Application();
static Application& the()
{
return static_cast<Application&>(WebView::Application::the());
}
virtual void create_platform_arguments(Core::ArgsParser&) override; virtual void create_platform_arguments(Core::ArgsParser&) override;
virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override; virtual void create_platform_options(WebView::BrowserOptions&, WebView::WebContentOptions&) override;

View file

@ -26,7 +26,6 @@
#include <QAction> #include <QAction>
#include <QActionGroup> #include <QActionGroup>
#include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QGuiApplication> #include <QGuiApplication>
#include <QInputDialog> #include <QInputDialog>
@ -615,7 +614,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
tab.focus_location_editor(); tab.focus_location_editor();
}); });
QObject::connect(m_new_window_action, &QAction::triggered, this, [] { QObject::connect(m_new_window_action, &QAction::triggered, this, [] {
(void)static_cast<Ladybird::Application*>(QApplication::instance())->new_window({}); (void)Application::the().new_window({});
}); });
QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file);
QObject::connect(m_tabs_container, &QTabWidget::currentChanged, [this](int index) { 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<u64> page_index) { tab->view().on_new_web_view = [this, tab](auto activate_tab, Web::HTML::WebViewHints hints, Optional<u64> page_index) {
if (hints.popup) { if (hints.popup) {
auto& window = static_cast<Ladybird::Application*>(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); window.set_window_rect(hints.screen_x, hints.screen_y, hints.width, hints.height);
return window.current_tab()->view().handle(); return window.current_tab()->view().handle();
} }
@ -1168,7 +1167,7 @@ bool BrowserWindow::event(QEvent* event)
#endif #endif
if (event->type() == QEvent::WindowActivate) if (event->type() == QEvent::WindowActivate)
static_cast<Ladybird::Application*>(QApplication::instance())->set_active_window(*this); Application::the().set_active_window(*this);
return QMainWindow::event(event); return QMainWindow::event(event);
} }