Ladybird: Open target _blank links in new tab

This commit is contained in:
Coderdreams 2023-03-22 21:24:15 -03:00 committed by Linus Groh
parent 05a2d1f0e0
commit 14c9ef2563
Notes: sideshowbarker 2024-07-17 03:45:48 +09:00
3 changed files with 26 additions and 9 deletions

View file

@ -369,6 +369,25 @@ Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_
return tab.view().handle();
};
tab_ptr->view().on_tab_open_request = [this](auto url, auto activate_tab) {
auto& tab = new_tab(qstring_from_ak_deprecated_string(url.to_deprecated_string()), activate_tab);
return tab.view().handle();
};
tab_ptr->view().on_link_click = [this](auto url, auto target, unsigned modifiers) {
// TODO: maybe activate tabs according to some configuration, this is just normal current browser behavior
if (modifiers == Mod_Ctrl) {
m_current_tab->view().on_tab_open_request(url, Web::HTML::ActivateTab::No);
} else if (target == "_blank") {
m_current_tab->view().on_tab_open_request(url, Web::HTML::ActivateTab::Yes);
}
};
tab_ptr->view().on_link_middle_click = [this](auto url, auto target, unsigned modifiers) {
m_current_tab->view().on_link_click(url, target, Mod_Ctrl);
(void)modifiers;
};
tab_ptr->view().on_get_all_cookies = [this](auto const& url) {
return m_cookie_jar.get_all_cookies(url);
};

View file

@ -778,19 +778,16 @@ void WebContentView::notify_server_did_unhover_link(Badge<WebContentClient>)
void WebContentView::notify_server_did_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
{
// FIXME
(void)url;
(void)target;
(void)modifiers;
// if (on_link_click)
// on_link_click(url, target, modifiers);
if (on_link_click) {
on_link_click(url, target, modifiers);
}
}
void WebContentView::notify_server_did_middle_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
{
(void)url;
(void)target;
(void)modifiers;
if (on_link_middle_click) {
on_link_middle_click(url, target, modifiers);
}
}
void WebContentView::notify_server_did_start_loading(Badge<WebContentClient>, AK::URL const& url, bool is_redirect)

View file

@ -51,6 +51,7 @@ public:
virtual ~WebContentView() override;
Function<String(Web::HTML::ActivateTab)> on_new_tab;
Function<String(const AK::URL&, Web::HTML::ActivateTab)> on_tab_open_request;
Function<void()> on_close;
Function<void(Gfx::IntPoint screen_position)> on_context_menu_request;
Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_click;