1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

WebContent+Everywhere: Add a WebContent IPC to activate a tab

This commit is contained in:
Timothy Flynn 2023-03-20 19:52:00 -04:00 committed by Linus Groh
parent a77daf77bd
commit f8b6369c23
Notes: sideshowbarker 2024-07-17 00:27:16 +09:00
18 changed files with 50 additions and 0 deletions

View file

@ -401,6 +401,11 @@ Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_
return *tab_ptr;
}
void BrowserWindow::activate_tab(int index)
{
m_tabs_container->setCurrentIndex(index);
}
void BrowserWindow::close_tab(int index)
{
auto* tab = m_tabs_container->widget(index);

View file

@ -36,6 +36,7 @@ public slots:
void tab_title_changed(int index, QString const&);
void tab_favicon_changed(int index, QIcon icon);
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
void activate_tab(int index);
void close_tab(int index);
void close_current_tab();
void open_next_tab();

View file

@ -64,6 +64,10 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path)
m_toolbar->addAction(m_home_action);
m_toolbar->addWidget(m_location_edit);
QObject::connect(m_view, &WebContentView::activate_tab, [this] {
m_window->activate_tab(tab_index());
});
QObject::connect(m_view, &WebContentView::close, [this] {
m_window->close_tab(tab_index());
});

View file

@ -988,6 +988,11 @@ String WebContentView::notify_server_did_request_new_tab(Badge<WebContentClient>
return {};
}
void WebContentView::notify_server_did_request_activate_tab(Badge<WebContentClient>)
{
emit activate_tab();
}
void WebContentView::notify_server_did_update_resource_count(i32 count_waiting)
{
// FIXME

View file

@ -148,6 +148,7 @@ public:
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override;
virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) override;
virtual String notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab) override;
virtual void notify_server_did_request_activate_tab(Badge<WebContentClient>) override;
virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) override;
virtual void notify_server_did_update_resource_count(i32 count_waiting) override;
virtual void notify_server_did_request_restore_window() override;
@ -160,6 +161,7 @@ public:
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
signals:
void activate_tab();
void close();
void link_hovered(QString, int timeout = 0);
void link_unhovered();

View file

@ -590,6 +590,10 @@ Tab& BrowserWindow::create_new_tab(URL url, Web::HTML::ActivateTab activate)
create_new_tab(url, Web::HTML::ActivateTab::Yes);
};
new_tab.on_activate_tab_request = [this](auto& tab) {
m_tab_widget->set_active_widget(&tab);
};
new_tab.on_tab_close_request = [this](auto& tab) {
m_tab_widget->deferred_invoke([this, &tab] {
m_tab_widget->remove_tab(tab);

View file

@ -473,6 +473,10 @@ Tab::Tab(BrowserWindow& window)
return tab.view().handle();
};
view().on_activate_tab = [this]() {
on_activate_tab_request(*this);
};
view().on_close = [this] {
on_tab_close_request(*this);
};

View file

@ -62,6 +62,7 @@ public:
Function<void(DeprecatedString const&)> on_title_change;
Function<void(const URL&)> on_tab_open_request;
Function<void(Tab&)> on_activate_tab_request;
Function<void(Tab&)> on_tab_close_request;
Function<void(Tab&)> on_tab_close_other_request;
Function<void(const URL&)> on_window_open_request;

View file

@ -203,6 +203,7 @@ public:
virtual void page_did_update_cookie(Web::Cookie::Cookie) { }
virtual void page_did_update_resource_count(i32) { }
virtual String page_did_request_new_tab(HTML::ActivateTab) { return {}; }
virtual void page_did_request_activate_tab() { }
virtual void page_did_close_browsing_context(HTML::BrowsingContext const&) { }
virtual void request_file(FileRequest) = 0;

View file

@ -480,6 +480,12 @@ String OutOfProcessWebView::notify_server_did_request_new_tab(Badge<WebContentCl
return {};
}
void OutOfProcessWebView::notify_server_did_request_activate_tab(Badge<WebContentClient>)
{
if (on_activate_tab)
on_activate_tab();
}
void OutOfProcessWebView::notify_server_did_close_browsing_context(Badge<WebContentClient>)
{
if (on_close)

View file

@ -59,6 +59,7 @@ public:
void set_content_scales_to_viewport(bool);
Function<String(Web::HTML::ActivateTab)> on_new_tab;
Function<void()> on_activate_tab;
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;
@ -164,6 +165,7 @@ private:
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override;
virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) override;
virtual String notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab) override;
virtual void notify_server_did_request_activate_tab(Badge<WebContentClient>) override;
virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) override;
virtual void notify_server_did_update_resource_count(i32 count_waiting) override;
virtual void notify_server_did_request_restore_window() override;

View file

@ -100,6 +100,7 @@ public:
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) = 0;
virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) = 0;
virtual String notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab) = 0;
virtual void notify_server_did_request_activate_tab(Badge<WebContentClient>) = 0;
virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) = 0;
virtual void notify_server_did_update_resource_count(i32 count_waiting) = 0;
virtual void notify_server_did_request_restore_window() = 0;

View file

@ -245,6 +245,11 @@ Messages::WebContentClient::DidRequestNewTabResponse WebContentClient::did_reque
return m_view.notify_server_did_request_new_tab({}, activate_tab);
}
void WebContentClient::did_request_activate_tab()
{
m_view.notify_server_did_request_activate_tab({});
}
void WebContentClient::did_close_browsing_context()
{
m_view.notify_server_did_close_browsing_context({});

View file

@ -71,6 +71,7 @@ private:
virtual void did_set_cookie(AK::URL const&, Web::Cookie::ParsedCookie const&, u8) override;
virtual void did_update_cookie(Web::Cookie::Cookie const&) override;
virtual Messages::WebContentClient::DidRequestNewTabResponse did_request_new_tab(Web::HTML::ActivateTab const& activate_tab) override;
virtual void did_request_activate_tab() override;
virtual void did_close_browsing_context() override;
virtual void did_update_resource_count(i32 count_waiting) override;
virtual void did_request_restore_window() override;

View file

@ -382,6 +382,11 @@ String PageHost::page_did_request_new_tab(Web::HTML::ActivateTab activate_tab)
return m_client.did_request_new_tab(activate_tab);
}
void PageHost::page_did_request_activate_tab()
{
m_client.async_did_request_activate_tab();
}
void PageHost::page_did_close_browsing_context(Web::HTML::BrowsingContext const&)
{
m_client.async_did_close_browsing_context();

View file

@ -99,6 +99,7 @@ private:
virtual void page_did_update_cookie(Web::Cookie::Cookie) override;
virtual void page_did_update_resource_count(i32) override;
virtual String page_did_request_new_tab(Web::HTML::ActivateTab activate_tab) override;
virtual void page_did_request_activate_tab() override;
virtual void page_did_close_browsing_context(Web::HTML::BrowsingContext const&) override;
virtual void request_file(Web::FileRequest) override;

View file

@ -48,6 +48,7 @@ endpoint WebContentClient
did_update_cookie(Web::Cookie::Cookie cookie) =|
did_update_resource_count(i32 count_waiting) =|
did_request_new_tab(Web::HTML::ActivateTab activate_tab) => (String handle)
did_request_activate_tab() =|
did_close_browsing_context() =|
did_request_restore_window() =|
did_request_reposition_window(Gfx::IntPoint position) => (Gfx::IntPoint window_position)

View file

@ -134,6 +134,7 @@ private:
void notify_server_did_set_cookie(Badge<WebView::WebContentClient>, const URL&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override { }
void notify_server_did_update_cookie(Badge<WebView::WebContentClient>, Web::Cookie::Cookie const&) override { }
String notify_server_did_request_new_tab(Badge<WebView::WebContentClient>, Web::HTML::ActivateTab) override { return {}; }
void notify_server_did_request_activate_tab(Badge<WebView::WebContentClient>) override { }
void notify_server_did_close_browsing_context(Badge<WebView::WebContentClient>) override { }
void notify_server_did_update_resource_count(i32) override { }
void notify_server_did_request_restore_window() override { }