1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

Browser: React to favicon notifications and put favicons in the tabs!

This commit is contained in:
Andreas Kling 2020-04-24 22:28:05 +02:00
parent 53cb5325ee
commit 682f0ac93b
3 changed files with 16 additions and 0 deletions

View file

@ -85,6 +85,7 @@ int main(int argc, char** argv)
widget.layout()->set_spacing(2);
auto& tab_widget = widget.add<GUI::TabWidget>();
tab_widget.set_text_alignment(Gfx::TextAlignment::CenterLeft);
tab_widget.set_container_padding(0);
tab_widget.on_change = [&](auto& active_widget) {
@ -95,16 +96,25 @@ int main(int argc, char** argv)
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");
tab_widget.set_tab_icon(new_tab, default_favicon);
new_tab.on_title_change = [&](auto title) {
tab_widget.set_tab_title(new_tab, title);
if (tab_widget.active_widget() == &new_tab)
window->set_title(String::format("%s - Browser", title.characters()));
};
new_tab.on_favicon_change = [&](auto& bitmap) {
tab_widget.set_tab_icon(new_tab, &bitmap);
};
new_tab.on_tab_open_request = [&](auto& url) {
create_new_tab(url, true);
};