mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-14 21:42:19 +00:00
Ladybird: Respect window.open() features in Qt chrome
This commit is contained in:
parent
46e00a8f5e
commit
c4f2ff44a5
Notes:
sideshowbarker
2024-07-17 10:08:28 +09:00
Author: https://github.com/ADKaster
Commit: c4f2ff44a5
Pull-request: https://github.com/SerenityOS/serenity/pull/24477
Reviewed-by: https://github.com/trflynn89
4 changed files with 40 additions and 18 deletions
|
@ -62,9 +62,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)
|
BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional<u64> 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);
|
set_active_window(*window);
|
||||||
window->show();
|
window->show();
|
||||||
window->activateWindow();
|
window->activateWindow();
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
Function<void(URL::URL)> on_open_file;
|
Function<void(URL::URL)> on_open_file;
|
||||||
RefPtr<Protocol::RequestClient> request_server_client;
|
RefPtr<Protocol::RequestClient> request_server_client;
|
||||||
|
|
||||||
BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path);
|
BrowserWindow& new_window(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
|
||||||
|
|
||||||
void show_task_manager_window();
|
void show_task_manager_window();
|
||||||
void close_task_manager_window();
|
void close_task_manager_window();
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path)
|
BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional<u64> page_index)
|
||||||
: m_tabs_container(new TabWidget(this))
|
: m_tabs_container(new TabWidget(this))
|
||||||
, m_cookie_jar(cookie_jar)
|
, m_cookie_jar(cookie_jar)
|
||||||
, m_web_content_options(web_content_options)
|
, m_web_content_options(web_content_options)
|
||||||
|
@ -525,8 +525,12 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
|
||||||
m_tabs_container->setCurrentIndex(m_tabs_container->count() - 1);
|
m_tabs_container->setCurrentIndex(m_tabs_container->count() - 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (size_t i = 0; i < initial_urls.size(); ++i) {
|
if (parent_tab) {
|
||||||
new_tab_from_url(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No);
|
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);
|
setCentralWidget(m_tabs_container);
|
||||||
|
@ -563,23 +567,22 @@ Tab& BrowserWindow::new_tab_from_content(StringView html, Web::HTML::ActivateTab
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tab& BrowserWindow::new_child_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Web::HTML::WebViewHints hints, Optional<u64> page_index)
|
Tab& BrowserWindow::new_child_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional<u64> 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<u64> page_index)
|
Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional<u64> page_index)
|
||||||
{
|
{
|
||||||
if (!page_index.has_value())
|
if (!page_index.has_value())
|
||||||
return create_new_tab(activate_tab);
|
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());
|
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");
|
m_tabs_container->addTab(tab, "New Tab");
|
||||||
if (activate_tab == Web::HTML::ActivateTab::Yes)
|
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<u64> page_index) {
|
tab->view().on_new_web_view = [this, tab](auto activate_tab, Web::HTML::WebViewHints hints, Optional<u64> page_index) {
|
||||||
auto& new_tab = new_child_tab(activate_tab, *tab, hints, 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, 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();
|
return new_tab.view().handle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -927,6 +935,18 @@ void BrowserWindow::update_displayed_zoom_level()
|
||||||
m_current_tab->update_reset_zoom_button();
|
m_current_tab->update_reset_zoom_button();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> 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()
|
void BrowserWindow::copy_selected_text()
|
||||||
{
|
{
|
||||||
if (!m_current_tab)
|
if (!m_current_tab)
|
||||||
|
|
|
@ -31,7 +31,7 @@ class BrowserWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path);
|
BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar&, WebContentOptions const&, StringView webdriver_content_ipc_path, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
|
||||||
|
|
||||||
WebContentView& view() const { return m_current_tab->view(); }
|
WebContentView& view() const { return m_current_tab->view(); }
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ public slots:
|
||||||
void tab_navigation_buttons_state_changed(int index);
|
void tab_navigation_buttons_state_changed(int index);
|
||||||
Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab);
|
Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab);
|
||||||
Tab& new_tab_from_content(StringView html, 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<u64> page_index);
|
Tab& new_child_tab(Web::HTML::ActivateTab, Tab& parent, Optional<u64> page_index);
|
||||||
void activate_tab(int index);
|
void activate_tab(int index);
|
||||||
void close_tab(int index);
|
void close_tab(int index);
|
||||||
void move_tab(int old_index, int new_index);
|
void move_tab(int old_index, int new_index);
|
||||||
|
@ -139,7 +139,7 @@ private:
|
||||||
virtual void wheelEvent(QWheelEvent*) override;
|
virtual void wheelEvent(QWheelEvent*) override;
|
||||||
virtual void closeEvent(QCloseEvent*) override;
|
virtual void closeEvent(QCloseEvent*) override;
|
||||||
|
|
||||||
Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Web::HTML::WebViewHints, Optional<u64> page_index);
|
Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Optional<u64> page_index);
|
||||||
void initialize_tab(Tab*);
|
void initialize_tab(Tab*);
|
||||||
|
|
||||||
void debug_request(ByteString const& request, ByteString const& argument = "");
|
void debug_request(ByteString const& request, ByteString const& argument = "");
|
||||||
|
@ -162,6 +162,8 @@ private:
|
||||||
QString tool_tip_for_page_mute_state(Tab&) const;
|
QString tool_tip_for_page_mute_state(Tab&) const;
|
||||||
QTabBar::ButtonPosition audio_button_position_for_tab(int tab_index) const;
|
QTabBar::ButtonPosition audio_button_position_for_tab(int tab_index) const;
|
||||||
|
|
||||||
|
void set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> height);
|
||||||
|
|
||||||
QScreen* m_current_screen;
|
QScreen* m_current_screen;
|
||||||
double m_device_pixel_ratio { 0 };
|
double m_device_pixel_ratio { 0 };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue