mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
Browser: Use the active tab's favicon as the window icon :^)
This commit is contained in:
parent
4d8206f7c2
commit
260e4049ff
3 changed files with 12 additions and 5 deletions
|
@ -154,9 +154,10 @@ Tab::Tab()
|
||||||
on_title_change(m_title);
|
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)
|
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&) {
|
auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [this](auto&) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||||
|
|
||||||
const String& title() const { return m_title; }
|
const String& title() const { return m_title; }
|
||||||
|
const Gfx::Bitmap* icon() const { return m_icon; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Tab();
|
Tab();
|
||||||
|
@ -68,6 +69,8 @@ private:
|
||||||
RefPtr<GUI::MenuBar> m_menubar;
|
RefPtr<GUI::MenuBar> m_menubar;
|
||||||
|
|
||||||
String m_title;
|
String m_title;
|
||||||
|
RefPtr<const Gfx::Bitmap> m_icon;
|
||||||
|
|
||||||
bool m_should_push_loads_to_history { true };
|
bool m_should_push_loads_to_history { true };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -89,17 +89,18 @@ int main(int argc, char** argv)
|
||||||
tab_widget.set_container_padding(0);
|
tab_widget.set_container_padding(0);
|
||||||
tab_widget.set_uniform_tabs(true);
|
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) {
|
tab_widget.on_change = [&](auto& active_widget) {
|
||||||
auto& tab = static_cast<Browser::Tab&>(active_widget);
|
auto& tab = static_cast<Browser::Tab&>(active_widget);
|
||||||
window->set_title(String::format("%s - Browser", tab.title().characters()));
|
window->set_title(String::format("%s - Browser", tab.title().characters()));
|
||||||
|
window->set_icon(tab.icon() ? tab.icon() : default_favicon.ptr());
|
||||||
tab.did_become_active();
|
tab.did_become_active();
|
||||||
};
|
};
|
||||||
|
|
||||||
Browser::WindowActions window_actions(*window);
|
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;
|
Function<void(URL url, bool activate)> create_new_tab;
|
||||||
create_new_tab = [&](auto url, auto activate) {
|
create_new_tab = [&](auto url, auto activate) {
|
||||||
auto& new_tab = tab_widget.add_tab<Browser::Tab>("New tab");
|
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) {
|
new_tab.on_favicon_change = [&](auto& bitmap) {
|
||||||
tab_widget.set_tab_icon(new_tab, &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) {
|
new_tab.on_tab_open_request = [&](auto& url) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue