diff --git a/Ladybird/Qt/Application.cpp b/Ladybird/Qt/Application.cpp index 73dc6e1726b..3db63bda945 100644 --- a/Ladybird/Qt/Application.cpp +++ b/Ladybird/Qt/Application.cpp @@ -62,9 +62,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) +BrowserWindow& Application::new_window(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional page_index) { - auto* window = new BrowserWindow(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path); + auto* window = new BrowserWindow(initial_urls, cookie_jar, web_content_options, webdriver_content_ipc_path, parent_tab, move(page_index)); set_active_window(*window); window->show(); window->activateWindow(); diff --git a/Ladybird/Qt/Application.h b/Ladybird/Qt/Application.h index 5a1a5d1b9e7..2d77c1b800c 100644 --- a/Ladybird/Qt/Application.h +++ b/Ladybird/Qt/Application.h @@ -27,7 +27,7 @@ public: Function on_open_file; RefPtr request_server_client; - BrowserWindow& new_window(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path); + BrowserWindow& new_window(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, Tab* parent_tab = nullptr, Optional page_index = {}); void show_task_manager_window(); void close_task_manager_window(); diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index bfa76b4c086..abc68e209e4 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -68,7 +68,7 @@ public: } }; -BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path) +BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional page_index) : m_tabs_container(new TabWidget(this)) , m_cookie_jar(cookie_jar) , m_web_content_options(web_content_options) @@ -525,8 +525,12 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::Cook m_tabs_container->setCurrentIndex(m_tabs_container->count() - 1); }); - for (size_t i = 0; i < initial_urls.size(); ++i) { - new_tab_from_url(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); + if (parent_tab) { + new_child_tab(Web::HTML::ActivateTab::Yes, *parent_tab, AK::move(page_index)); + } else { + for (size_t i = 0; i < initial_urls.size(); ++i) { + new_tab_from_url(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); + } } setCentralWidget(m_tabs_container); @@ -563,23 +567,22 @@ Tab& BrowserWindow::new_tab_from_content(StringView html, Web::HTML::ActivateTab return tab; } -Tab& BrowserWindow::new_child_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Web::HTML::WebViewHints hints, Optional page_index) +Tab& BrowserWindow::new_child_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional page_index) { - return create_new_tab(activate_tab, parent, hints, page_index); + return create_new_tab(activate_tab, parent, page_index); } -Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Web::HTML::WebViewHints, Optional page_index) +Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional page_index) { if (!page_index.has_value()) return create_new_tab(activate_tab); - // FIXME: Respect hints for: - // popup: Create new window - // width, height: size of window - // screen_x, screen_y: positioning of window on the screen auto* tab = new Tab(this, m_web_content_options, m_webdriver_content_ipc_path, parent.view().client(), page_index.value()); - VERIFY(m_current_tab != nullptr); + // FIXME: Merge with other overload + if (m_current_tab == nullptr) { + set_current_tab(tab); + } m_tabs_container->addTab(tab, "New Tab"); if (activate_tab == Web::HTML::ActivateTab::Yes) @@ -620,7 +623,12 @@ void BrowserWindow::initialize_tab(Tab* tab) }); tab->view().on_new_web_view = [this, tab](auto activate_tab, Web::HTML::WebViewHints hints, Optional page_index) { - auto& new_tab = new_child_tab(activate_tab, *tab, hints, 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, 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(); + } + auto& new_tab = new_child_tab(activate_tab, *tab, page_index); return new_tab.view().handle(); }; @@ -927,6 +935,18 @@ void BrowserWindow::update_displayed_zoom_level() m_current_tab->update_reset_zoom_button(); } +void BrowserWindow::set_window_rect(Optional x, Optional y, Optional width, Optional height) +{ + x = x.value_or(0); + y = y.value_or(0); + if (!width.has_value() || width.value() == 0) + width = 800; + if (!height.has_value() || height.value() == 0) + height = 600; + + setGeometry(x.value().value(), y.value().value(), width.value().value(), height.value().value()); +} + void BrowserWindow::copy_selected_text() { if (!m_current_tab) diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index 449835de4fa..2701407059f 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -31,7 +31,7 @@ class BrowserWindow : public QMainWindow { Q_OBJECT public: - BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path); + BrowserWindow(Vector const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, Tab* parent_tab = nullptr, Optional page_index = {}); WebContentView& view() const { return m_current_tab->view(); } @@ -109,7 +109,7 @@ public slots: void tab_navigation_buttons_state_changed(int index); Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab); Tab& new_tab_from_content(StringView html, Web::HTML::ActivateTab); - Tab& new_child_tab(Web::HTML::ActivateTab, Tab& parent, Web::HTML::WebViewHints, Optional page_index); + Tab& new_child_tab(Web::HTML::ActivateTab, Tab& parent, Optional page_index); void activate_tab(int index); void close_tab(int index); void move_tab(int old_index, int new_index); @@ -139,7 +139,7 @@ private: virtual void wheelEvent(QWheelEvent*) override; virtual void closeEvent(QCloseEvent*) override; - Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Web::HTML::WebViewHints, Optional page_index); + Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Optional page_index); void initialize_tab(Tab*); void debug_request(ByteString const& request, ByteString const& argument = ""); @@ -162,6 +162,8 @@ private: QString tool_tip_for_page_mute_state(Tab&) const; QTabBar::ButtonPosition audio_button_position_for_tab(int tab_index) const; + void set_window_rect(Optional x, Optional y, Optional width, Optional height); + QScreen* m_current_screen; double m_device_pixel_ratio { 0 };