From 2d95cc01dc3a7417b9531c8476a15505866bbf53 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 27 Jul 2024 11:38:39 +0100 Subject: [PATCH] UI/Qt: Don't save size and location of popup windows on exit --- Ladybird/Qt/Application.cpp | 4 ++-- Ladybird/Qt/Application.h | 2 +- Ladybird/Qt/BrowserWindow.cpp | 13 ++++++++----- Ladybird/Qt/BrowserWindow.h | 8 +++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Ladybird/Qt/Application.cpp b/Ladybird/Qt/Application.cpp index 19683247aa0..4cab11cf1f8 100644 --- a/Ladybird/Qt/Application.cpp +++ b/Ladybird/Qt/Application.cpp @@ -96,9 +96,9 @@ void Application::close_task_manager_window() } } -BrowserWindow& Application::new_window(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional page_index) +BrowserWindow& Application::new_window(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, BrowserWindow::IsPopupWindow is_popup_window, Tab* parent_tab, Optional page_index) { - auto* window = new BrowserWindow(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path, allow_popups, parent_tab, move(page_index)); + auto* window = new BrowserWindow(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path, allow_popups, is_popup_window, parent_tab, move(page_index)); set_active_window(*window); window->show(); if (initial_urls.is_empty()) { diff --git a/Ladybird/Qt/Application.h b/Ladybird/Qt/Application.h index 639c2c2ff3b..7689b55df33 100644 --- a/Ladybird/Qt/Application.h +++ b/Ladybird/Qt/Application.h @@ -31,7 +31,7 @@ public: NonnullRefPtr image_decoder_client() const { return *m_image_decoder_client; } ErrorOr initialize_image_decoder(); - BrowserWindow& new_window(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab = nullptr, Optional page_index = {}); + BrowserWindow& new_window(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, BrowserWindow::IsPopupWindow is_popup_window = BrowserWindow::IsPopupWindow::No, Tab* parent_tab = nullptr, Optional page_index = {}); void show_task_manager_window(WebContentOptions const&); void close_task_manager_window(); diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 006c2fa6072..4d9efc66eca 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -70,13 +70,14 @@ public: } }; -BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional page_index) +BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, IsPopupWindow is_popup_window, Tab* parent_tab, Optional page_index) : m_tabs_container(new TabWidget(this)) , m_new_tab_button_toolbar(new QToolBar("New Tab", m_tabs_container)) , m_cookie_jar(cookie_jar) , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) , m_allow_popups(allow_popups) + , m_is_popup_window(is_popup_window) { setWindowIcon(app_icon()); @@ -786,7 +787,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({}, m_cookie_jar, m_web_content_options, m_webdriver_content_ipc_path, m_allow_popups, tab, AK::move(page_index)); + auto& window = static_cast(QApplication::instance())->new_window({}, m_cookie_jar, m_web_content_options, m_webdriver_content_ipc_path, m_allow_popups, 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(); } @@ -1238,9 +1239,11 @@ bool BrowserWindow::eventFilter(QObject* obj, QEvent* event) void BrowserWindow::closeEvent(QCloseEvent* event) { - Settings::the()->set_last_position(pos()); - Settings::the()->set_last_size(size()); - Settings::the()->set_is_maximized(isMaximized()); + if (m_is_popup_window == IsPopupWindow::No) { + Settings::the()->set_last_position(pos()); + Settings::the()->set_last_size(size()); + Settings::the()->set_is_maximized(isMaximized()); + } QObject::deleteLater(); diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index 08f08378def..b4cab8c0f83 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -31,7 +31,12 @@ class BrowserWindow : public QMainWindow { Q_OBJECT public: - BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab = nullptr, Optional page_index = {}); + enum class IsPopupWindow { + No, + Yes, + }; + + BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, IsPopupWindow is_popup_window = IsPopupWindow::No, Tab* parent_tab = nullptr, Optional page_index = {}); WebContentView& view() const { return m_current_tab->view(); } @@ -216,6 +221,7 @@ private: StringView m_webdriver_content_ipc_path; bool m_allow_popups { false }; + IsPopupWindow m_is_popup_window { IsPopupWindow::No }; }; }