Skip to content

Commit

Permalink
UI/Qt: Don't save size and location of popup windows on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 committed Jul 27, 2024
1 parent a6ebd10 commit 8f0a46f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Ladybird/Qt/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void Application::close_task_manager_window()
}
}

BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional<u64> page_index)
BrowserWindow& Application::new_window(Vector<URL::URL> 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<u64> 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()) {
Expand Down
2 changes: 1 addition & 1 deletion Ladybird/Qt/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Application : public QApplication {
NonnullRefPtr<ImageDecoderClient::Client> image_decoder_client() const { return *m_image_decoder_client; }
ErrorOr<void> initialize_image_decoder();

BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
BrowserWindow& new_window(Vector<URL::URL> 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<u64> page_index = {});

void show_task_manager_window(WebContentOptions const&);
void close_task_manager_window();
Expand Down
13 changes: 8 additions & 5 deletions Ladybird/Qt/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ class HamburgerMenu : public QMenu {
}
};

BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional<u64> page_index)
BrowserWindow::BrowserWindow(Vector<URL::URL> 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<u64> 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());

Expand Down Expand Up @@ -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<u64> page_index) {
if (hints.popup) {
auto& window = static_cast<Ladybird::Application*>(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<Ladybird::Application*>(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();
}
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 7 additions & 1 deletion Ladybird/Qt/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class BrowserWindow : public QMainWindow {
Q_OBJECT

public:
BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
enum class IsPopupWindow {
No,
Yes,
};

BrowserWindow(Vector<URL::URL> 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<u64> page_index = {});

WebContentView& view() const { return m_current_tab->view(); }

Expand Down Expand Up @@ -216,6 +221,7 @@ public slots:
StringView m_webdriver_content_ipc_path;

bool m_allow_popups { false };
IsPopupWindow m_is_popup_window { IsPopupWindow::No };
};

}

0 comments on commit 8f0a46f

Please sign in to comment.