mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
Browser: React to favicon notifications and put favicons in the tabs!
This commit is contained in:
parent
53cb5325ee
commit
682f0ac93b
Notes:
sideshowbarker
2024-07-19 07:19:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/682f0ac93b9
3 changed files with 16 additions and 0 deletions
|
@ -154,6 +154,11 @@ Tab::Tab()
|
|||
on_title_change(m_title);
|
||||
};
|
||||
|
||||
m_html_widget->on_favicon_change = [this](auto& bitmap) {
|
||||
if (on_favicon_change)
|
||||
on_favicon_change(bitmap);
|
||||
};
|
||||
|
||||
auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [this](auto&) {
|
||||
m_location_box->select_all();
|
||||
m_location_box->set_focus(true);
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
Function<void(String)> on_title_change;
|
||||
Function<void(URL&)> on_tab_open_request;
|
||||
Function<void(Tab&)> on_tab_close_request;
|
||||
Function<void(const Gfx::Bitmap&)> on_favicon_change;
|
||||
|
||||
const String& title() const { return m_title; }
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue