1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

Ladybird: Allow creating new tabs with plain HTML

This will allow us to internally create a new tab with HTML, to be used
by the View Source command.
This commit is contained in:
Timothy Flynn 2023-08-28 16:14:34 -04:00 committed by Tim Flynn
parent 9c4ce1b80b
commit a718a1f3a6
10 changed files with 83 additions and 29 deletions

View file

@ -429,6 +429,20 @@ void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedStr
}
Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_tab)
{
auto& tab = create_new_tab(activate_tab);
tab.navigate(url);
return tab;
}
Tab& BrowserWindow::new_tab(StringView html, URL const& url, Web::HTML::ActivateTab activate_tab)
{
auto& tab = create_new_tab(activate_tab);
tab.load_html(html, url);
return tab;
}
Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
{
auto tab = make<Tab>(this, m_webdriver_content_ipc_path, m_enable_callgrind_profiling, m_use_lagom_networking);
auto tab_ptr = tab.ptr();
@ -500,9 +514,6 @@ Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_
};
tab_ptr->focus_location_editor();
tab_ptr->navigate(url);
return *tab_ptr;
}

View file

@ -73,6 +73,7 @@ public slots:
void tab_title_changed(int index, QString const&);
void tab_favicon_changed(int index, QIcon const& icon);
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
Tab& new_tab(StringView html, URL const& url, Web::HTML::ActivateTab);
void activate_tab(int index);
void close_tab(int index);
void close_current_tab();
@ -98,6 +99,8 @@ private:
virtual void wheelEvent(QWheelEvent*) override;
virtual void closeEvent(QCloseEvent*) override;
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
void set_current_tab(Tab* tab);

View file

@ -566,6 +566,11 @@ void Tab::navigate(QString url_qstring)
view().load(url_string);
}
void Tab::load_html(StringView html, URL const& url)
{
view().load_html(html, url);
}
void Tab::back()
{
if (!m_history.can_go_back())

View file

@ -34,6 +34,8 @@ public:
WebContentView& view() { return *m_view; }
void navigate(QString);
void load_html(StringView, URL const&);
void back();
void forward();
void reload();