Ladybird/Qt: Display a default favicon and title

This ensures we consistently show a favicon and that we update the title
to at least display the page URL when there isn't a <title> tag. We
would otherwise continue displaying the previous page's title.
This commit is contained in:
Timothy Flynn 2024-03-28 11:11:02 -04:00 committed by Andreas Kling
parent 59fb811159
commit 8503bcb897
Notes: sideshowbarker 2024-07-17 14:33:07 +09:00
3 changed files with 18 additions and 5 deletions

View file

@ -534,7 +534,6 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
void BrowserWindow::initialize_tab(Tab* tab)
{
QObject::connect(tab, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
QObject::connect(tab, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
@ -592,6 +591,8 @@ void BrowserWindow::initialize_tab(Tab* tab)
m_cookie_jar.update_cookie(cookie);
};
m_tabs_container->setTabIcon(m_tabs_container->indexOf(tab), tab->favicon());
tab->focus_location_editor();
}

View file

@ -82,6 +82,8 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
recreate_toolbar_icons();
m_favicon = load_icon_from_uri("resource://icons/16x16/app-browser.png"sv);
m_toolbar->addAction(&m_window->go_back_action());
m_toolbar->addAction(&m_window->go_forward_action());
m_toolbar->addAction(&m_window->reload_action());
@ -128,7 +130,12 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
m_history.replace_current(url, m_title.toUtf8().data());
}
m_location_edit->setText(url.to_byte_string().characters());
auto url_serialized = qstring_from_ak_string(url.serialize());
m_title = url_serialized;
emit title_changed(tab_index(), url_serialized);
m_location_edit->setText(url_serialized);
m_location_edit->setCursorPosition(0);
// Don't add to history if back or forward is pressed
@ -166,7 +173,9 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
auto qpixmap = QPixmap::fromImage(qimage);
if (qpixmap.isNull())
return;
emit favicon_changed(tab_index(), QIcon(qpixmap));
m_favicon = qpixmap;
emit favicon_changed(tab_index(), m_favicon);
};
view().on_request_alert = [this](auto const& message) {

View file

@ -51,14 +51,16 @@ public:
};
void show_inspector_window(InspectorTarget = InspectorTarget::Document);
QIcon const& favicon() const { return m_favicon; }
public slots:
void focus_location_editor();
void location_edit_return_pressed();
void select_dropdown_action();
signals:
void title_changed(int id, QString);
void favicon_changed(int id, QIcon);
void title_changed(int id, QString const&);
void favicon_changed(int id, QIcon const&);
private:
void select_dropdown_add_item(QMenu* menu, Web::HTML::SelectItem const& item);
@ -85,6 +87,7 @@ private:
WebView::History m_history;
QString m_title;
QLabel* m_hover_label { nullptr };
QIcon m_favicon;
QMenu* m_page_context_menu { nullptr };
Optional<String> m_page_context_menu_search_text;