Browser: Use the active tab's favicon as the window icon :^)

This commit is contained in:
Andreas Kling 2020-04-24 22:47:53 +02:00
parent 4d8206f7c2
commit 260e4049ff
Notes: sideshowbarker 2024-07-19 07:19:20 +09:00
3 changed files with 12 additions and 5 deletions

View file

@ -154,9 +154,10 @@ Tab::Tab()
on_title_change(m_title);
};
m_html_widget->on_favicon_change = [this](auto& bitmap) {
m_html_widget->on_favicon_change = [this](auto& icon) {
m_icon = icon;
if (on_favicon_change)
on_favicon_change(bitmap);
on_favicon_change(icon);
};
auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [this](auto&) {

View file

@ -49,6 +49,7 @@ public:
Function<void(const Gfx::Bitmap&)> on_favicon_change;
const String& title() const { return m_title; }
const Gfx::Bitmap* icon() const { return m_icon; }
private:
Tab();
@ -68,6 +69,8 @@ private:
RefPtr<GUI::MenuBar> m_menubar;
String m_title;
RefPtr<const Gfx::Bitmap> m_icon;
bool m_should_push_loads_to_history { true };
};

View file

@ -89,17 +89,18 @@ int main(int argc, char** argv)
tab_widget.set_container_padding(0);
tab_widget.set_uniform_tabs(true);
auto default_favicon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png");
ASSERT(default_favicon);
tab_widget.on_change = [&](auto& active_widget) {
auto& tab = static_cast<Browser::Tab&>(active_widget);
window->set_title(String::format("%s - Browser", tab.title().characters()));
window->set_icon(tab.icon() ? tab.icon() : default_favicon.ptr());
tab.did_become_active();
};
Browser::WindowActions window_actions(*window);
auto default_favicon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png");
ASSERT(default_favicon);
Function<void(URL url, bool activate)> create_new_tab;
create_new_tab = [&](auto url, auto activate) {
auto& new_tab = tab_widget.add_tab<Browser::Tab>("New tab");
@ -114,6 +115,8 @@ int main(int argc, char** argv)
new_tab.on_favicon_change = [&](auto& bitmap) {
tab_widget.set_tab_icon(new_tab, &bitmap);
if (tab_widget.active_widget() == &new_tab)
window->set_icon(&bitmap);
};
new_tab.on_tab_open_request = [&](auto& url) {